Bug 792652 - Store Manager() in IProtocol (r=dvander)
authorBill McCloskey <billm@mozilla.com>
Sat, 29 Oct 2016 10:38:31 -0700
changeset 351808 f6642de5fb7a88dc6c3dff07dc53b748436d13e7
parent 351807 6209f046a2832e3d3cb6bb254dbf6dcda6f4c760
child 351809 1b4e8fdc3b837f16e4867627fc3404d303fa38c1
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 - Store Manager() in IProtocol (r=dvander) This patch stores mManager in IProtocol rather than in each individual PFoo. It also adds a generic accessor for that field. Note that each individual protocol still defines a Manager() function that returns PFooParent or whatever. I tried to get rid of that but it was a lot of work.
dom/cache/CacheOpParent.cpp
dom/cache/CacheOpParent.h
ipc/glue/ProtocolUtils.h
ipc/ipdl/ipdl/lower.py
--- a/dom/cache/CacheOpParent.cpp
+++ b/dom/cache/CacheOpParent.cpp
@@ -49,30 +49,30 @@ CacheOpParent::~CacheOpParent()
 
 void
 CacheOpParent::Execute(ManagerId* aManagerId)
 {
   NS_ASSERT_OWNINGTHREAD(CacheOpParent);
   MOZ_ASSERT(!mManager);
   MOZ_ASSERT(!mVerifier);
 
-  RefPtr<Manager> manager;
-  nsresult rv = Manager::GetOrCreate(aManagerId, getter_AddRefs(manager));
+  RefPtr<cache::Manager> manager;
+  nsresult rv = cache::Manager::GetOrCreate(aManagerId, getter_AddRefs(manager));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     ErrorResult result(rv);
     Unused << Send__delete__(this, result, void_t());
     result.SuppressException();
     return;
   }
 
   Execute(manager);
 }
 
 void
-CacheOpParent::Execute(Manager* aManager)
+CacheOpParent::Execute(cache::Manager* aManager)
 {
   NS_ASSERT_OWNINGTHREAD(CacheOpParent);
   MOZ_ASSERT(!mManager);
   MOZ_ASSERT(!mVerifier);
 
   mManager = aManager;
 
   // Handle put op
--- a/dom/cache/CacheOpParent.h
+++ b/dom/cache/CacheOpParent.h
@@ -32,17 +32,17 @@ public:
   CacheOpParent(mozilla::ipc::PBackgroundParent* aIpcManager,
                 Namespace aNamespace, const CacheOpArgs& aOpArgs);
   ~CacheOpParent();
 
   void
   Execute(ManagerId* aManagerId);
 
   void
-  Execute(Manager* aManager);
+  Execute(cache::Manager* aManager);
 
   void
   WaitForVerification(PrincipalVerifier* aVerifier);
 
 private:
   // PCacheOpParent methods
   virtual void
   ActorDestroy(ActorDestroyReason aReason) override;
@@ -62,17 +62,17 @@ private:
   // utility methods
   already_AddRefed<nsIInputStream>
   DeserializeCacheStream(const CacheReadStreamOrVoid& aStreamOrVoid);
 
   mozilla::ipc::PBackgroundParent* mIpcManager;
   const CacheId mCacheId;
   const Namespace mNamespace;
   const CacheOpArgs mOpArgs;
-  RefPtr<Manager> mManager;
+  RefPtr<cache::Manager> mManager;
   RefPtr<PrincipalVerifier> mVerifier;
 
   NS_DECL_OWNINGTHREAD
 };
 
 } // namespace cache
 } // namespace dom
 } // namespace mozilla
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -1,9 +1,9 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * vim: sw=4 ts=4 et :
  */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_ipc_ProtocolUtils_h
 #define mozilla_ipc_ProtocolUtils_h 1
@@ -147,16 +147,18 @@ public:
         NormalShutdown,
         AbnormalShutdown
     };
 
     typedef base::ProcessId ProcessId;
     typedef IPC::Message Message;
     typedef IPC::MessageInfo MessageInfo;
 
+    IProtocol() : mManager(nullptr) {}
+
     virtual int32_t Register(IProtocol*) = 0;
     virtual int32_t RegisterID(IProtocol*, int32_t) = 0;
     virtual IProtocol* Lookup(int32_t) = 0;
     virtual void Unregister(int32_t) = 0;
     virtual void RemoveManagee(int32_t, IProtocol*) = 0;
 
     virtual Shmem::SharedMemory* CreateSharedMemory(
         size_t, SharedMemory::SharedMemoryType, bool, int32_t*) = 0;
@@ -173,16 +175,24 @@ public:
     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; }
