Bug 1319850 - part 1, Add MessagePumpForAndroidUI r=nfroyd
authorRandall Barker <rbarker@mozilla.com>
Wed, 30 Nov 2016 14:56:53 -0800
changeset 327219 ab1843cc574e33893ac6284e81be8ebf1096926b
parent 327218 f79edc3888e5ce7647fd259cbceb6e806df2a715
child 327220 7f1ec68f6e5b1f778bbf63ac9a0ed19c958d4471
push id31122
push userphilringnalda@gmail.com
push dateSun, 25 Dec 2016 00:51:37 +0000
treeherdermozilla-central@1156db49e976 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnfroyd
bugs1319850
milestone53.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 1319850 - part 1, Add MessagePumpForAndroidUI r=nfroyd
ipc/glue/MessagePump.cpp
ipc/glue/MessagePump.h
--- a/ipc/glue/MessagePump.cpp
+++ b/ipc/glue/MessagePump.cpp
@@ -458,8 +458,34 @@ MessagePumpForNonMainUIThreads::OnProces
 NS_IMETHODIMP
 MessagePumpForNonMainUIThreads::AfterProcessNextEvent(nsIThreadInternal *thread,
                                                       bool eventWasProcessed)
 {
   return NS_OK;
 }
 
 #endif // XP_WIN
+
+#if defined(MOZ_WIDGET_ANDROID)
+void
+MessagePumpForAndroidUI::Run(Delegate* delegate)
+{
+  MOZ_CRASH("MessagePumpForAndroidUI should never be Run.");
+}
+
+void
+MessagePumpForAndroidUI::Quit()
+{
+  MOZ_CRASH("MessagePumpForAndroidUI should never be Quit.");
+}
+
+void
+MessagePumpForAndroidUI::ScheduleWork()
+{
+  MOZ_CRASH("MessagePumpForAndroidUI should never ScheduleWork");
+}
+
+void
+MessagePumpForAndroidUI::ScheduleDelayedWork(const TimeTicks& delayed_work_time)
+{
+  MOZ_CRASH("MessagePumpForAndroidUI should never ScheduleDelayedWork");
+}
+#endif // defined(MOZ_WIDGET_ANDROID)
--- a/ipc/glue/MessagePump.h
+++ b/ipc/glue/MessagePump.h
@@ -159,12 +159,49 @@ private:
   {
   }
 
   bool mInWait;
   mozilla::Mutex mWaitLock;
 };
 #endif // defined(XP_WIN)
 
+#if defined(MOZ_WIDGET_ANDROID)
+/*`
+ * The MessagePumpForAndroidUI exists to enable IPDL in the Android UI thread. The Android
+ * UI thread event loop is controlled by Android. This prevents running an existing
+ * MessagePump implementation in the Android UI thread. In order to enable IPDL on the
+ * Android UI thread it is necessary to have a non-looping MessagePump. This class enables
+ * forwarding of nsIRunnables from MessageLoop::PostTask_Helper to the registered
+ * nsIEventTarget with out the need to control the event loop. The only member function
+ * that should be invoked is GetXPCOMThread. All other member functions will invoke MOZ_CRASH
+*/
+class MessagePumpForAndroidUI : public base::MessagePump {
+
+public:
+  MessagePumpForAndroidUI(nsIEventTarget* aEventTarget)
+    : mEventTarget(aEventTarget)
+  { }
+
+  virtual void Run(Delegate* delegate);
+  virtual void Quit();
+  virtual void ScheduleWork();
+  virtual void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time);
+  virtual nsIEventTarget* GetXPCOMThread()
+  {
+    return mEventTarget;
+  }
+
+private:
+  ~MessagePumpForAndroidUI()
+  { }
+  MessagePumpForAndroidUI()
+  { }
+
+  nsIEventTarget* mEventTarget;
+};
+#endif // defined(MOZ_WIDGET_ANDROID)
+
+
 } /* namespace ipc */
 } /* namespace mozilla */
 
 #endif /* __IPC_GLUE_MESSAGEPUMP_H__ */