Bug 792652 - Move FatalError to IProtocol (r=dvander)
☠☠ backed out by d2098e1d1f2d ☠ ☠
authorBill McCloskey <billm@mozilla.com>
Tue, 01 Nov 2016 09:10:42 -0700
changeset 351772 59e6d0a4f35b0559157423e844df5e5320841819
parent 351771 bdf86b8b9c43a5fc7e9b9d481f15d82925f0ae53
child 351773 cf9c4164eb435ebf23cb3056eb1830861e8e8087
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 FatalError to IProtocol (r=dvander) This patch moves FatalError to IProtocol. I had to make a few changes. - I added a ProtocolName() method to find the name of the protocol. - I gave the two-argument version of FatalError its own name. Otherwise C++ doesn't like there to be two virtual methods with the same name in cases where one is overridden and the other isn't (as happens in IToplevelProtocol).
dom/media/ipc/VideoDecoderManagerChild.cpp
dom/media/ipc/VideoDecoderManagerChild.h
gfx/ipc/VsyncBridgeChild.cpp
gfx/ipc/VsyncBridgeChild.h
gfx/layers/ipc/CompositorBridgeChild.cpp
gfx/layers/ipc/CompositorBridgeChild.h
gfx/layers/ipc/ImageBridgeChild.cpp
gfx/layers/ipc/ImageBridgeChild.h
gfx/vr/ipc/VRManagerChild.cpp
gfx/vr/ipc/VRManagerChild.h
ipc/glue/ProtocolUtils.cpp
ipc/glue/ProtocolUtils.h
ipc/ipdl/ipdl/lower.py
--- a/dom/media/ipc/VideoDecoderManagerChild.cpp
+++ b/dom/media/ipc/VideoDecoderManagerChild.cpp
@@ -241,15 +241,15 @@ VideoDecoderManagerChild::DeallocateSurf
   sVideoDecoderChildThread->Dispatch(NS_NewRunnableFunction([ref, sd]() {
     if (ref->mCanSend) {
       ref->SendDeallocateSurfaceDescriptorGPUVideo(sd);
     }
   }), NS_DISPATCH_NORMAL);
 }
 
 void
-VideoDecoderManagerChild::FatalError(const char* const aName, const char* const aMsg) const
+VideoDecoderManagerChild::HandleFatalError(const char* aName, const char* aMsg) const
 {
   dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aName, aMsg, OtherPid());
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/media/ipc/VideoDecoderManagerChild.h
+++ b/dom/media/ipc/VideoDecoderManagerChild.h
@@ -53,17 +53,17 @@ public:
   // Main thread only
   static void Initialize();
   static void Shutdown();
 
 protected:
   void ActorDestroy(ActorDestroyReason aWhy) override;
   void DeallocPVideoDecoderManagerChild() override;
 
-  void FatalError(const char* const aName, const char* const aMsg) const override;
+  void HandleFatalError(const char* aName, const char* aMsg) const override;
 
   PVideoDecoderChild* AllocPVideoDecoderChild() override;
   bool DeallocPVideoDecoderChild(PVideoDecoderChild* actor) override;
 
 private:
   VideoDecoderManagerChild()
     : mCanSend(false)
   {}
--- a/gfx/ipc/VsyncBridgeChild.cpp
+++ b/gfx/ipc/VsyncBridgeChild.cpp
@@ -141,15 +141,15 @@ VsyncBridgeChild::DeallocPVsyncBridgeChi
 
 void
 VsyncBridgeChild::ProcessingError(Result aCode, const char* aReason)
 {
   MOZ_RELEASE_ASSERT(aCode == MsgDropped, "Processing error in VsyncBridgeChild");
 }
 
 void
-VsyncBridgeChild::FatalError(const char* const aName, const char* const aMsg) const
+VsyncBridgeChild::HandleFatalError(const char* aName, const char* aMsg) const
 {
   dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aName, aMsg, OtherPid());
 }
 
 } // namespace gfx
 } // namespace mozilla
--- a/gfx/ipc/VsyncBridgeChild.h
+++ b/gfx/ipc/VsyncBridgeChild.h
@@ -28,17 +28,17 @@ public:
   void Close();
 
   void ActorDestroy(ActorDestroyReason aWhy) override;
   void DeallocPVsyncBridgeChild() override;
   void ProcessingError(Result aCode, const char* aReason) override;
 
   void NotifyVsync(TimeStamp aTimeStamp, const uint64_t& aLayersId);
 
-  virtual void FatalError(const char* const aName, const char* const aMsg) const override;
+  virtual void HandleFatalError(const char* aName, const char* aMsg) const override;
 
 private:
   VsyncBridgeChild(RefPtr<VsyncIOThreadHolder>, const uint64_t& aProcessToken);
   ~VsyncBridgeChild();
 
   void Open(Endpoint<PVsyncBridgeChild>&& aEndpoint);
 
   void NotifyVsyncImpl(TimeStamp aTimeStamp, const uint64_t& aLayersId);
