Bug 792652 - Move mChannel to IProtocol (r=dvander)
☠☠ backed out by d2098e1d1f2d ☠ ☠
authorBill McCloskey <billm@mozilla.com>
Mon, 31 Oct 2016 15:18:35 -0700
changeset 321752 63a3c8e4016edb83f9079390cac98fcb3277e731
parent 321751 e3e496eab99124260d5b8dd66f4ca2efcb1a5708
child 321753 8edf4b247250cf585bb0e0ec9d533cbf7ad85d4c
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewersdvander
bugs792652
milestone52.0a1
Bug 792652 - Move mChannel to IProtocol (r=dvander) This moves the mChannel field to IProtocol. The toplevel protocol still keeps its own mChannel field that's a MessageChannel (no pointer).
ipc/glue/ProtocolUtils.h
ipc/ipdl/ipdl/lower.py
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -147,52 +147,55 @@ public:
         NormalShutdown,
         AbnormalShutdown
     };
 
     typedef base::ProcessId ProcessId;
     typedef IPC::Message Message;
     typedef IPC::MessageInfo MessageInfo;
 
-    IProtocol() : mManager(nullptr) {}
+    IProtocol() : mManager(nullptr), mChannel(nullptr) {}
 
     virtual int32_t Register(IProtocol*);
     virtual int32_t RegisterID(IProtocol*, int32_t);
     virtual IProtocol* Lookup(int32_t);
     virtual void Unregister(int32_t);
     virtual void RemoveManagee(int32_t, IProtocol*) = 0;
 
     virtual Shmem::SharedMemory* CreateSharedMemory(
         size_t, SharedMemory::SharedMemoryType, bool, int32_t*);
     virtual Shmem::SharedMemory* LookupSharedMemory(int32_t);
     virtual bool IsTrackingSharedMemory(Shmem::SharedMemory*);
     virtual bool DestroySharedMemory(Shmem&);
 
     // XXX odd ducks, acknowledged
     virtual ProcessId OtherPid() const;
-    virtual MessageChannel* GetIPCChannel() = 0;
 
     virtual void FatalError(const char* const aProtocolName, const char* const aErrorMsg) const = 0;
 
     Maybe<IProtocol*> ReadActor(const IPC::Message* aMessage, PickleIterator* aIter, bool aNullable,
                                 const char* aActorDescription, int32_t aProtocolTypeId);
 
     virtual Result OnMessageReceived(const Message& aMessage) = 0;
     virtual Result OnMessageReceived(const Message& aMessage, Message *& aReply) = 0;
     virtual Result OnCallReceived(const Message& aMessage, Message *& aReply) = 0;
 
     virtual int32_t GetProtocolTypeId() = 0;
 
     IProtocol* Manager() const { return mManager; }
+    virtual const MessageChannel* GetIPCChannel() const { return mChannel; }
+    virtual MessageChannel* GetIPCChannel() { return mChannel; }
 
 protected:
     void SetManager(IProtocol* aManager) { mManager = aManager; }
+    void SetIPCChannel(MessageChannel* aChannel) { mChannel = aChannel; }
 
 private:
     IProtocol* mManager;
+    MessageChannel* mChannel;
 };
 
 typedef IPCMessageStart ProtocolId;
 
 template<class PFooSide>
 class Endpoint;
 
 /**
@@ -214,18 +217,16 @@ public:
     {
         mTrans = Move(aTrans);
     }
 
     Transport* GetTransport() const { return mTrans.get(); }
 
     ProtocolId GetProtocolId() const { return mProtocolId; }
 
-    virtual MessageChannel* GetIPCChannel() = 0;
-
     virtual void OnChannelClose() = 0;
     virtual void OnChannelError() = 0;
     virtual void OnProcessingError(Result aError, const char* aMsgName) = 0;
     virtual void OnChannelConnected(int32_t peer_pid) {}
     virtual bool OnReplyTimeout() {
         return false;
     }
 
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -121,19 +121,16 @@ def _actorTypeTagType():
 def _actorId(actor=None):
     if actor is not None:
         return ExprSelect(actor, '->', 'mId')
     return ExprVar('mId')
 
 def _actorHId(actorhandle):
     return ExprSelect(actorhandle, '.', 'mId')
 
-def _actorChannel(actor):
-    return ExprSelect(actor, '->', 'mChannel')
-
 def _actorManager(actor):
     return ExprCall(ExprSelect(actor, '->', 'Manager'), args=[])
 
 def _actorState(actor):
     return ExprSelect(actor, '->', 'mState')
 
 def _backstagePass():
     return ExprCall(ExprVar('mozilla::ipc::PrivateIPDLInterface'))
@@ -1207,21 +1204,16 @@ class Protocol(ipdl.ast.Protocol):
         assert self.decl.type.isToplevel()
         return ExprVar('mActorMap')
 
     def channelVar(self, actorThis=None):
         if actorThis is not None:
             return ExprSelect(actorThis, '->', 'mChannel')
         return ExprVar('mChannel')
 
-    def channelForSubactor(self):
-        if self.decl.type.isToplevel():
-            return ExprAddrOf(self.channelVar())
-        return self.channelVar()
-
     def routingId(self, actorThis=None):
         if self.decl.type.isToplevel():
             return ExprVar('MSG_ROUTING_CONTROL')
         if actorThis is not None:
             return ExprSelect(actorThis, '->', self.idVar().name)
         return self.idVar()
 
     def idVar(self):
@@ -3569,18 +3561,18 @@ class _GenerateProtocolActorCode(ipdl.as
             self.cls.addstmts([ deallocshmem, Whitespace.NL ])
 
             deallocself = MethodDefn(MethodDecl(deallocselfvar.name, virtual=1))
             self.cls.addstmts([ deallocself, Whitespace.NL ])
 
         self.implementPickling()
 
         ## private members
-        self.cls.addstmt(StmtDecl(Decl(p.channelType(), 'mChannel')))
         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))
             ])
         elif ptype.isManaged():
@@ -3662,31 +3654,39 @@ class _GenerateProtocolActorCode(ipdl.as
                 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,
+                ret=Type('MessageChannel', ptr=1, const=1),
+                virtual=1, const=1))
+            getchannelconst.addstmt(StmtReturn(ExprAddrOf(p.channelVar())))
 
             methods += [ register,
                          registerid,
                          lookup,
                          unregister,
                          createshmem,
                          lookupshmem,
                          istracking,
                          destroyshmem,
-                         otherpid ]
-
-        getchannel = MethodDefn(MethodDecl(
-            p.getChannelMethod().name,
-            ret=Type('MessageChannel', ptr=1),
-            virtual=1))
+                         otherpid,
+                         getchannel,
+                         getchannelconst ]
 
         if p.decl.type.isToplevel():
             tmpvar = ExprVar('tmp')
 
             register.addstmts([
                 StmtDecl(Decl(_actorIdType(), tmpvar.name),
                          p.nextActorIdExpr(self.side)),
                 StmtExpr(ExprCall(
@@ -3739,17 +3739,17 @@ class _GenerateProtocolActorCode(ipdl.as
                                             p.callOtherPid(),
                                             p.routingId()))
             ])
             failif = StmtIf(ExprNot(descriptorvar))
             failif.addifstmt(StmtReturn(ExprLiteral.NULL))
             createshmem.addstmt(failif)
 
             failif = StmtIf(ExprNot(ExprCall(
-                ExprSelect(p.channelVar(), p.channelSel(), 'Send'),
+                ExprSelect(p.callGetChannel(), '->', 'Send'),
                 args=[ descriptorvar ])))
             createshmem.addstmt(failif)
 
             rawsegmentvar = ExprVar('rawSegment')
             createshmem.addstmts([
                 StmtExpr(ExprAssn(ExprDeref(idvar), _shmemId(shmemvar))),
                 StmtDecl(Decl(_rawShmemType(ptr=1), rawsegmentvar.name),
                          init=_refptrGet(rawvar)),
@@ -3834,19 +3834,16 @@ class _GenerateProtocolActorCode(ipdl.as
                     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()))
-            getchannel.addstmt(StmtReturn(ExprAddrOf(p.channelVar())))
-        else:
-            getchannel.addstmt(StmtReturn(p.channelVar()))
 
         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 = []
@@ -3896,17 +3893,17 @@ class _GenerateProtocolActorCode(ipdl.as
                 ])
                 switchontype.addcase(CaseLabel(_protocolId(manageeipdltype).name),
                                      case)
             default = StmtBlock()
             default.addstmts([ _fatalError('unreached'), StmtReturn() ])
             switchontype.addcase(DefaultLabel(), default)
             removemanagee.addstmt(switchontype)
 
-        return methods + [removemanagee, getchannel, Whitespace.NL]
+        return methods + [removemanagee, Whitespace.NL]
 
     def makeShmemIface(self):
         p = self.protocol
         idvar = ExprVar('id')
         sizevar = ExprVar('aSize')
         typevar = ExprVar('aType')
         memvar = ExprVar('aMem')
         outmemvar = ExprVar('aOutMem')
@@ -4769,18 +4766,18 @@ class _GenerateProtocolActorCode(ipdl.as
         else:
             idexpr = ExprCall(self.protocol.registerIDMethod(),
                               args=[ actorvar, idexpr ])
 
         return [
             self.failIfNullActor(actorvar, errfn, msg="Error constructing actor %s" % actortype.name() + self.side.capitalize()),
             StmtExpr(ExprAssn(_actorId(actorvar), idexpr)),
             StmtExpr(ExprCall(ExprSelect(actorvar, '->', 'SetManager'), args=[ExprVar.THIS])),
-            StmtExpr(ExprAssn(_actorChannel(actorvar),
-                              self.protocol.channelForSubactor())),
+            StmtExpr(ExprCall(ExprSelect(actorvar, '->', 'SetIPCChannel'),
+                              args=[self.protocol.callGetChannel()])),
             StmtExpr(_callInsertManagedActor(
                 self.protocol.managedVar(md.decl.type.constructedType(),
                                          self.side),
                 actorvar)),
             StmtExpr(ExprAssn(_actorState(actorvar),
                               _startState(actorproto, fq=1)))
         ]
 
@@ -5194,35 +5191,35 @@ class _GenerateProtocolActorCode(ipdl.as
             sendok,
             ([ Whitespace.NL,
                self.logMessage(md, msgexpr, 'Sending ', actor),
                self.profilerLabel(md) ]
             + self.transition(md, 'out', actor)
             + [ Whitespace.NL,
                 StmtDecl(Decl(Type.BOOL, sendok.name),
                          init=ExprCall(
-                             ExprSelect(self.protocol.channelVar(actor),
-                                        self.protocol.channelSel(), 'Send'),
+                             ExprSelect(self.protocol.callGetChannel(actor),
+                                        '->', 'Send'),
                              args=[ msgexpr ]))
             ])
         )
 
     def sendBlocking(self, md, msgexpr, replyexpr, actor=None):
         sendok = ExprVar('sendok__')
         return (
             sendok,
             ([ Whitespace.NL,
                self.logMessage(md, msgexpr, 'Sending ', actor),
                self.profilerLabel(md) ]
             + self.transition(md, 'out', actor)
             + [ Whitespace.NL,
                 StmtDecl(
                     Decl(Type.BOOL, sendok.name),
-                    init=ExprCall(ExprSelect(self.protocol.channelVar(actor),
-                                             self.protocol.channelSel(),
+                    init=ExprCall(ExprSelect(self.protocol.callGetChannel(actor),
+                                             '->',
                                              _sendPrefix(md.decl.type)),
                                   args=[ msgexpr, ExprAddrOf(replyexpr) ]))
             ])
         )
 
     def callAllocActor(self, md, retsems, side):
         return ExprCall(
             _allocMethod(md.decl.type.constructedType(), side),