Bug 1160703 (Part 1) - Move ImageCacheKey out of imgLoader.h. r=baku
authorSeth Fowler <mark.seth.fowler@gmail.com>
Wed, 20 May 2015 10:21:09 -0700
changeset 244778 da24d90ca18780c51e061fdf4109f636e7152f88
parent 244777 d192c8d0ddb6c27b994cbe1dcd5772ed99b081c6
child 244779 0c1b8244dcb085137418034cd622d52400344e31
push id60027
push usermfowler@mozilla.com
push dateWed, 20 May 2015 17:21:33 +0000
treeherdermozilla-inbound@74c9d2746692 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1160703
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1160703 (Part 1) - Move ImageCacheKey out of imgLoader.h. r=baku
image/ImageCacheKey.cpp
image/ImageCacheKey.h
image/imgLoader.cpp
image/imgLoader.h
image/moz.build
new file mode 100644
--- /dev/null
+++ b/image/ImageCacheKey.cpp
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "ImageCacheKey.h"
+
+#include "mozilla/Move.h"
+#include "File.h"
+#include "ImageURL.h"
+#include "nsHostObjectProtocolHandler.h"
+#include "nsString.h"
+
+namespace mozilla {
+
+using namespace dom;
+
+namespace image {
+
+ImageCacheKey::ImageCacheKey(nsIURI* aURI)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aURI);
+
+  bool isChrome;
+  mIsChrome = NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome;
+
+  aURI->GetSpec(mSpec);
+  mHash = ComputeHash(mSpec);
+}
+
+ImageCacheKey::ImageCacheKey(ImageURL* aURI)
+{
+  MOZ_ASSERT(aURI);
+
+  bool isChrome;
+  mIsChrome = NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome;
+
+  aURI->GetSpec(mSpec);
+  mHash = ComputeHash(mSpec);
+}
+
+ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther)
+  : mSpec(aOther.mSpec)
+  , mHash(aOther.mHash)
+  , mIsChrome(aOther.mIsChrome)
+{ }
+
+ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther)
+  : mSpec(Move(aOther.mSpec))
+  , mHash(aOther.mHash)
+  , mIsChrome(aOther.mIsChrome)
+{ }
+
+bool
+ImageCacheKey::operator==(const ImageCacheKey& aOther) const
+{
+  return mSpec == aOther.mSpec;
+}
+
+/* static */ uint32_t
+ImageCacheKey::ComputeHash(const nsACString& aSpec)
+{
+  // Since we frequently call Hash() several times in a row on the same
+  // ImageCacheKey, as an optimization we compute our hash once and store it.
+  return HashString(aSpec);
+}
+
+} // namespace image
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/image/ImageCacheKey.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * ImageCacheKey is the key type for the image cache (see imgLoader.h).
+ */
+
+#ifndef mozilla_image_src_ImageCacheKey_h
+#define mozilla_image_src_ImageCacheKey_h
+
+class nsIURI;
+
+namespace mozilla {
+namespace image {
+
+class ImageURL;
+
+/**
+ * An ImageLib cache entry key.
+ *
+ * We key the cache on the initial URI (before any redirects), with some
+ * canonicalization applied. See ComputeHash() for the details.
+ */
+class ImageCacheKey final
+{
+public:
+  explicit ImageCacheKey(nsIURI* aURI);
+  explicit ImageCacheKey(ImageURL* aURI);
+
+  ImageCacheKey(const ImageCacheKey& aOther);
+  ImageCacheKey(ImageCacheKey&& aOther);
+
+  bool operator==(const ImageCacheKey& aOther) const;
+  uint32_t Hash() const { return mHash; }
+
+  /// A weak pointer to the URI spec for this cache entry. For logging only.
+  const char* Spec() const { return mSpec.get(); }
+
+  /// Is this cache entry for a chrome image?
+  bool IsChrome() const { return mIsChrome; }
+
+private:
+  static uint32_t ComputeHash(const nsACString& aSpec);
+
+  nsCString mSpec;
+  uint32_t mHash;
+  bool mIsChrome;
+};
+
+} // namespace image
+} // namespace mozilla
+
+#endif // mozilla_image_src_ImageCacheKey_h
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -1096,70 +1096,16 @@ imgCacheExpirationTracker::NotifyExpired
     entry->Loader()->RemoveFromCache(entry);
   }
 
   entry->Loader()->VerifyCacheSizes();
 }
 
 
 ///////////////////////////////////////////////////////////////////////////////
