Bug 1268313: Part 1 - Be explicit about which NewRunnableMethod callers want to be able to cancel. r=froydnj
☠☠ backed out by 4026758d1d02 ☠ ☠
authorKyle Huey <khuey@kylehuey.com>
Thu, 28 Apr 2016 14:08:24 -0700
changeset 357667 af51821b2fc52323a8bbeae3efd2d49c77b1ea7e
parent 357666 b4dfa9f7f63cd920d559bcb64934326c3a2c9bee
child 357668 fd833da413ad93c9ff893360f1b9a2f32dd371af
push id16816
push userbmo:gasolin@mozilla.com
push dateFri, 29 Apr 2016 03:33:20 +0000
reviewersfroydnj
bugs1268313
milestone49.0a1
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
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
@@ -1594,17 +1594,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/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
@@ -422,18 +422,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()
 {
@@ -476,17 +476,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;
   }
 
@@ -1360,17 +1360,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
 }
@@ -2086,17 +2086,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();
 }
@@ -2106,17 +2106,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: