Bug 792652 - Move over toplevel process ID field (r=dvander)
☠☠ backed out by d2098e1d1f2d ☠ ☠
authorBill McCloskey <billm@mozilla.com>
Tue, 01 Nov 2016 17:02:48 -0700
changeset 351775 2ba36b8ac60c01b555ee7311706720458739f7c2
parent 351774 94fcd3bf3f34dc20e2b2fbe7ff44ecfa47371f28
child 351776 b658ebaad5d70a92a76e67ae33a96cfe8f48b773
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs792652
milestone52.0a1
Bug 792652 - Move over toplevel process ID field (r=dvander) Moves some state to IToplevelProtocol.
ipc/glue/ProtocolUtils.cpp
ipc/glue/ProtocolUtils.h
ipc/ipdl/ipdl/lower.py
--- a/ipc/glue/ProtocolUtils.cpp
+++ b/ipc/glue/ProtocolUtils.cpp
@@ -48,30 +48,16 @@ MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLAT
                                           ::LocalFree)
 MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedPSecurityDescriptor, \
                                           RemovePointer<PSECURITY_DESCRIPTOR>::Type, \
                                           ::LocalFree)
 #endif
 
 namespace ipc {
 
-IToplevelProtocol::IToplevelProtocol(ProtocolId aProtoId, Side aSide)
- : IProtocol(aSide),
-   mProtocolId(aProtoId)
-{
-}
-
-IToplevelProtocol::~IToplevelProtocol()
-{
-  if (mTrans) {
-    RefPtr<DeleteTask<Transport>> task = new DeleteTask<Transport>(mTrans.release());
-    XRE_GetIOMessageLoop()->PostTask(task.forget());
-  }
-}
-
 class ChannelOpened : public IPC::Message
 {
 public:
   ChannelOpened(TransportDescriptor aDescriptor,
                 ProcessId aOtherProcess,
                 ProtocolId aProtocol,
                 NestedLevel aNestedLevel = NOT_NESTED)
     : IPC::Message(MSG_ROUTING_CONTROL, // these only go to top-level actors
@@ -516,16 +502,43 @@ IProtocol::DeallocShmem(Shmem& aMem)
     }
     return false;
   }
 #endif // DEBUG
   aMem.forget(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
   return ok;
 }
 
+IToplevelProtocol::IToplevelProtocol(ProtocolId aProtoId, Side aSide)
+ : IProtocol(aSide),
+   mProtocolId(aProtoId),
+   mOtherPid(mozilla::ipc::kInvalidProcessId)
+{
+}
+
+IToplevelProtocol::~IToplevelProtocol()
+{
+  if (mTrans) {
+    RefPtr<DeleteTask<Transport>> task = new DeleteTask<Transport>(mTrans.release());
+    XRE_GetIOMessageLoop()->PostTask(task.forget());
+  }
+}
+
+base::ProcessId
+IToplevelProtocol::OtherPid() const
+{
+  return mOtherPid;
+}
+
+void
+IToplevelProtocol::SetOtherProcessId(base::ProcessId aOtherPid)
+{
+  mOtherPid = aOtherPid;
+}
+
 bool
 IToplevelProtocol::IsOnCxxStack() const
 {
   return GetIPCChannel()->IsOnCxxStack();
 }
 
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -226,16 +226,19 @@ public:
     {
         mTrans = Move(aTrans);
     }
 
     Transport* GetTransport() const { return mTrans.get(); }
 
     ProtocolId GetProtocolId() const { return mProtocolId; }
 
+    base::ProcessId OtherPid() const;
+    void SetOtherProcessId(base::ProcessId aOtherPid);
+
     virtual void OnChannelClose() = 0;
     virtual void OnChannelError() = 0;
     virtual void ProcessingError(Result aError, const char* aMsgName) {}
     virtual void OnChannelConnected(int32_t peer_pid) {}
 
     virtual bool ShouldContinueFromReplyTimeout() {
         return false;
     }
@@ -297,16 +300,17 @@ public:
     }
 
     virtual void ProcessRemoteNativeEventsInInterruptCall() {
     }
 
 private:
     ProtocolId mProtocolId;
     UniquePtr<Transport> mTrans;
+    base::ProcessId mOtherPid;
 };
 
 class IShmemAllocator
 {
 public:
   virtual bool AllocShmem(size_t aSize,
                           mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
                           mozilla::ipc::Shmem* aShmem) = 0;
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -1219,20 +1219,16 @@ class Protocol(ipdl.ast.Protocol):
 
     def managerVar(self, thisexpr=None):
         assert thisexpr is not None or not self.decl.type.isToplevel()
         mvar = ExprCall(ExprVar('Manager'), args=[])
         if thisexpr is not None:
             mvar = ExprCall(ExprSelect(thisexpr, '->', 'Manager'), args=[])
         return mvar
 
-    def otherPidVar(self):
-        assert self.decl.type.isToplevel()
-        return ExprVar('mOtherPid')
-
     def managedCxxType(self, actortype, side):
         assert self.decl.type.isManagerOf(actortype)
         return Type(_actorName(actortype.name(), side), ptr=1)
 
     def managedMethod(self, actortype, side):
         assert self.decl.type.isManagerOf(actortype)
         return ExprVar('Managed'+  _actorName(actortype.name(), side))
 
@@ -2931,18 +2927,16 @@ class _GenerateProtocolActorCode(ipdl.as
             ctor.memberinits = [
                 ExprMemberInit(ExprVar('mozilla::ipc::IToplevelProtocol'),
                                [_protocolId(ptype), side]),
                 ExprMemberInit(p.channelVar(), [
                     ExprCall(ExprVar('ALLOW_THIS_IN_INITIALIZER_LIST'),
                              [ ExprVar.THIS ]) ]),
                 ExprMemberInit(p.lastActorIdVar(),
                                [ p.actorIdInit(self.side) ]),
-                ExprMemberInit(p.otherPidVar(),
-                               [ ExprVar('mozilla::ipc::kInvalidProcessId') ]),
                 ExprMemberInit(p.lastShmemIdVar(),
                                [ p.shmemIdInit(self.side) ]),
                 ExprMemberInit(p.stateVar(),
                                [ p.startState() ])
             ]
         else:
             ctor.memberinits = [
                 ExprMemberInit(ExprVar('mozilla::ipc::IProtocol'), [side]),
@@ -3263,28 +3257,16 @@ class _GenerateProtocolActorCode(ipdl.as
                     CppDirective('else'),
                     _fatalError('This method is Windows-only'),
                     CppDirective('endif'),
                     ])
 
             self.cls.addstmts([ processnative, Whitespace.NL ])
 
         if ptype.isToplevel() and self.side is 'parent':
-            ## void SetOtherProcessId(ProcessId aOtherPid)
-            otherpidvar = ExprVar('aOtherPid')
-            setotherprocessid = MethodDefn(MethodDecl(
-                    'SetOtherProcessId',
-                    params=[ Decl(Type('base::ProcessId'), otherpidvar.name)]))
-            setotherprocessid.addstmts([
-                StmtExpr(ExprAssn(p.otherPidVar(), otherpidvar)),
-            ])
-            self.cls.addstmts([
-                    setotherprocessid,
-                    Whitespace.NL])
-
             ## bool GetMinidump(nsIFile** dump)
             self.cls.addstmt(Label.PROTECTED)
 
             dumpvar = ExprVar('aDump')
             seqvar = ExprVar('aSequence')
             getdump = MethodDefn(MethodDecl(
                 'TakeMinidump',
                 params=[ Decl(Type('nsIFile', ptrptr=1), dumpvar.name),
@@ -3450,19 +3432,17 @@ class _GenerateProtocolActorCode(ipdl.as
         self.implementPickling()
 
         ## private members
         if ptype.isToplevel():
             self.cls.addstmt(StmtDecl(Decl(p.channelType(), 'mChannel')))
             self.cls.addstmts([
                 StmtDecl(Decl(Type('IDMap', T=Type('ProtocolBase')),
                               p.actorMapVar().name)),
-                StmtDecl(Decl(_actorIdType(), p.lastActorIdVar().name)),
-                StmtDecl(Decl(Type('base::ProcessId'),
-                              p.otherPidVar().name))
+                StmtDecl(Decl(_actorIdType(), p.lastActorIdVar().name))
             ])
         elif ptype.isManaged():
             self.cls.addstmts([
                 StmtDecl(Decl(_actorIdType(), p.idVar().name))
             ])
         if p.decl.type.isToplevel():
             self.cls.addstmts([
                 StmtDecl(Decl(p.shmemMapType(), p.shmemMapVar().name)),
@@ -3533,21 +3513,16 @@ class _GenerateProtocolActorCode(ipdl.as
                 params=[ Decl(_shmemType(ref=1), shmemvar.name) ],
                 virtual=1))
             istracking = MethodDefn(MethodDecl(
                 p.isTrackingSharedMemory().name,
                 ret=Type.BOOL,
                 params=[ Decl(_rawShmemType(ptr=1), rawvar.name) ],
                 virtual=1))
 
-            otherpid = MethodDefn(MethodDecl(
-                p.otherPidMethod().name,
-                ret=Type('base::ProcessId'),
-                const=1,
-                virtual=1))
             getchannel = MethodDefn(MethodDecl(
                 p.getChannelMethod().name,
                 ret=Type('MessageChannel', ptr=1),
                 virtual=1))
             getchannel.addstmt(StmtReturn(ExprAddrOf(p.channelVar())))
 
             getchannelconst = MethodDefn(MethodDecl(
                 p.getChannelMethod().name,
@@ -3558,17 +3533,16 @@ class _GenerateProtocolActorCode(ipdl.as
             methods += [ register,
                          registerid,
                          lookup,
                          unregister,
                          createshmem,
                          lookupshmem,
                          istracking,
                          destroyshmem,
-                         otherpid,
                          getchannel,
                          getchannelconst ]
 
         if p.decl.type.isToplevel():
             tmpvar = ExprVar('tmp')
 
             register.addstmts([
                 StmtDecl(Decl(_actorIdType(), tmpvar.name),
@@ -3717,18 +3691,16 @@ class _GenerateProtocolActorCode(ipdl.as
                     _fatalError('this protocol tree does not use shmem'),
                     StmtReturn(_Result.NotKnown)
                 ])
                 self.asyncSwitch.addcase(
                     CaseLabel('SHMEM_CREATED_MESSAGE_TYPE'), abort)
                 self.asyncSwitch.addcase(
                     CaseLabel('SHMEM_DESTROYED_MESSAGE_TYPE'), abort)
 
-            otherpid.addstmt(StmtReturn(p.otherPidVar()))
-
         othervar = ExprVar('other')
         managertype = Type(_actorName(p.name, self.side), ptr=1)
 
         # Keep track of types created with an INOUT ctor. We need to call
         # Register() or RegisterID() for them depending on the side the managee
         # is created.
         inoutCtorTypes = []
         for msg in p.messageDecls: