Bug 1319850 - part 3, Convert AndroidBridge::PostTaskToUiThread to use nsIRunnable instead of mozilla::Runnable r=jchen
authorRandall Barker <rbarker@mozilla.com>
Wed, 30 Nov 2016 15:46:27 -0800
changeset 453564 7b28041341d67fbb0d4123daa326389953e9c04b
parent 453563 7f1ec68f6e5b1f778bbf63ac9a0ed19c958d4471
child 453565 e99463c6d0716ce472a350dca61349a274205570
push id39711
push userdmitchell@mozilla.com
push dateFri, 23 Dec 2016 21:59:47 +0000
reviewersjchen
bugs1319850
milestone53.0a1
Bug 1319850 - part 3, Convert AndroidBridge::PostTaskToUiThread to use nsIRunnable instead of mozilla::Runnable r=jchen
widget/android/AndroidBridge.cpp
widget/android/AndroidBridge.h
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -994,22 +994,22 @@ AndroidBridge::IsContentDocumentDisplaye
 }
 
 class AndroidBridge::DelayedTask
 {
     using TimeStamp = mozilla::TimeStamp;
     using TimeDuration = mozilla::TimeDuration;
 
 public:
-    DelayedTask(already_AddRefed<Runnable> aTask)
+    DelayedTask(already_AddRefed<nsIRunnable> aTask)
         : mTask(aTask)
         , mRunTime() // Null timestamp representing no delay.
     {}
 
-    DelayedTask(already_AddRefed<Runnable> aTask, int aDelayMs)
+    DelayedTask(already_AddRefed<nsIRunnable> aTask, int aDelayMs)
         : mTask(aTask)
         , mRunTime(TimeStamp::Now() + TimeDuration::FromMilliseconds(aDelayMs))
     {}
 
     bool IsEarlierThan(const DelayedTask& aOther) const
     {
         if (mRunTime) {
             return aOther.mRunTime ? mRunTime < aOther.mRunTime : false;
@@ -1022,29 +1022,29 @@ public:
     int64_t MillisecondsToRunTime() const
     {
         if (mRunTime) {
             return int64_t((mRunTime - TimeStamp::Now()).ToMilliseconds());
         }
         return 0;
     }
 
-    already_AddRefed<Runnable> TakeTask()
+    already_AddRefed<nsIRunnable> TakeTask()
     {
         return mTask.forget();
     }
 
 private:
-    RefPtr<Runnable> mTask;
+    nsCOMPtr<nsIRunnable> mTask;
     const TimeStamp mRunTime;
 };
 
 
 void
-AndroidBridge::PostTaskToUiThread(already_AddRefed<Runnable> aTask, int aDelayMs)
+AndroidBridge::PostTaskToUiThread(already_AddRefed<nsIRunnable> aTask, int aDelayMs)
 {
     // add the new task into the mUiTaskQueue, sorted with
     // the earliest task first in the queue
     size_t i;
     DelayedTask newTask(aDelayMs ? DelayedTask(mozilla::Move(aTask), aDelayMs)
                                  : DelayedTask(mozilla::Move(aTask)));
 
     {
@@ -1081,17 +1081,17 @@ AndroidBridge::RunDelayedUiThreadTasks()
         if (timeLeft > 0) {
             // this task (and therefore all remaining tasks)
             // have not yet reached their runtime. return the
             // time left until we should be called again
             return timeLeft;
         }
 
         // Retrieve task before unlocking/running.
-        RefPtr<Runnable> nextTask(mUiTaskQueue[0].TakeTask());
+        nsCOMPtr<nsIRunnable> nextTask(mUiTaskQueue[0].TakeTask());
         mUiTaskQueue.RemoveElementAt(0);
 
         // Unlock to allow posting new tasks reentrantly.
         MutexAutoUnlock unlock(mUiTaskQueueLock);
         nextTask->Run();
     }
     return -1;
 }
--- a/widget/android/AndroidBridge.h
+++ b/widget/android/AndroidBridge.h
@@ -37,26 +37,22 @@
 #include "Units.h"
 
 // Some debug #defines
 // #define DEBUG_ANDROID_EVENTS
 // #define DEBUG_ANDROID_WIDGET
 
 class nsPIDOMWindowOuter;
 
-namespace base {
-class Thread;
-} // end namespace base
-
 typedef void* EGLSurface;
+class nsIRunnable;
 
 namespace mozilla {
 
 class AutoLocalJNIFrame;
-class Runnable;
 
 namespace hal {
 class BatteryInformation;
 class NetworkInformation;
 } // namespace hal
 
 // The order and number of the members in this structure must correspond
 // to the attrsAppearance array in GeckoAppShell.getSystemColors()
@@ -234,17 +230,17 @@ protected:
     jmethodID mMessageQueueNext;
 
 private:
     class DelayedTask;
     nsTArray<DelayedTask> mUiTaskQueue;
     mozilla::Mutex mUiTaskQueueLock;
 
 public:
-    void PostTaskToUiThread(already_AddRefed<Runnable> aTask, int aDelayMs);
+    void PostTaskToUiThread(already_AddRefed<nsIRunnable> aTask, int aDelayMs);
     int64_t RunDelayedUiThreadTasks();
 };
 
 class AutoJNIClass {
 private:
     JNIEnv* const mEnv;
     const jclass mClass;