Bug 1268313: Part 1 - Be explicit about which NewRunnableMethod callers want to be able to cancel. r=froydnj
authorKyle Huey <khuey@kylehuey.com>
Thu, 05 May 2016 01:44:59 -0700
changeset 335204 bf5001ed992f96517e6d35409f3d07c0351d4986
parent 335203 03540c2e61c12a3e31869efb34fcee59b0adeec3
child 335205 c8b8d67ee83372c56a761821f5eb63e98abdf679
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1268313
milestone49.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 1268313: Part 1 - Be explicit about which NewRunnableMethod callers want to be able to cancel. r=froydnj
dom/ipc/ContentChild.cpp
dom/plugins/ipc/PluginInstanceChild.cpp
dom/plugins/ipc/PluginInstanceParent.cpp
gfx/layers/apz/src/GestureEventListener.cpp
gfx/layers/apz/util/ActiveElementManager.cpp
gfx/layers/ipc/CompositorBridgeParent.cpp
gfx/thebes/SoftwareVsyncSource.cpp
ipc/chromium/src/base/task.h
ipc/glue/MessageChannel.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -1575,17 +1575,17 @@ ContentChild::RecvPBrowserConstructor(PB
     os->NotifyObservers(tc, "tab-child-created", nullptr);
   }
 
   static bool hasRunOnce = false;
   if (!hasRunOnce) {
       hasRunOnce = true;
 
     MOZ_ASSERT(!sFirstIdleTask);
-    RefPtr<CancelableRunnable> firstIdleTask = NewRunnableFunction(FirstIdle);
+    RefPtr<CancelableRunnable> firstIdleTask = NewCancelableRunnableFunction(FirstIdle);
     sFirstIdleTask = firstIdleTask;
     MessageLoop::current()->PostIdleTask(firstIdleTask.forget());
 
     // Redo InitProcessAttributes() when the app or browser is really
     // launching so the attributes will be correct.
     mID = aCpID;
     mIsForApp = aIsForApp;
     mIsForBrowser = aIsForBrowser;
--- a/dom/plugins/ipc/PluginInstanceChild.cpp
+++ b/dom/plugins/ipc/PluginInstanceChild.cpp
@@ -3294,19 +3294,19 @@ PluginInstanceChild::RecvAsyncSetWindow(
         mCurrentAsyncSetWindowTask->Cancel();
         mCurrentAsyncSetWindowTask = nullptr;
     }
 
     // We shouldn't process this now because it may be received within a nested
     // RPC call, and both Flash and Java don't expect to receive setwindow calls
     // at arbitrary times.
     mCurrentAsyncSetWindowTask =
-        NewRunnableMethod<PluginInstanceChild,
-                          void (PluginInstanceChild::*)(const gfxSurfaceType&, const NPRemoteWindow&, bool),
-                          const gfxSurfaceType&, const NPRemoteWindow&, bool>
+        NewCancelableRunnableMethod<PluginInstanceChild,
+                                    void (PluginInstanceChild::*)(const gfxSurfaceType&, const NPRemoteWindow&, bool),
+                                    const gfxSurfaceType&, const NPRemoteWindow&, bool>
         (this, &PluginInstanceChild::DoAsyncSetWindow,
          aSurfaceType, aWindow, true);
     RefPtr<Runnable> addrefedTask = mCurrentAsyncSetWindowTask;
     MessageLoop::current()->PostTask(addrefedTask.forget());
 
     return true;
 }
 
@@ -4218,17 +4218,17 @@ PluginInstanceChild::AsyncShowPluginFram
     // When the plugin is using direct surfaces to draw, it is not driving
     // paints via paint events - it will drive painting via its own events
     // and/or DidComposite callbacks.
     if (IsUsingDirectDrawing()) {
         return;
     }
 
     mCurrentInvalidateTask =
-        NewRunnableMethod(this, &PluginInstanceChild::InvalidateRectDelayed);
+        NewCancelableRunnableMethod(this, &PluginInstanceChild::InvalidateRectDelayed);
     RefPtr<Runnable> addrefedTask = mCurrentInvalidateTask;
     MessageLoop::current()->PostTask(addrefedTask.forget());
 }
 
 void
 PluginInstanceChild::InvalidateRect(NPRect* aInvalidRect)
 {
     NS_ASSERTION(aInvalidRect, "Null pointer!");
--- a/dom/plugins/ipc/PluginInstanceParent.cpp
+++ b/dom/plugins/ipc/PluginInstanceParent.cpp
@@ -1218,17 +1218,17 @@ PluginInstanceParent::EndUpdateBackgroun
 void
 PluginInstanceParent::ScheduleScrollCapture(int aTimeout)
 {
     if (mCaptureRefreshTask) {
         return;
     }
     CAPTURE_LOG("delayed scroll capture requested.");
     mCaptureRefreshTask =
-        NewRunnableMethod(this, &PluginInstanceParent::ScheduledUpdateScrollCaptureCallback);
+        NewCancelableRunnableMethod(this, &PluginInstanceParent::ScheduledUpdateScrollCaptureCallback);
     RefPtr<Runnable> addrefedTask = mCaptureRefreshTask;
     MessageLoop::current()->PostDelayedTask(addrefedTask.forget(),
                                             kScrollCaptureDelayMs);
 }
 
 void
 PluginInstanceParent::ScheduledUpdateScrollCaptureCallback()
 {
--- a/gfx/layers/apz/src/GestureEventListener.cpp
+++ b/gfx/layers/apz/src/GestureEventListener.cpp
@@ -493,17 +493,17 @@ void GestureEventListener::CancelLongTap
     mLongTapTimeoutTask->Cancel();
     mLongTapTimeoutTask = nullptr;
   }
 }
 
 void GestureEventListener::CreateLongTapTimeoutTask()
 {
   RefPtr<CancelableRunnable> task =
-    NewRunnableMethod(this, &GestureEventListener::HandleInputTimeoutLongTap);
+    NewCancelableRunnableMethod(this, &GestureEventListener::HandleInputTimeoutLongTap);
 
   mLongTapTimeoutTask = task;
   mAsyncPanZoomController->PostDelayedTask(
     task.forget(),
     gfxPrefs::UiClickHoldContextMenusDelay());
 }
 
 void GestureEventListener::CancelMaxTapTimeoutTask()
@@ -520,18 +520,18 @@ void GestureEventListener::CancelMaxTapT
 }
 
 void GestureEventListener::CreateMaxTapTimeoutTask()
 {
   mLastTapInput = mLastTouchInput;
 
   TouchBlockState* block = mAsyncPanZoomController->GetInputQueue()->CurrentTouchBlock();
   RefPtr<CancelableRunnable> task =
-    NewRunnableMethod(this, &GestureEventListener::HandleInputTimeoutMaxTap,
-                      block->IsDuringFastFling());
+    NewCancelableRunnableMethod(this, &GestureEventListener::HandleInputTimeoutMaxTap,
+                                block->IsDuringFastFling());
 
   mMaxTapTimeoutTask = task;
   mAsyncPanZoomController->PostDelayedTask(
     task.forget(),
     MAX_TAP_TIME);
 }
 
 } // namespace layers
--- a/gfx/layers/apz/util/ActiveElementManager.cpp
+++ b/gfx/layers/apz/util/ActiveElementManager.cpp
@@ -89,17 +89,17 @@ ActiveElementManager::TriggerElementActi
   // Otherwise, wait a bit to see if the user will pan or not.
   if (!mCanBePan) {
     SetActive(mTarget);
   } else {
     CancelTask();   // this is only needed because of bug 1169802. Fixing that
                     // bug properly should make this unnecessary.
     MOZ_ASSERT(mSetActiveTask == nullptr);
 
-    RefPtr<CancelableRunnable> task = NewRunnableMethod(
+    RefPtr<CancelableRunnable> task = NewCancelableRunnableMethod(
         this, &ActiveElementManager::SetActiveTask, mTarget);
     mSetActiveTask = task;
     MessageLoop::current()->PostDelayedTask(task.forget(), sActivationDelayMs);
     AEM_LOG("Scheduling mSetActiveTask %p\n", mSetActiveTask);
   }
 }
 
 void
--- a/gfx/layers/ipc/CompositorBridgeParent.cpp
+++ b/gfx/layers/ipc/CompositorBridgeParent.cpp
@@ -421,18 +421,18 @@ CompositorVsyncScheduler::Destroy()
 
 void
 CompositorVsyncScheduler::PostCompositeTask(TimeStamp aCompositeTimestamp)
 {
   // can be called from the compositor or vsync thread
   MonitorAutoLock lock(mCurrentCompositeTaskMonitor);
   if (mCurrentCompositeTask == nullptr) {
     RefPtr<CancelableRunnable> task =
-      NewRunnableMethod(this, &CompositorVsyncScheduler::Composite,
-                        aCompositeTimestamp);
+      NewCancelableRunnableMethod(this, &CompositorVsyncScheduler::Composite,
+                                  aCompositeTimestamp);
     mCurrentCompositeTask = task;
     ScheduleTask(task.forget(), 0);
   }
 }
 
 void
 CompositorVsyncScheduler::ScheduleComposition()
 {
@@ -475,17 +475,17 @@ CompositorVsyncScheduler::CancelCurrentS
  * How many skipped vsync events until we stop listening to vsync events?
  */
 void
 CompositorVsyncScheduler::SetNeedsComposite()
 {
   if (!CompositorBridgeParent::IsInCompositorThread()) {
     MonitorAutoLock lock(mSetNeedsCompositeMonitor);
     RefPtr<CancelableRunnable> task =
-      NewRunnableMethod(this, &CompositorVsyncScheduler::SetNeedsComposite);
+      NewCancelableRunnableMethod(this, &CompositorVsyncScheduler::SetNeedsComposite);
     mSetNeedsCompositeTask = task;
     ScheduleTask(task.forget(), 0);
     return;
   } else {
     MonitorAutoLock lock(mSetNeedsCompositeMonitor);
     mSetNeedsCompositeTask = nullptr;
   }
 
@@ -1358,17 +1358,17 @@ CompositorBridgeParent::ScheduleRotation
   MOZ_ASSERT(IsInCompositorThread());
 
   if (!aIsFirstPaint &&
       !mCompositionManager->IsFirstPaint() &&
       mCompositionManager->RequiresReorientation(aTargetConfig.orientation())) {
     if (mForceCompositionTask != nullptr) {
       mForceCompositionTask->Cancel();
     }
-    RefPtr<CancelableRunnable> task = NewRunnableMethod(this, &CompositorBridgeParent::ForceComposition);
+    RefPtr<CancelableRunnable> task = NewCancelableRunnableMethod(this, &CompositorBridgeParent::ForceComposition);
     mForceCompositionTask = task;
     ScheduleTask(task.forget(), gfxPrefs::OrientationSyncMillis());
   }
 }
 
 void
 CompositorBridgeParent::ShadowLayersUpdated(LayerTransactionParent* aLayerTree,
                                             const uint64_t& aTransactionId,
--- a/gfx/thebes/SoftwareVsyncSource.cpp
+++ b/gfx/thebes/SoftwareVsyncSource.cpp
@@ -123,21 +123,21 @@ SoftwareDisplay::ScheduleNextVsync(mozil
   MOZ_ASSERT(IsInSoftwareVsyncThread());
   mozilla::TimeStamp nextVsync = aVsyncTimestamp + mVsyncRate;
   mozilla::TimeDuration delay = nextVsync - mozilla::TimeStamp::Now();
   if (delay.ToMilliseconds() < 0) {
     delay = mozilla::TimeDuration::FromMilliseconds(0);
     nextVsync = mozilla::TimeStamp::Now();
   }
 
-  mCurrentVsyncTask = NewRunnableMethod(this,
+  mCurrentVsyncTask = NewCancelableRunnableMethod(this,
       &SoftwareDisplay::NotifyVsync,
       nextVsync);
 
-  RefPtr<mozilla::CancelableRunnable> addrefedTask = mCurrentVsyncTask;
+  RefPtr<mozilla::Runnable> addrefedTask = mCurrentVsyncTask;
   mVsyncThread->message_loop()->PostDelayedTask(
       addrefedTask.forget(),
       delay.ToMilliseconds());
 }
 
 void
 SoftwareDisplay::Shutdown()
 {
--- a/ipc/chromium/src/base/task.h
+++ b/ipc/chromium/src/base/task.h
@@ -300,19 +300,29 @@ class RunnableMethod : public mozilla::C
   // constructor and destructor.
   T* MOZ_OWNING_REF obj_;
   Method meth_;
   Params params_;
 };
 
 template <class T, class Method, typename... Args>
 inline already_AddRefed<mozilla::CancelableRunnable>
+NewCancelableRunnableMethod(T* object, Method method, Args&&... args) {
+  typedef mozilla::Tuple<typename mozilla::Decay<Args>::Type...> ArgsTuple;
+  RefPtr<mozilla::CancelableRunnable> t =
+    new RunnableMethod<T, Method, ArgsTuple>(object, method,
+                                             mozilla::MakeTuple(mozilla::Forward<Args>(args)...));
+  return t.forget();
+}
+
+template <class T, class Method, typename... Args>
+inline already_AddRefed<mozilla::Runnable>
 NewRunnableMethod(T* object, Method method, Args&&... args) {
   typedef mozilla::Tuple<typename mozilla::Decay<Args>::Type...> ArgsTuple;
-  RefPtr<mozilla::CancelableRunnable> t =
+  RefPtr<mozilla::Runnable> t =
     new RunnableMethod<T, Method, ArgsTuple>(object, method,
                                              mozilla::MakeTuple(mozilla::Forward<Args>(args)...));
   return t.forget();
 }
 
 // RunnableFunction and NewRunnableFunction implementation ---------------------
 
 template <class Function, class Params>
@@ -337,17 +347,27 @@ class RunnableFunction : public mozilla:
   }
 
   Function function_;
   Params params_;
 };
 
 template <class Function, typename... Args>
 inline already_AddRefed<mozilla::CancelableRunnable>
-NewRunnableFunction(Function function, Args&&... args) {
+NewCancelableRunnableFunction(Function function, Args&&... args) {
   typedef mozilla::Tuple<typename mozilla::Decay<Args>::Type...> ArgsTuple;
   RefPtr<mozilla::CancelableRunnable> t =
     new RunnableFunction<Function, ArgsTuple>(function,
                                               mozilla::MakeTuple(mozilla::Forward<Args>(args)...));
   return t.forget();
 }
 
+template <class Function, typename... Args>
+inline already_AddRefed<mozilla::Runnable>
+NewRunnableFunction(Function function, Args&&... args) {
+  typedef mozilla::Tuple<typename mozilla::Decay<Args>::Type...> ArgsTuple;
+  RefPtr<mozilla::Runnable> t =
+    new RunnableFunction<Function, ArgsTuple>(function,
+                                              mozilla::MakeTuple(mozilla::Forward<Args>(args)...));
+  return t.forget();
+}
+
 #endif  // BASE_TASK_H_
--- a/ipc/glue/MessageChannel.cpp
+++ b/ipc/glue/MessageChannel.cpp
@@ -497,21 +497,21 @@ MessageChannel::MessageChannel(MessageLi
 {
     MOZ_COUNT_CTOR(ipc::MessageChannel);
 
 #ifdef OS_WIN
     mTopFrame = nullptr;
     mIsSyncWaitingOnNonMainThread = false;
 #endif
 
-    mDequeueOneTask = new RefCountedTask(NewRunnableMethod(
+    mDequeueOneTask = new RefCountedTask(NewCancelableRunnableMethod(
                                                  this,
                                                  &MessageChannel::OnMaybeDequeueOne));
 
-    mOnChannelConnectedTask = new RefCountedTask(NewRunnableMethod(
+    mOnChannelConnectedTask = new RefCountedTask(NewCancelableRunnableMethod(
         this,
         &MessageChannel::DispatchOnChannelConnected));
 
 #ifdef OS_WIN
     mEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
     MOZ_RELEASE_ASSERT(mEvent, "CreateEvent failed! Nothing is going to work!");
 #endif
 }
@@ -2096,17 +2096,17 @@ MessageChannel::OnNotifyMaybeChannelErro
     // should only continue once OnChannelError has completed.
     {
         MonitorAutoLock lock(*mMonitor);
         // nothing to do here
     }
 
     if (IsOnCxxStack()) {
         mChannelErrorTask =
-            NewRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError);
+            NewCancelableRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError);
         RefPtr<Runnable> task = mChannelErrorTask;
         // 10 ms delay is completely arbitrary
         mWorkerLoop->PostDelayedTask(task.forget(), 10);
         return;
     }
 
     NotifyMaybeChannelError();
 }
@@ -2116,17 +2116,17 @@ MessageChannel::PostErrorNotifyTask()
 {
     mMonitor->AssertCurrentThreadOwns();
 
     if (mChannelErrorTask)
         return;
 
     // This must be the last code that runs on this thread!
     mChannelErrorTask =
-        NewRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError);
+        NewCancelableRunnableMethod(this, &MessageChannel::OnNotifyMaybeChannelError);
     RefPtr<Runnable> task = mChannelErrorTask;
     mWorkerLoop->PostTask(task.forget());
 }
 
 // Special async message.
 class GoodbyeMessage : public IPC::Message
 {
 public: