Bug 1139804 (Part 5) - Stop accessing private imgRequest members in imgMemoryReporter. r=baku
authorSeth Fowler <seth@mozilla.com>
Mon, 23 Mar 2015 19:37:45 -0700
changeset 265540 e488bdbe1bc8496358d83afdcae14942e0e29ea6
parent 265539 06eca034b0850718b9cdf562df452bac08d29029
child 265541 165b9f6bb984c873811c181a553876e4c6336f6e
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1139804
milestone39.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 1139804 (Part 5) - Stop accessing private imgRequest members in imgMemoryReporter. r=baku
image/src/imgLoader.cpp
image/src/imgRequest.cpp
image/src/imgRequest.h
--- a/image/src/imgLoader.cpp
+++ b/image/src/imgLoader.cpp
@@ -397,17 +397,17 @@ private:
                             req->HasConsumers());
     return PL_DHASH_NEXT;
   }
 
   static void RecordCounterForRequest(imgRequest* aRequest,
                                       nsTArray<ImageMemoryCounter>* aArray,
                                       bool aIsUsed)
   {
-    auto image = static_cast<Image*>(aRequest->mImage.get());
+    nsRefPtr<Image> image = aRequest->GetImage();
     if (!image) {
       return;
     }
 
     nsRefPtr<ImageURL> imageURL(image->GetURI());
     nsAutoCString spec;
     imageURL->GetSpec(spec);
 
@@ -427,17 +427,17 @@ private:
                                                     imgCacheEntry* aEntry,
                                                     void* aUserArg)
   {
     if (aEntry->HasNoProxies()) {
       return PL_DHASH_NEXT;
     }
 
     nsRefPtr<imgRequest> req = aEntry->GetRequest();
-    auto image = static_cast<Image*>(req->mImage.get());
+    nsRefPtr<Image> image = req->GetImage();
     if (!image) {
       return PL_DHASH_NEXT;
     }
 
     // Both this and EntryImageSizes measure images/content/raster/used/decoded
     // memory.  This function's measurement is secondary -- the result doesn't
     // go in the "explicit" tree -- so we use moz_malloc_size_of instead of
     // ImagesMallocSizeOf to prevent DMD from seeing it reported twice.
--- a/image/src/imgRequest.cpp
+++ b/image/src/imgRequest.cpp
@@ -145,17 +145,17 @@ nsresult imgRequest::Init(nsIURI *aURI,
   return NS_OK;
 }
 
 void imgRequest::ClearLoader() {
   mLoader = nullptr;
 }
 
 already_AddRefed<ProgressTracker>
-imgRequest::GetProgressTracker()
+imgRequest::GetProgressTracker() const
 {
   MutexAutoLock lock(mMutex);
 
   if (mImage) {
     MOZ_ASSERT(!mProgressTracker,
                "Should have given mProgressTracker to mImage");
     return mImage->GetProgressTracker();
   } else {
@@ -444,17 +444,18 @@ imgRequest::RemoveFromCache()
     } else {
       mLoader->RemoveFromCache(mURI);
     }
   }
 
   mCacheEntry = nullptr;
 }
 
-bool imgRequest::HasConsumers()
+bool
+imgRequest::HasConsumers() const
 {
   nsRefPtr<ProgressTracker> progressTracker = GetProgressTracker();
   return progressTracker && progressTracker->ObserverCount() > 0;
 }
 
 already_AddRefed<Image>
 imgRequest::GetImage() const
 {
--- a/image/src/imgRequest.h
+++ b/image/src/imgRequest.h
@@ -21,17 +21,16 @@
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/net/ReferrerPolicy.h"
 
 class imgCacheValidator;
 class imgLoader;
 class imgRequestProxy;
 class imgCacheEntry;
-class imgMemoryReporter;
 class nsIApplicationCache;
 class nsIProperties;
 class nsIRequest;
 class nsITimedChannel;
 class nsIURI;
 
 namespace mozilla {
 namespace image {
@@ -122,17 +121,17 @@ public:
   {
     nsCOMPtr<nsIPrincipal> principal = mLoadingPrincipal;
     return principal.forget();
   }
 
   // Return the ProgressTracker associated with this imgRequest. It may live
   // in |mProgressTracker| or in |mImage.mProgressTracker|, depending on whether
   // mImage has been instantiated yet.
-  already_AddRefed<ProgressTracker> GetProgressTracker();
+  already_AddRefed<ProgressTracker> GetProgressTracker() const;
 
   /// Returns the Image associated with this imgRequest, if it's ready.
   already_AddRefed<Image> GetImage() const;
 
   // Get the current principal of the image. No AddRefing.
   inline nsIPrincipal* GetPrincipal() const { return mPrincipal.get(); }
 
   // Resize the cache entry to 0 if it exists
@@ -184,43 +183,42 @@ public:
   /// try to update or modify the image cache.
   void SetIsInCache(bool aCacheable);
 
   void EvictFromCache();
   void RemoveFromCache();
 
   nsIProperties* Properties() const { return mProperties; }
 
+  bool HasConsumers() const;
+
 private:
   friend class mozilla::image::ProgressTracker;
 
   void Cancel(nsresult aStatus);
 
   // Update the cache entry size based on the image container.
   void UpdateCacheEntrySize();
 
-  bool HasConsumers();
-
   /// Returns true if RequestDecode() was called.
   bool IsDecodeRequested() const;
 
 public:
   NS_DECL_NSISTREAMLISTENER
   NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
   NS_DECL_NSIREQUESTOBSERVER
   NS_DECL_NSICHANNELEVENTSINK
   NS_DECL_NSIINTERFACEREQUESTOR
   NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
 
   // Sets properties for this image; will dispatch to main thread if needed.
   void SetProperties(const nsACString& aContentType,
                      const nsACString& aContentDisposition);
 
 private:
-  friend class imgMemoryReporter;
   friend class FinishPreparingForNewPartRunnable;
 
   void FinishPreparingForNewPart(const NewPartResult& aResult);
 
   // Weak reference to parent loader; this request cannot outlive its owner.
   imgLoader* mLoader;
   nsCOMPtr<nsIRequest> mRequest;
   // The original URI we were loaded with. This is the same as the URI we are