Bug 1097432 (Part 1) - Remove imgStatusTracker::Send* methods and clean up. r=tn
authorSeth Fowler <seth@mozilla.com>
Fri, 14 Nov 2014 20:10:47 -0800
changeset 215889 a958224850fbd17a9f388fce16e422e2d982a73d
parent 215888 1d1810ba0ebf323cff97648732547786df12cc87
child 215890 6dee00e11ec284535dcde2150f6eeb12e88e843a
push id27829
push usergszorc@mozilla.com
push dateSat, 15 Nov 2014 22:34:49 +0000
treeherdermozilla-central@19f75e1211e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn
bugs1097432
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 1097432 (Part 1) - Remove imgStatusTracker::Send* methods and clean up. r=tn
image/src/imgStatusTracker.cpp
image/src/imgStatusTracker.h
--- a/image/src/imgStatusTracker.cpp
+++ b/image/src/imgStatusTracker.cpp
@@ -220,79 +220,80 @@ imgStatusTracker::NotifyCurrentState(img
 
   proxy->SetNotificationsDeferred(true);
 
   // We don't keep track of
   nsCOMPtr<nsIRunnable> ev = new imgStatusNotifyRunnable(this, proxy);
   NS_DispatchToCurrentThread(ev);
 }
 
-#define NOTIFY_IMAGE_OBSERVERS(func) \
+#define NOTIFY_IMAGE_OBSERVERS(PROXIES, FUNC) \
   do { \
-    ProxyArray::ForwardIterator iter(aProxies); \
+    ProxyArray::ForwardIterator iter(PROXIES); \
     while (iter.HasMore()) { \
       nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get(); \
       if (proxy && !proxy->NotificationsDeferred()) { \
-        proxy->func; \
+        proxy->FUNC; \
       } \
     } \
   } while (false);
 
 /* static */ void
 imgStatusTracker::SyncNotifyState(ProxyArray& aProxies,
                                   bool aHasImage, uint32_t aState,
                                   const nsIntRect& aDirtyRect)
 {
   MOZ_ASSERT(NS_IsMainThread());
   // OnStartRequest
   if (aState & FLAG_REQUEST_STARTED)
-    NOTIFY_IMAGE_OBSERVERS(OnStartRequest());
+    NOTIFY_IMAGE_OBSERVERS(aProxies, OnStartRequest());
 
   // OnStartContainer
   if (aState & FLAG_HAS_SIZE)
-    NOTIFY_IMAGE_OBSERVERS(OnStartContainer());
+    NOTIFY_IMAGE_OBSERVERS(aProxies, OnStartContainer());
 
   // OnStartDecode
   if (aState & FLAG_DECODE_STARTED)
-    NOTIFY_IMAGE_OBSERVERS(OnStartDecode());
+    NOTIFY_IMAGE_OBSERVERS(aProxies, OnStartDecode());
 
   // BlockOnload
   if (aState & FLAG_ONLOAD_BLOCKED)
-    NOTIFY_IMAGE_OBSERVERS(BlockOnload());
+    NOTIFY_IMAGE_OBSERVERS(aProxies, BlockOnload());
 
   if (aHasImage) {
     // OnFrameUpdate
     // If there's any content in this frame at all (always true for
     // vector images, true for raster images that have decoded at
     // least one frame) then send OnFrameUpdate.
     if (!aDirtyRect.IsEmpty())
-      NOTIFY_IMAGE_OBSERVERS(OnFrameUpdate(&aDirtyRect));
+      NOTIFY_IMAGE_OBSERVERS(aProxies, OnFrameUpdate(&aDirtyRect));
 
     if (aState & FLAG_FRAME_STOPPED)
-      NOTIFY_IMAGE_OBSERVERS(OnStopFrame());
+      NOTIFY_IMAGE_OBSERVERS(aProxies, OnStopFrame());
 
     // OnImageIsAnimated
     if (aState & FLAG_IS_ANIMATED)
-      NOTIFY_IMAGE_OBSERVERS(OnImageIsAnimated());
+      NOTIFY_IMAGE_OBSERVERS(aProxies, OnImageIsAnimated());
   }
 
   // Send UnblockOnload before OnStopDecode and OnStopRequest. This allows
   // observers that can fire events when they receive those notifications to do
   // so then, instead of being forced to wait for UnblockOnload.
   if (aState & FLAG_ONLOAD_UNBLOCKED) {
-    NOTIFY_IMAGE_OBSERVERS(UnblockOnload());
+    NOTIFY_IMAGE_OBSERVERS(aProxies, UnblockOnload());
   }
 
   if (aState & FLAG_DECODE_STOPPED) {
     MOZ_ASSERT(aHasImage, "Stopped decoding without ever having an image?");
-    NOTIFY_IMAGE_OBSERVERS(OnStopDecode());
+    NOTIFY_IMAGE_OBSERVERS(aProxies, OnStopDecode());
   }
 
   if (aState & FLAG_REQUEST_STOPPED) {
-    NOTIFY_IMAGE_OBSERVERS(OnStopRequest(aState & FLAG_MULTIPART_STOPPED));
+    NOTIFY_IMAGE_OBSERVERS(aProxies,
+                           OnStopRequest(aState & FLAG_MULTIPART_STOPPED));
   }
 }
 
 ImageStatusDiff
 imgStatusTracker::Difference(const ImageStatusDiff& aOther) const
 {
   ImageStatusDiff diff;
   diff.diffState = ~mState & aOther.diffState;
@@ -418,200 +419,73 @@ imgStatusTracker::FirstConsumerIs(imgReq
 
 void
 imgStatusTracker::RecordError()
 {
   mState |= FLAG_HAS_ERROR;
 }
 
 void
-imgStatusTracker::SendStartDecode(imgRequestProxy* aProxy)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred())
-    aProxy->OnStartDecode();
-}
-
-void
-imgStatusTracker::SendStartContainer(imgRequestProxy* aProxy)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred())
-    aProxy->OnStartContainer();
-}
-
-void
-imgStatusTracker::SendStopFrame(imgRequestProxy* aProxy)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred())
-    aProxy->OnStopFrame();
-}
-
-void
-imgStatusTracker::SendStopDecode(imgRequestProxy* aProxy,
-                                 nsresult aStatus)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred())
-    aProxy->OnStopDecode();
-}
-
-void
-imgStatusTracker::SendDiscard(imgRequestProxy* aProxy)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred())
-    aProxy->OnDiscard();
-}
-
-
-void
-imgStatusTracker::SendImageIsAnimated(imgRequestProxy* aProxy)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred())
-    aProxy->OnImageIsAnimated();
-}
-
-void
-imgStatusTracker::SendUnlockedDraw(imgRequestProxy* aProxy)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred())
-    aProxy->OnUnlockedDraw();
-}
-
-void
 imgStatusTracker::OnUnlockedDraw()
 {
   MOZ_ASSERT(NS_IsMainThread());
-  ProxyArray::ForwardIterator iter(mConsumers);
-  while (iter.HasMore()) {
-    nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
-    if (proxy) {
-      SendUnlockedDraw(proxy);
-    }
-  }
-}
-
-/* non-virtual sort-of-nsIRequestObserver methods */
-void
-imgStatusTracker::SendStartRequest(imgRequestProxy* aProxy)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred())
-    aProxy->OnStartRequest();
+  NOTIFY_IMAGE_OBSERVERS(mConsumers, OnUnlockedDraw());
 }
 
 void
 imgStatusTracker::OnStartRequest()
 {
   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.
   mState &= FLAG_IS_MULTIPART | FLAG_HAS_ERROR;
   mState |= FLAG_REQUEST_STARTED;
 
-  ProxyArray::ForwardIterator iter(mConsumers);
-  while (iter.HasMore()) {
-    nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
-    if (proxy) {
-      SendStartRequest(proxy);
-    }
-  }
-}
-
-void
-imgStatusTracker::SendStopRequest(imgRequestProxy* aProxy,
-                                  bool aLastPart,
-                                  nsresult aStatus)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred()) {
-    aProxy->OnStopRequest(aLastPart);
-  }
+  NOTIFY_IMAGE_OBSERVERS(mConsumers, OnStartRequest());
 }
 
 void
 imgStatusTracker::OnDiscard()
 {
   MOZ_ASSERT(NS_IsMainThread());
-
-  /* notify the kids */
-  ProxyArray::ForwardIterator iter(mConsumers);
-  while (iter.HasMore()) {
-    nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
-    if (proxy) {
-      SendDiscard(proxy);
-    }
-  }
+  NOTIFY_IMAGE_OBSERVERS(mConsumers, OnDiscard());
 }
 
 void
 imgStatusTracker::OnDataAvailable()
 {
   if (!NS_IsMainThread()) {
     // Note: SetHasImage calls Image::Lock and Image::IncrementAnimationCounter
     // so subsequent calls or dispatches which Unlock or Decrement~ should
     // be issued after this to avoid race conditions.
     NS_DispatchToMainThread(
       NS_NewRunnableMethod(this, &imgStatusTracker::OnDataAvailable));
     return;
   }
-  // Notify any imgRequestProxys that are observing us that we have an Image.
-  ProxyArray::ForwardIterator iter(mConsumers);
-  while (iter.HasMore()) {
-    nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
-    if (proxy) {
-      proxy->SetHasImage();
-    }
-  }
-}
 
