Bug 1283609 - Part 1: Add an IToplevelProtocol::Open overload that takes an nsIEventTarget. r=billm, a=lizzard
authorJan Varga <jan.varga@gmail.com>
Thu, 03 Aug 2017 11:21:44 +0200
changeset 423651 df048280b51310e530778e9d5535c85d0e41a889
parent 423650 f236b5a4397cdd0af004da8ad5640a46ba955801
child 423652 269bc08c27eda39cbf4e369d4ef6fa6d3aecf6b5
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm, lizzard
bugs1283609
milestone56.0
Bug 1283609 - Part 1: Add an IToplevelProtocol::Open overload that takes an nsIEventTarget. r=billm, a=lizzard
ipc/glue/MessageChannel.cpp
ipc/glue/MessageChannel.h
ipc/glue/ProtocolUtils.cpp
ipc/glue/ProtocolUtils.h
--- a/ipc/glue/MessageChannel.cpp
+++ b/ipc/glue/MessageChannel.cpp
@@ -763,17 +763,17 @@ MessageChannel::Open(Transport* aTranspo
 
     ProcessLink *link = new ProcessLink(this);
     link->Open(aTransport, aIOLoop, aSide); // :TODO: n.b.: sets mChild
     mLink = link;
     return true;
 }
 
 bool
-MessageChannel::Open(MessageChannel *aTargetChan, MessageLoop *aTargetLoop, Side aSide)
+MessageChannel::Open(MessageChannel *aTargetChan, nsIEventTarget *aEventTarget, Side aSide)
 {
     // Opens a connection to another thread in the same process.
 
     //  This handshake proceeds as follows:
     //  - Let A be the thread initiating the process (either child or parent)
     //    and B be the other thread.
     //  - A spawns thread for B, obtaining B's message loop
     //  - A creates ProtocolChild and ProtocolParent instances.
@@ -796,22 +796,22 @@ MessageChannel::Open(MessageChannel *aTa
       case ParentSide: oppSide = ChildSide; break;
       case UnknownSide: break;
     }
 
     mMonitor = new RefCountedMonitor();
 
     MonitorAutoLock lock(*mMonitor);
     mChannelState = ChannelOpening;
-    aTargetLoop->PostTask(NewNonOwningRunnableMethod<MessageChannel*, Side>(
+    MOZ_ALWAYS_SUCCEEDS(aEventTarget->Dispatch(NewNonOwningRunnableMethod<MessageChannel*, Side>(
       "ipc::MessageChannel::OnOpenAsSlave",
       aTargetChan,
       &MessageChannel::OnOpenAsSlave,
       this,
-      oppSide));
+      oppSide)));
 
     while (ChannelOpening == mChannelState)
         mMonitor->Wait();
     MOZ_RELEASE_ASSERT(ChannelConnected == mChannelState, "not connected when awoken");
     return (ChannelConnected == mChannelState);
 }
 
 void
--- a/ipc/glue/MessageChannel.h
+++ b/ipc/glue/MessageChannel.h
@@ -30,16 +30,18 @@
 
 #include <deque>
 #include <functional>
 #include <map>
 #include <math.h>
 #include <stack>
 #include <vector>
 
+class nsIEventTarget;
+
 namespace mozilla {
 namespace ipc {
 
 class MessageChannel;
 class IToplevelProtocol;
 
 class RefCountedMonitor : public Monitor
 {
@@ -141,17 +143,17 @@ class MessageChannel : HasResultCodes, M
     // "Open" a connection to another thread in the same process.
     //
     // Returns true if the transport layer was successfully connected,
     // i.e., mChannelState == ChannelConnected.
     //
     // For more details on the process of opening a channel between
     // threads, see the extended comment on this function
     // in MessageChannel.cpp.
-    bool Open(MessageChannel *aTargetChan, MessageLoop *aTargetLoop, Side aSide);
+    bool Open(MessageChannel *aTargetChan, nsIEventTarget *aEventTarget, Side aSide);
 
     // Close the underlying transport channel.
     void Close();
 
     // Force the channel to behave as if a channel error occurred. Valid
     // for process links only, not thread links.
     void CloseWithError();
 
--- a/ipc/glue/ProtocolUtils.cpp
+++ b/ipc/glue/ProtocolUtils.cpp
@@ -639,17 +639,26 @@ IToplevelProtocol::Open(mozilla::ipc::Tr
 }
 
 bool
 IToplevelProtocol::Open(MessageChannel* aChannel,
                         MessageLoop* aMessageLoop,
                         mozilla::ipc::Side aSide)
 {
   SetOtherProcessId(base::GetCurrentProcId());
-  return GetIPCChannel()->Open(aChannel, aMessageLoop, aSide);
+  return GetIPCChannel()->Open(aChannel, aMessageLoop->SerialEventTarget(), aSide);
+}
+
+bool
+IToplevelProtocol::Open(MessageChannel* aChannel,
+                        nsIEventTarget* aEventTarget,
+                        mozilla::ipc::Side aSide)
+{
+  SetOtherProcessId(base::GetCurrentProcId());
+  return GetIPCChannel()->Open(aChannel, aEventTarget, aSide);
 }
 
 void
 IToplevelProtocol::Close()
 {
   GetIPCChannel()->Close();
 }
 
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -289,16 +289,20 @@ public:
               base::ProcessId aOtherPid,
               MessageLoop* aThread = nullptr,
               mozilla::ipc::Side aSide = mozilla::ipc::UnknownSide);
 
     bool Open(MessageChannel* aChannel,
               MessageLoop* aMessageLoop,
               mozilla::ipc::Side aSide = mozilla::ipc::UnknownSide);
 
+    bool Open(MessageChannel* aChannel,
+              nsIEventTarget* aEventTarget,
+              mozilla::ipc::Side aSide = mozilla::ipc::UnknownSide);
+
     void Close();
 
     void SetReplyTimeoutMs(int32_t aTimeoutMs);
 
     virtual int32_t Register(IProtocol*);
     virtual int32_t RegisterID(IProtocol*, int32_t);
     virtual IProtocol* Lookup(int32_t);
     virtual void Unregister(int32_t);