Bug 1217251 - Add APZThreadUtils::RunDelayedTaskOnCurrentThread(). r=kats
authorBotond Ballo <botond@mozilla.com>
Thu, 22 Oct 2015 16:45:26 -0400
changeset 304581 027c42d1dcc89962df6a9185e3f463ffd6aeccc6
parent 304580 d991f3e80e78f978f20156f0d7b58099e3e6f97c
child 304582 c6404f3d787c497242d7a5cc2d1ea9796205e991
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1217251
milestone44.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 1217251 - Add APZThreadUtils::RunDelayedTaskOnCurrentThread(). r=kats
gfx/layers/apz/util/APZThreadUtils.cpp
gfx/layers/apz/util/APZThreadUtils.h
--- a/gfx/layers/apz/util/APZThreadUtils.cpp
+++ b/gfx/layers/apz/util/APZThreadUtils.cpp
@@ -76,12 +76,29 @@ APZThreadUtils::RunOnControllerThread(Ta
     aTask->Run();
     delete aTask;
   } else {
     sControllerThread->PostTask(FROM_HERE, aTask);
   }
 #endif
 }
 
+/*static*/ void
+APZThreadUtils::RunDelayedTaskOnCurrentThread(Task* aTask,
+                                              const TimeDuration& aDelay)
+{
+  if (MessageLoop* messageLoop = MessageLoop::current()) {
+    messageLoop->PostDelayedTask(FROM_HERE, aTask, aDelay.ToMilliseconds());
+  } else {
+#ifdef MOZ_ANDROID_APZ
+    // Fennec does not have a MessageLoop::current() on the controller thread.
+    AndroidBridge::Bridge()->PostTaskToUiThread(aTask, aDelay.ToMilliseconds());
+#else
+    // Other platforms should.
+    MOZ_RELEASE_ASSERT(false, "This non-Fennec platform should have a MessageLoop::current()");
+#endif
+  }
+}
+
 NS_IMPL_ISUPPORTS(GenericTimerCallbackBase, nsITimerCallback)
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/apz/util/APZThreadUtils.h
+++ b/gfx/layers/apz/util/APZThreadUtils.h
@@ -2,16 +2,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_layers_APZThreadUtils_h
 #define mozilla_layers_APZThreadUtils_h
 
 #include "base/message_loop.h"
+#include "mozilla/TimeStamp.h"  // for TimeDuration
 #include "nsITimer.h"
 
 class Task;
 
 namespace mozilla {
 namespace layers {
 
 class APZThreadUtils
@@ -45,16 +46,22 @@ public:
   static void AssertOnCompositorThread();
 
   /**
    * Run the given task on the APZ "controller thread" for this platform. If
    * this function is called from the controller thread itself then the task is
    * run immediately without getting queued.
    */
   static void RunOnControllerThread(Task* aTask);
+
+  /**
+   * Runs the given task on the current thread after a delay of |aDelay|.
+   */
+  static void RunDelayedTaskOnCurrentThread(Task* aTask,
+                                            const TimeDuration& aDelay);
 };
 
 // A base class for GenericTimerCallback<Function>.
 // This is necessary because NS_IMPL_ISUPPORTS doesn't work for a class
 // template.
 class GenericTimerCallbackBase : public nsITimerCallback
 {
 public: