Bug 1098108 (Part 5) - Check consistency whenever progress changes in ProgressTracker. r=tn
authorSeth Fowler <seth@mozilla.com>
Fri, 14 Nov 2014 20:10:48 -0800
changeset 240210 c786bdac4406ca9920a83fa50e558750be6d5f60
parent 240209 0b3a6fee879c389028c97f903a1917c57fa9f365
child 240211 19f75e1211e671b62fd19887a19d4220f411d8e2
child 240256 3f85d8942e3eb2904067cb39ea9833c8c82f96b6
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs1098108
milestone36.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 1098108 (Part 5) - Check consistency whenever progress changes in ProgressTracker. r=tn
image/src/ProgressTracker.cpp
--- a/image/src/ProgressTracker.cpp
+++ b/image/src/ProgressTracker.cpp
@@ -36,16 +36,66 @@ ProgressTrackerInit::ProgressTrackerInit
   MOZ_ASSERT(mTracker);
 }
 
 ProgressTrackerInit::~ProgressTrackerInit()
 {
   mTracker->ResetImage();
 }
 
+static void
+CheckProgressConsistency(Progress aProgress)
+{
+  // Check preconditions for every progress bit.
+
+  if (aProgress & FLAG_REQUEST_STARTED) {
+    // No preconditions.
+  }
+  if (aProgress & FLAG_HAS_SIZE) {
+    MOZ_ASSERT(aProgress & FLAG_REQUEST_STARTED);
+  }
+  if (aProgress & FLAG_DECODE_STARTED) {
+    MOZ_ASSERT(aProgress & FLAG_REQUEST_STARTED);
+  }
+  if (aProgress & FLAG_DECODE_STOPPED) {
+    MOZ_ASSERT(aProgress & FLAG_DECODE_STARTED);
+  }
+  if (aProgress & FLAG_FRAME_STOPPED) {
+    MOZ_ASSERT(aProgress & FLAG_DECODE_STARTED);
+  }
+  if (aProgress & FLAG_REQUEST_STOPPED) {
+    MOZ_ASSERT(aProgress & FLAG_REQUEST_STARTED);
+  }
+  if (aProgress & FLAG_ONLOAD_BLOCKED) {
+    if (aProgress & FLAG_IS_MULTIPART) {
+      MOZ_ASSERT(aProgress & FLAG_ONLOAD_UNBLOCKED);
+    } else {
+      MOZ_ASSERT(aProgress & FLAG_DECODE_STARTED);
+    }
+  }
+  if (aProgress & FLAG_ONLOAD_UNBLOCKED) {
+    MOZ_ASSERT(aProgress & FLAG_ONLOAD_BLOCKED);
+    MOZ_ASSERT(aProgress & (FLAG_FRAME_STOPPED |
+                            FLAG_IS_MULTIPART |
+                            FLAG_HAS_ERROR));
+  }
+  if (aProgress & FLAG_IS_ANIMATED) {
+    MOZ_ASSERT(aProgress & FLAG_DECODE_STARTED);
+  }
+  if (aProgress & FLAG_IS_MULTIPART) {
+    // No preconditions.
+  }
+  if (aProgress & FLAG_MULTIPART_STOPPED) {
+    MOZ_ASSERT(aProgress & FLAG_REQUEST_STOPPED);
+  }
+  if (aProgress & FLAG_HAS_ERROR) {
+    // No preconditions.
+  }
+}
+
 void
 ProgressTracker::SetImage(Image* aImage)
 {
   NS_ABORT_IF_FALSE(aImage, "Setting null image");
   NS_ABORT_IF_FALSE(!mImage, "Setting image when we already have one");
   mImage = aImage;
 }
 
@@ -62,16 +112,18 @@ void ProgressTracker::SetIsMultipart()
     return;
   }
 
   MOZ_ASSERT(!(mProgress & FLAG_ONLOAD_BLOCKED),
              "Blocked onload before we knew we were multipart?");
 
   // Set the MULTIPART flag and ensure that we never block onload.
   mProgress |= FLAG_IS_MULTIPART | FLAG_ONLOAD_BLOCKED | FLAG_ONLOAD_UNBLOCKED;
+
+  CheckProgressConsistency(mProgress);
 }
 
 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.
@@ -311,16 +363,18 @@ ProgressTracker::SyncNotifyProgress(Prog
   Progress progress = Difference(aProgress);
   if (!((mProgress | progress) & FLAG_ONLOAD_BLOCKED)) {
     progress &= ~FLAG_ONLOAD_UNBLOCKED;
   }
 
   // Apply the changes.
   mProgress |= progress;
 
+  CheckProgressConsistency(mProgress);
+
   // Send notifications.
   SyncNotifyInternal(mConsumers, !!mImage, progress, aInvalidRect);
 
   if (progress & FLAG_HAS_ERROR) {
     FireFailureNotification();
   }
 }
 
@@ -430,16 +484,18 @@ void
 ProgressTracker::ResetForNewRequest()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // We're starting a new load (and if this is called more than once, this is a
   // multipart request) so keep only the bits that carry over between loads.
   mProgress &= FLAG_IS_MULTIPART | FLAG_HAS_ERROR |
                FLAG_ONLOAD_BLOCKED | FLAG_ONLOAD_UNBLOCKED;
+
+  CheckProgressConsistency(mProgress);
 }
 
 void
 ProgressTracker::OnDiscard()
 {
   MOZ_ASSERT(NS_IsMainThread());
   NOTIFY_IMAGE_OBSERVERS(mConsumers, OnDiscard());
 }