-void
-imgStatusTracker::SendBlockOnload(imgRequestProxy* aProxy)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred()) {
-    aProxy->BlockOnload();
-  }
-}
-
-void
-imgStatusTracker::SendUnblockOnload(imgRequestProxy* aProxy)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  if (!aProxy->NotificationsDeferred()) {
-    aProxy->UnblockOnload();
-  }
+  NOTIFY_IMAGE_OBSERVERS(mConsumers, SetHasImage());
 }
 
 void
 imgStatusTracker::MaybeUnblockOnload()
 {
   if (!NS_IsMainThread()) {
     NS_DispatchToMainThread(
       NS_NewRunnableMethod(this, &imgStatusTracker::MaybeUnblockOnload));
     return;
   }
+
   if (!(mState & FLAG_ONLOAD_BLOCKED) || (mState & FLAG_ONLOAD_UNBLOCKED)) {
     return;
   }
 
   mState |= FLAG_ONLOAD_UNBLOCKED;
 
-  ProxyArray::ForwardIterator iter(mConsumers);
-  while (iter.HasMore()) {
-    nsRefPtr<imgRequestProxy> proxy = iter.GetNext().get();
-    if (proxy) {
-      SendUnblockOnload(proxy);
-    }
-  }
+  NOTIFY_IMAGE_OBSERVERS(mConsumers, UnblockOnload());
 }
 
 void
 imgStatusTracker::FireFailureNotification()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // Some kind of problem has happened with image decoding.
--- a/image/src/imgStatusTracker.h
+++ b/image/src/imgStatusTracker.h
@@ -175,48 +175,25 @@ public:
 
   // Returns whether we are in the process of loading; that is, whether we have
   // not received OnStopRequest.
   bool IsLoading() const;
 
   // Get the current image status (as in imgIRequest).
   uint32_t GetImageStatus() const;
 
-  // Functions with prefix Send- are main thread only, since they contain calls
-  // to imgRequestProxy functions, which are expected on the main thread.
-  void SendStartDecode(imgRequestProxy* aProxy);
-  void SendStartContainer(imgRequestProxy* aProxy);
-  void SendStopFrame(imgRequestProxy* aProxy);
-  void SendStopDecode(imgRequestProxy* aProxy, nsresult aStatus);
-  void SendDiscard(imgRequestProxy* aProxy);
-  void SendUnlockedDraw(imgRequestProxy* aProxy);
-  void SendImageIsAnimated(imgRequestProxy *aProxy);
-
-  /* non-virtual sort-of-nsIRequestObserver methods */
-  // Functions with prefix Send- are main thread only, since they contain calls
-  // to imgRequestProxy functions, which are expected on the main thread.
-  void SendStartRequest(imgRequestProxy* aProxy);
-  void SendStopRequest(imgRequestProxy* aProxy, bool aLastPart, nsresult aStatus);
-
-  // All main thread only because they call functions (like SendStartRequest)
-  // which are expected to be called on the main thread.
+  // All main thread only because they call functions which are expected to be
+  // called on the main thread.
   void OnStartRequest();
   // OnDataAvailable will dispatch a call to itself onto the main thread if not
   // called there.
   void OnDataAvailable();
   void OnDiscard();
   void OnUnlockedDraw();
 
-  /* non-virtual imgIOnloadBlocker methods */
-  // NB: If UnblockOnload is sent, and then we are asked to replay the
-  // notifications, we will not send a BlockOnload/UnblockOnload pair.  This
-  // is different from all the other notifications.
-  void SendBlockOnload(imgRequestProxy* aProxy);
-  void SendUnblockOnload(imgRequestProxy* aProxy);
-
   // Main thread only because mConsumers is not threadsafe.
   void MaybeUnblockOnload();
 
   void RecordError();
 
   bool IsMultipart() const { return mState & mozilla::image::FLAG_IS_MULTIPART; }
 
   // Weak pointer getters - no AddRefs.