Bug 1125401 - Replace ProgressTracker::IsLoading() with checks of the correct progress flags. r=tn, a=sledru
authorSeth Fowler <seth@mozilla.com>
Sat, 24 Jan 2015 23:16:46 -0800
changeset 243681 41f8742f7c93
parent 243680 a6b21fce4c12
child 243682 8f52ac825ba7
push id4434
push userryanvm@gmail.com
push date2015-02-04 16:40 +0000
treeherdermozilla-beta@8f52ac825ba7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn, sledru
bugs1125401
milestone36.0
Bug 1125401 - Replace ProgressTracker::IsLoading() with checks of the correct progress flags. r=tn, a=sledru
image/src/ClippedImage.cpp
image/src/ProgressTracker.cpp
image/src/ProgressTracker.h
image/src/imgRequest.cpp
--- a/image/src/ClippedImage.cpp
+++ b/image/src/ClippedImage.cpp
@@ -142,17 +142,18 @@ ClippedImage::ShouldClip()
     } else if (NS_SUCCEEDED(InnerImage()->GetWidth(&width)) && width > 0 &&
                NS_SUCCEEDED(InnerImage()->GetHeight(&height)) && height > 0) {
       // Clamp the clipping region to the size of the underlying image.
       mClip = mClip.Intersect(nsIntRect(0, 0, width, height));
 
       // If the clipping region is the same size as the underlying image we
       // don't have to do anything.
       mShouldClip.emplace(!mClip.IsEqualInterior(nsIntRect(0, 0, width, height)));
-    } else if (progressTracker && progressTracker->IsLoading()) {
+    } else if (progressTracker &&
+               !(progressTracker->GetProgress() & FLAG_LOAD_COMPLETE)) {
       // The image just hasn't finished loading yet. We don't yet know whether
       // clipping with be needed or not for now. Just return without memoizing
       // anything.
       return false;
     } else {
       // We have a fully loaded image without a clearly defined width and
       // height. This can happen with SVG images.
       mShouldClip.emplace(false);
--- a/image/src/ProgressTracker.cpp
+++ b/image/src/ProgressTracker.cpp
@@ -94,25 +94,16 @@ ProgressTracker::SetImage(Image* aImage)
 
 void
 ProgressTracker::ResetImage()
 {
   NS_ABORT_IF_FALSE(mImage, "Resetting image when it's already null!");
   mImage = nullptr;
 }
 
-bool
-ProgressTracker::IsLoading() const
-{
-  // Checking for whether OnStopRequest has fired allows us to say we're
-  // loading before OnStartRequest gets called, letting the request properly
-  // get removed from the cache in certain cases.
-  return !(mProgress & FLAG_LOAD_COMPLETE);
-}
-
 uint32_t
 ProgressTracker::GetImageStatus() const
 {
   uint32_t status = imgIRequest::STATUS_NONE;
 
   // Translate our current state to a set of imgIRequest::STATE_* flags.
   if (mProgress & FLAG_SIZE_AVAILABLE) {
     status |= imgIRequest::STATUS_SIZE_AVAILABLE;
--- a/image/src/ProgressTracker.h
+++ b/image/src/ProgressTracker.h
@@ -83,20 +83,16 @@ public:
 
   bool HasImage() const { return mImage; }
   already_AddRefed<Image> GetImage() const
   {
     nsRefPtr<Image> image = mImage;
     return image.forget();
   }
 
-  // Returns whether we are in the process of loading; that is, whether we have
-  // not received OnStopRequest from Necko.
-  bool IsLoading() const;
-
   // Get the current image status (as in imgIRequest).
   uint32_t GetImageStatus() const;
 
   // Get the current Progress.
   Progress GetProgress() const { return mProgress; }
 
   // Schedule an asynchronous "replaying" of all the notifications that would
   // have to happen to put us in the current state.
--- a/image/src/imgRequest.cpp
+++ b/image/src/imgRequest.cpp
@@ -227,17 +227,18 @@ nsresult imgRequest::RemoveProxy(imgRequ
     }
 #endif
 
     /* If |aStatus| is a failure code, then cancel the load if it is still in progress.
        Otherwise, let the load continue, keeping 'this' in the cache with no observers.
        This way, if a proxy is destroyed without calling cancel on it, it won't leak
        and won't leave a bad pointer in the observer list.
      */
-    if (progressTracker->IsLoading() && NS_FAILED(aStatus)) {
+    if (!(progressTracker->GetProgress() & FLAG_LAST_PART_COMPLETE) &&
+        NS_FAILED(aStatus)) {
       LOG_MSG(GetImgLog(), "imgRequest::RemoveProxy", "load in progress.  canceling");
 
       this->Cancel(NS_BINDING_ABORTED);
     }
 
     /* break the cycle from the cache entry. */
     mCacheEntry = nullptr;
   }
@@ -303,17 +304,17 @@ void imgRequest::ContinueCancel(nsresult
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   nsRefPtr<ProgressTracker> progressTracker = GetProgressTracker();
   progressTracker->SyncNotifyProgress(FLAG_HAS_ERROR | FLAG_ONLOAD_UNBLOCKED);
 
   RemoveFromCache();
 
-  if (mRequest && progressTracker->IsLoading()) {
+  if (mRequest && !(progressTracker->GetProgress() & FLAG_LAST_PART_COMPLETE)) {
      mRequest->Cancel(aStatus);
   }
 }
 
 class imgRequestMainThreadEvict : public nsRunnable
 {
 public:
   explicit imgRequestMainThreadEvict(imgRequest *aImgRequest)