--- a/gfx/layers/ipc/CompositorBridgeChild.cpp
+++ b/gfx/layers/ipc/CompositorBridgeChild.cpp
@@ -1119,16 +1119,16 @@ CompositorBridgeChild::ProcessingError(R
 
 void
 CompositorBridgeChild::WillEndTransaction()
 {
   ResetShmemCounter();
 }
 
 void
-CompositorBridgeChild::FatalError(const char* const aName, const char* const aMsg) const
+CompositorBridgeChild::HandleFatalError(const char* aName, const char* aMsg) const
 {
   dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aName, aMsg, OtherPid());
 }
 
 } // namespace layers
 } // namespace mozilla
 
--- a/gfx/layers/ipc/CompositorBridgeChild.h
+++ b/gfx/layers/ipc/CompositorBridgeChild.h
@@ -129,17 +129,17 @@ public:
 
   virtual bool
   RecvParentAsyncMessages(InfallibleTArray<AsyncParentMessageData>&& aMessages) override;
   virtual PTextureChild* CreateTexture(const SurfaceDescriptor& aSharedData,
                                        LayersBackend aLayersBackend,
                                        TextureFlags aFlags,
                                        uint64_t aSerial) override;
 
-  virtual void FatalError(const char* const aName, const char* const aMsg) const override;
+  virtual void HandleFatalError(const char* aName, const char* aMsg) const override;
 
   /**
    * Request that the parent tell us when graphics are ready on GPU.
    * When we get that message, we bounce it to the TabParent via
    * the TabChild
    * @param tabChild The object to bounce the note to.  Non-NULL.
    */
   void RequestNotifyAfterRemotePaint(TabChild* aTabChild);
--- a/gfx/layers/ipc/ImageBridgeChild.cpp
+++ b/gfx/layers/ipc/ImageBridgeChild.cpp
@@ -1225,15 +1225,15 @@ ImageBridgeChild::Destroy(CompositableCh
 bool
 ImageBridgeChild::CanSend() const
 {
   MOZ_ASSERT(InImageBridgeChildThread());
   return mCanSend;
 }
 
 void
-ImageBridgeChild::FatalError(const char* const aName, const char* const aMsg) const
+ImageBridgeChild::HandleFatalError(const char* aName, const char* aMsg) const
 {
   dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aName, aMsg, OtherPid());
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/ipc/ImageBridgeChild.h
+++ b/gfx/layers/ipc/ImageBridgeChild.h
@@ -344,17 +344,17 @@ public:
 
   virtual void UpdateFwdTransactionId() override { ++mFwdTransactionId; }
   virtual uint64_t GetFwdTransactionId() override { return mFwdTransactionId; }
 
   bool InForwarderThread() override {
     return InImageBridgeChildThread();
   }
 
-  virtual void FatalError(const char* const aName, const char* const aMsg) const override;
+  virtual void HandleFatalError(const char* aName, const char* aMsg) const override;
 
 protected:
   ImageBridgeChild();
   bool DispatchAllocShmemInternal(size_t aSize,
                                   SharedMemory::SharedMemoryType aType,
                                   Shmem* aShmem,
                                   bool aUnsafe);
 
--- a/gfx/vr/ipc/VRManagerChild.cpp
+++ b/gfx/vr/ipc/VRManagerChild.cpp
@@ -563,17 +563,17 @@ VRManagerChild::RemoveListener(dom::VREv
 
   mListeners.RemoveElement(aObserver);
   if (mListeners.IsEmpty()) {
     Unused << SendSetHaveEventListener(false);
   }
 }
 
 void
-VRManagerChild::FatalError(const char* const aName, const char* const aMsg) const
+VRManagerChild::HandleFatalError(const char* aName, const char* aMsg) const
 {
   dom::ContentChild::FatalErrorIfNotUsingGPUProcess(aName, aMsg, OtherPid());
 }
 
 void
 VRManagerChild::SetGamepadManager(dom::GamepadManager* aGamepadManager)
 {
   MOZ_ASSERT(aGamepadManager);
--- a/gfx/vr/ipc/VRManagerChild.h
+++ b/gfx/vr/ipc/VRManagerChild.h
@@ -82,17 +82,17 @@ public:
   // the same singleton GamepadManager from the same process.
   void SetGamepadManager(dom::GamepadManager* aGamepadManager);
 
   void UpdateDisplayInfo(nsTArray<VRDisplayInfo>& aDisplayUpdates);
   void FireDOMVRDisplayConnectEvent();
   void FireDOMVRDisplayDisconnectEvent();
   void FireDOMVRDisplayPresentChangeEvent();
 
-  virtual void FatalError(const char* const aName, const char* const aMsg) const override;
+  virtual void HandleFatalError(const char* aName, const char* aMsg) const override;
 
 protected:
   explicit VRManagerChild();
   ~VRManagerChild();
   void Destroy();
   static void DeferredDestroy(RefPtr<VRManagerChild> aVRManagerChild);
 
   virtual PTextureChild* AllocPTextureChild(const SurfaceDescriptor& aSharedData,
--- a/ipc/glue/ProtocolUtils.cpp
+++ b/ipc/glue/ProtocolUtils.cpp
@@ -451,10 +451,27 @@ IProtocol::DestroySharedMemory(Shmem& aS
 }
 
 ProcessId
 IProtocol::OtherPid() const
 {
   return Manager()->OtherPid();
 }
 
+void
+IProtocol::FatalError(const char* const aErrorMsg) const
+{
+  HandleFatalError(ProtocolName(), aErrorMsg);
+}
+
+void
+IProtocol::HandleFatalError(const char* aProtocolName, const char* aErrorMsg) const
+{
+  if (IProtocol* manager = Manager()) {
+    manager->HandleFatalError(aProtocolName, aErrorMsg);
+    return;
+  }
+
+  mozilla::ipc::FatalError(aProtocolName, aErrorMsg, mSide == ParentSide);
+}
+
 } // namespace ipc
 } // namespace mozilla
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -164,17 +164,19 @@ public:
         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 void FatalError(const char* const aProtocolName, const char* const aErrorMsg) const = 0;
+    virtual const char* ProtocolName() const = 0;
+    void FatalError(const char* const aErrorMsg) const;
+    virtual void HandleFatalError(const char* aProtocolName, const char* aErrorMsg) const;
 
     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;
 
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -387,36 +387,16 @@ def _printErrorMessage(msg):
         ExprCall(ExprVar('NS_ERROR'), args=[ msg ]))
 
 def _protocolErrorBreakpoint(msg):
     if isinstance(msg, str):
         msg = ExprLiteral.String(msg)
     return StmtExpr(ExprCall(ExprVar('mozilla::ipc::ProtocolErrorBreakpoint'),
                              args=[ msg ]))
 
-def _ipcFatalError(name, msg):
-    if isinstance(name, str):
-        name = ExprLiteral.String(name)
-    if isinstance(msg, str):
-        msg = ExprLiteral.String(msg)
-    return StmtExpr(ExprCall(ExprVar('FatalError'),
-                             args=[ name, msg ]))
-
-def _ipcFatalErrorWithClassname(name, msg, p, isparent):
-    if isinstance(name, str):
-        name = ExprLiteral.String(name)
-    if isinstance(msg, str):
-        msg = ExprLiteral.String(msg)
-    if p.decl.type.isToplevel():
-        return StmtExpr(ExprCall(ExprVar('mozilla::ipc::FatalError'),
-                                 args=[ name, msg, isparent ]))
-    else:
-        return StmtExpr(ExprCall(ExprSelect(p.managerVar(), '->', 'FatalError'),
-                                 [ name, msg ]))
-
 def _printWarningMessage(msg):
     if isinstance(msg, str):
         msg = ExprLiteral.String(msg)
     return StmtExpr(
         ExprCall(ExprVar('NS_WARNING'), args=[ msg ]))
 
 def _fatalError(msg):
     return StmtExpr(
@@ -3372,43 +3352,25 @@ class _GenerateProtocolActorCode(ipdl.as
                 StmtReturn.FALSE,
                 CppDirective('endif')
             ])
             self.cls.addstmts([ getdump, Whitespace.NL ])
 
         ## private methods
         self.cls.addstmt(Label.PRIVATE)
 
-        ## FatalError()
-        msgparam = ExprVar('aMsg')
+        ## ProtocolName()
         actorname = _actorName(p.name, self.side)
-        fatalerror = MethodDefn(MethodDecl(
-            'FatalError',
-            params=[ Decl(Type('char', const=1, ptrconst=1), msgparam.name) ],
-            const=1, never_inline=1))
-        if self.side is 'parent':
-            isparent = ExprLiteral.TRUE
-        else:
-            isparent = ExprLiteral.FALSE
-        fatalerror.addstmts([
-            _ipcFatalError(actorname, msgparam)
+        protocolname = MethodDefn(MethodDecl(
+            'ProtocolName', params=[],
+            const=1, virtual=1, ret=Type('char', const=1, ptr=1)))
+        protocolname.addstmts([
+            StmtReturn(ExprLiteral.String(actorname))
         ])
-        self.cls.addstmts([ fatalerror, Whitespace.NL ])
-
-        protocolnameparam = ExprVar('aProtocolName')
-
-        fatalerrorwithclassname = MethodDefn(MethodDecl(
-            'FatalError',
-            params=[ Decl(Type('char', const=1, ptrconst=1), protocolnameparam.name),
-                     Decl(Type('char', const=1, ptrconst=1), msgparam.name) ],
-            const=1))
-        fatalerrorwithclassname.addstmts([
-            _ipcFatalErrorWithClassname(protocolnameparam, msgparam, self.protocol, isparent)
-        ])
-        self.cls.addstmts([ fatalerrorwithclassname, Whitespace.NL ])
+        self.cls.addstmts([ protocolname, Whitespace.NL ])
 
         ## DestroySubtree(bool normal)
         whyvar = ExprVar('why')
         subtreewhyvar = ExprVar('subtreewhy')
         kidsvar = ExprVar('kids')
         ivar = ExprVar('i')
         itervar = ExprVar('iter')
         ithkid = ExprIndex(kidsvar, ivar)