-// ImageCacheKey
-///////////////////////////////////////////////////////////////////////////////
-
-ImageCacheKey::ImageCacheKey(nsIURI* aURI)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aURI);
-
-  bool isChrome;
-  mIsChrome = NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome;
-
-  aURI->GetSpec(mSpec);
-  mHash = ComputeHash(mSpec);
-}
-
-ImageCacheKey::ImageCacheKey(ImageURL* aURI)
-{
-  MOZ_ASSERT(aURI);
-
-  bool isChrome;
-  mIsChrome = NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome;
-
-  aURI->GetSpec(mSpec);
-  mHash = ComputeHash(mSpec);
-}
-
-ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther)
-  : mSpec(aOther.mSpec)
-  , mHash(aOther.mHash)
-  , mIsChrome(aOther.mIsChrome)
-{ }
-
-ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther)
-  : mSpec(Move(aOther.mSpec))
-  , mHash(aOther.mHash)
-  , mIsChrome(aOther.mIsChrome)
-{ }
-
-bool
-ImageCacheKey::operator==(const ImageCacheKey& aOther) const
-{
-  return mSpec == aOther.mSpec;
-}
-
-/* static */ uint32_t
-ImageCacheKey::ComputeHash(const nsACString& aSpec)
-{
-  // Since we frequently call Hash() several times in a row on the same
-  // ImageCacheKey, as an optimization we compute our hash once and store it.
-  return HashString(aSpec);
-}
-
-
-///////////////////////////////////////////////////////////////////////////////
 // imgLoader
 ///////////////////////////////////////////////////////////////////////////////
 
 double imgLoader::sCacheTimeWeight;
 uint32_t imgLoader::sCacheMaxSize;
 imgMemoryReporter* imgLoader::sMemReporter;
 
 NS_IMPL_ISUPPORTS(imgLoader, imgILoader, nsIContentSniffer, imgICache,
--- a/image/imgLoader.h
+++ b/image/imgLoader.h
@@ -12,16 +12,17 @@
 
 #include "imgILoader.h"
 #include "imgICache.h"
 #include "nsWeakReference.h"
 #include "nsIContentSniffer.h"
 #include "nsRefPtrHashtable.h"
 #include "nsExpirationTracker.h"
 #include "nsAutoPtr.h"
+#include "ImageCacheKey.h"
 #include "imgRequest.h"
 #include "nsIProgressEventSink.h"
 #include "nsIChannel.h"
 #include "nsIThreadRetargetableStreamListener.h"
 #include "imgIRequest.h"
 #include "mozilla/net/ReferrerPolicy.h"
 
 class imgLoader;
@@ -209,57 +210,26 @@ private:
   uint32_t mSize;
 };
 
 enum class AcceptedMimeTypes : uint8_t {
   IMAGES,
   IMAGES_AND_DOCUMENTS,
 };
 
-/**
- * An ImageLib cache entry key.
- *
- * We key the cache on the initial URI (before any redirects), with some
- * canonicalization applied. See ComputeHash() for the details.
- */
-class ImageCacheKey final
-{
-public:
-  explicit ImageCacheKey(nsIURI* aURI);
-  explicit ImageCacheKey(mozilla::image::ImageURL* aURI);
-
-  ImageCacheKey(const ImageCacheKey& aOther);
-  ImageCacheKey(ImageCacheKey&& aOther);
-
-  bool operator==(const ImageCacheKey& aOther) const;
-  uint32_t Hash() const { return mHash; }
-
-  /// A weak pointer to the URI spec for this cache entry. For logging only.
-  const char* Spec() const { return mSpec.get(); }
-
-  /// Is this cache entry for a chrome image?
-  bool IsChrome() const { return mIsChrome; }
-
-private:
-  static uint32_t ComputeHash(const nsACString& aSpec);
-
-  nsCString mSpec;
-  uint32_t mHash;
-  bool mIsChrome;
-};
-
 class imgLoader final : public imgILoader,
                         public nsIContentSniffer,
                         public imgICache,
                         public nsSupportsWeakReference,
                         public nsIObserver
 {
   virtual ~imgLoader();
 
 public:
+  typedef mozilla::image::ImageCacheKey ImageCacheKey;
   typedef mozilla::image::ImageURL ImageURL;
   typedef nsRefPtrHashtable<nsGenericHashKey<ImageCacheKey>,
                             imgCacheEntry> imgCacheTable;
   typedef nsTHashtable<nsPtrHashKey<imgRequest>> imgSet;
   typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
   typedef mozilla::Mutex Mutex;
 
   NS_DECL_ISUPPORTS
--- a/image/moz.build
+++ b/image/moz.build
@@ -29,16 +29,17 @@ XPIDL_SOURCES += [
     'imgIScriptedNotificationObserver.idl',
     'imgITools.idl',
     'nsIIconURI.idl',
 ]
 
 XPIDL_MODULE = 'imglib2'
 
 EXPORTS += [
+    'ImageCacheKey.h',
     'ImageLogging.h',
     'ImageOps.h',
     'ImageRegion.h',
     'imgLoader.h',
     'imgRequest.h',
     'imgRequestProxy.h',
     'IProgressObserver.h',
     'Orientation.h',
@@ -48,16 +49,17 @@ EXPORTS += [
 UNIFIED_SOURCES += [
     'ClippedImage.cpp',
     'DecodePool.cpp',
     'Decoder.cpp',
     'DynamicImage.cpp',
     'FrameAnimator.cpp',
     'FrozenImage.cpp',
     'Image.cpp',
+    'ImageCacheKey.cpp',
     'ImageFactory.cpp',
     'ImageMetadata.cpp',
     'ImageOps.cpp',
     'ImageWrapper.cpp',
     'imgFrame.cpp',
     'imgTools.cpp',
     'MultipartImage.cpp',
     'OrientedImage.cpp',