+
+protected:
+    void SetManager(IProtocol* aManager) { mManager = aManager; }
+
+private:
+    IProtocol* mManager;
 };
 
 typedef IPCMessageStart ProtocolId;
 
 template<class PFooSide>
 class Endpoint;
 
 /**
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -125,17 +125,17 @@ def _actorId(actor=None):
 
 def _actorHId(actorhandle):
     return ExprSelect(actorhandle, '.', 'mId')
 
 def _actorChannel(actor):
     return ExprSelect(actor, '->', 'mChannel')
 
 def _actorManager(actor):
-    return ExprSelect(actor, '->', 'mManager')
+    return ExprCall(ExprSelect(actor, '->', 'Manager'), args=[])
 
 def _actorState(actor):
     return ExprSelect(actor, '->', 'mState')
 
 def _backstagePass():
     return ExprCall(ExprVar('mozilla::ipc::PrivateIPDLInterface'))
 
 def _iterType(ptr):
@@ -1100,22 +1100,16 @@ class Protocol(ipdl.ast.Protocol):
     def _ipdlmgrtype(self):
         assert 1 == len(self.decl.type.managers)
         for mgr in self.decl.type.managers:  return mgr
 
     def managerActorType(self, side, ptr=0):
         return Type(_actorName(self._ipdlmgrtype().name(), side),
                     ptr=ptr)
 
-    def managerMethod(self, actorThis=None):
-        _ = self._ipdlmgrtype()
-        if actorThis is not None:
-            return ExprSelect(actorThis, '->', 'Manager')
-        return ExprVar('Manager');
-
     def stateMethod(self):
         return ExprVar('state');
 
     def registerMethod(self):
         return ExprVar('Register')
 
     def registerIDMethod(self):
         return ExprVar('RegisterID')
@@ -1248,19 +1242,19 @@ class Protocol(ipdl.ast.Protocol):
     def nullState(self):
         return _nullState(self.decl.type)
 
     def deadState(self):
         return _deadState(self.decl.type)
 
     def managerVar(self, thisexpr=None):
         assert thisexpr is not None or not self.decl.type.isToplevel()
-        mvar = ExprVar('mManager')
+        mvar = ExprCall(ExprVar('Manager'), args=[])
         if thisexpr is not None:
-            mvar = ExprSelect(thisexpr, '->', mvar.name)
+            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)
@@ -1274,23 +1268,16 @@ class Protocol(ipdl.ast.Protocol):
         assert self.decl.type.isManagerOf(actortype)
         return ExprVar('mManaged'+ _actorName(actortype.name(), side))
 
     def managedVarType(self, actortype, side, const=0, ref=0):
         assert self.decl.type.isManagerOf(actortype)
         return _cxxManagedContainerType(Type(_actorName(actortype.name(), side)),
                                         const=const, ref=ref)
 
-    def managerArrayExpr(self, thisvar, side):
-        """The member var my manager keeps of actors of my type."""
-        assert self.decl.type.isManaged()
-        return ExprSelect(
-            ExprCall(self.managerMethod(thisvar)),
-            '->', 'mManaged'+ _actorName(self.decl.type.name(), side))
-
     # shmem stuff
     def shmemMapType(self):
         assert self.decl.type.isToplevel()
         return Type('IDMap', T=_rawShmemType())
 
     def shmemIteratorType(self):
         assert self.decl.type.isToplevel()
         # XXX breaks abstractions
@@ -3076,19 +3063,20 @@ class _GenerateProtocolActorCode(ipdl.as
                         args=[ timeoutvar ])))
                 self.cls.addstmts([ settimeout, Whitespace.NL ])
 
         if not ptype.isToplevel():
             if 1 == len(p.managers):
                 ## manager() const
                 managertype = p.managerActorType(self.side, ptr=1)
                 managermeth = MethodDefn(MethodDecl(
-                    p.managerMethod().name, ret=managertype, const=1))
+                    'Manager', ret=managertype, const=1))
+                managerexp = ExprCall(ExprVar('IProtocol::Manager'), args=[])
                 managermeth.addstmt(StmtReturn(
-                    ExprCast(p.managerVar(), managertype, static=1)))
+                    ExprCast(managerexp, managertype, static=1)))
 
                 self.cls.addstmts([ managermeth, Whitespace.NL ])
 
         def actorFromIter(itervar):
             return ExprCall(ExprSelect(ExprCall(ExprSelect(itervar, '.', 'Get')),
                                        '->', 'GetKey'))
         def forLoopOverHashtable(hashtable, itervar, const=False):
             return StmtFor(
@@ -3592,18 +3580,16 @@ class _GenerateProtocolActorCode(ipdl.as
                 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():
             self.cls.addstmts([
-                StmtDecl(Decl(p.managerInterfaceType(ptr=1),
-                              p.managerVar().name)),
                 StmtDecl(Decl(_actorIdType(), p.idVar().name))
             ])
         if p.decl.type.isToplevel():
             self.cls.addstmts([
                 StmtDecl(Decl(p.shmemMapType(), p.shmemMapVar().name)),
                 StmtDecl(Decl(_shmemIdType(), p.lastShmemIdVar().name))
             ])
 
@@ -4808,17 +4794,17 @@ class _GenerateProtocolActorCode(ipdl.as
                               args=[ actorvar ])
         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(ExprAssn(_actorManager(actorvar), ExprVar.THIS)),
+            StmtExpr(ExprCall(ExprSelect(actorvar, '->', 'SetManager'), args=[ExprVar.THIS])),
             StmtExpr(ExprAssn(_actorChannel(actorvar),
                               self.protocol.channelForSubactor())),
             StmtExpr(_callInsertManagedActor(
                 self.protocol.managedVar(md.decl.type.constructedType(),
                                          self.side),
                 actorvar)),
             StmtExpr(ExprAssn(_actorState(actorvar),
                               _startState(actorproto, fq=1)))