Bug 1570369 - Part 4: Use IPDL refcounted for PChromiumCDM, r=jya
authorNika Layzell <nika@thelayzells.com>
Thu, 08 Aug 2019 16:46:31 +0000
changeset 487112 7faaefc8189cc87bec77ac02bbfc26181f89eec4
parent 487111 eb83232702916ef8fba9b123ca5f05dd1c39c4e6
child 487113 0b5d6a52c67fa8c0c35bb9a94d6c95d0b77ce13a
push id36411
push userrmaries@mozilla.com
push dateFri, 09 Aug 2019 03:49:20 +0000
treeherdermozilla-central@047e16b38566 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1570369
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1570369 - Part 4: Use IPDL refcounted for PChromiumCDM, r=jya Differential Revision: https://phabricator.services.mozilla.com/D40255
dom/media/gmp/ChromiumCDMChild.h
dom/media/gmp/ChromiumCDMParent.h
dom/media/gmp/GMPContentChild.cpp
dom/media/gmp/GMPContentChild.h
dom/media/gmp/GMPContentParent.cpp
dom/media/gmp/GMPContentParent.h
dom/media/gmp/PChromiumCDM.ipdl
--- a/dom/media/gmp/ChromiumCDMChild.h
+++ b/dom/media/gmp/ChromiumCDMChild.h
@@ -15,17 +15,19 @@ namespace mozilla {
 namespace gmp {
 
 class GMPContentChild;
 
 class ChromiumCDMChild : public PChromiumCDMChild,
                          public cdm::Host_9,
                          public cdm::Host_10 {
  public:
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMChild);
+  // Mark AddRef and Release as `final`, as they overload pure virtual
+  // implementations in PChromiumCDMChild.
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMChild, final);
 
   explicit ChromiumCDMChild(GMPContentChild* aPlugin);
 
   void Init(cdm::ContentDecryptionModule_10* aCDM, const nsCString& aStorageId);
 
   void TimerExpired(void* aContext);
 
   // Shared cdm::Host_9 and cdm::Host10 implementation
--- a/dom/media/gmp/ChromiumCDMParent.h
+++ b/dom/media/gmp/ChromiumCDMParent.h
@@ -31,17 +31,19 @@ class GMPContentParent;
 
 class ChromiumCDMParent final : public PChromiumCDMParent,
                                 public GMPCrashHelperHolder {
   friend class PChromiumCDMParent;
 
  public:
   typedef MozPromise<bool, MediaResult, /* IsExclusive = */ true> InitPromise;
 
-  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMParent)
+  // Mark AddRef and Release as `final`, as they overload pure virtual
+  // implementations in PChromiumCDMParent.
+  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ChromiumCDMParent, final)
 
   ChromiumCDMParent(GMPContentParent* aContentParent, uint32_t aPluginId);
 
   uint32_t PluginId() const { return mPluginId; }
 
   RefPtr<InitPromise> Init(ChromiumCDMCallback* aCDMCallback,
                            bool aAllowDistinctiveIdentifier,
                            bool aAllowPersistentState,
--- a/dom/media/gmp/GMPContentChild.cpp
+++ b/dom/media/gmp/GMPContentChild.cpp
@@ -56,25 +56,18 @@ PGMPVideoEncoderChild* GMPContentChild::
 }
 
 bool GMPContentChild::DeallocPGMPVideoEncoderChild(
     PGMPVideoEncoderChild* aActor) {
   static_cast<GMPVideoEncoderChild*>(aActor)->Release();
   return true;
 }
 
-PChromiumCDMChild* GMPContentChild::AllocPChromiumCDMChild() {
-  ChromiumCDMChild* actor = new ChromiumCDMChild(this);
-  actor->AddRef();
-  return actor;
-}
-
-bool GMPContentChild::DeallocPChromiumCDMChild(PChromiumCDMChild* aActor) {
-  static_cast<ChromiumCDMChild*>(aActor)->Release();
-  return true;
+already_AddRefed<PChromiumCDMChild> GMPContentChild::AllocPChromiumCDMChild() {
+  return MakeAndAddRef<ChromiumCDMChild>(this);
 }
 
 mozilla::ipc::IPCResult GMPContentChild::RecvPGMPVideoDecoderConstructor(
     PGMPVideoDecoderChild* aActor, const uint32_t& aDecryptorId) {
   auto vdc = static_cast<GMPVideoDecoderChild*>(aActor);
 
   void* vd = nullptr;
   GMPErr err =
--- a/dom/media/gmp/GMPContentChild.h
+++ b/dom/media/gmp/GMPContentChild.h
@@ -30,18 +30,17 @@ class GMPContentChild : public PGMPConte
 
   PGMPVideoDecoderChild* AllocPGMPVideoDecoderChild(
       const uint32_t& aDecryptorId);
   bool DeallocPGMPVideoDecoderChild(PGMPVideoDecoderChild* aActor);
 
   PGMPVideoEncoderChild* AllocPGMPVideoEncoderChild();
   bool DeallocPGMPVideoEncoderChild(PGMPVideoEncoderChild* aActor);
 
-  PChromiumCDMChild* AllocPChromiumCDMChild();
-  bool DeallocPChromiumCDMChild(PChromiumCDMChild* aActor);
+  already_AddRefed<PChromiumCDMChild> AllocPChromiumCDMChild();
 
   void ActorDestroy(ActorDestroyReason aWhy) override;
   void ProcessingError(Result aCode, const char* aReason) override;
 
   // GMPSharedMem
   void CheckThread() override;
 
   void CloseActive();
--- a/dom/media/gmp/GMPContentParent.cpp
+++ b/dom/media/gmp/GMPContentParent.cpp
@@ -157,21 +157,21 @@ nsCOMPtr<nsISerialEventTarget> GMPConten
     mGMPEventTarget = gmpThread->SerialEventTarget();
   }
 
   return mGMPEventTarget;
 }
 
 already_AddRefed<ChromiumCDMParent> GMPContentParent::GetChromiumCDM() {
   GMP_LOG("GMPContentParent::GetChromiumCDM(this=%p)", this);
-  PChromiumCDMParent* actor = SendPChromiumCDMConstructor();
-  if (!actor) {
+
+  RefPtr<ChromiumCDMParent> parent = new ChromiumCDMParent(this, GetPluginId());
+  if (!SendPChromiumCDMConstructor(parent)) {
     return nullptr;
   }
-  RefPtr<ChromiumCDMParent> parent = static_cast<ChromiumCDMParent*>(actor);
 
   // TODO: Remove parent from mChromiumCDMs in ChromiumCDMParent::Destroy().
   mChromiumCDMs.AppendElement(parent);
 
   return parent.forget();
 }
 
 nsresult GMPContentParent::GetGMPVideoDecoder(GMPVideoDecoderParent** aGMPVD,
@@ -204,39 +204,24 @@ nsresult GMPContentParent::GetGMPVideoEn
   // It's dropped by calling Close() on the interface.
   NS_ADDREF(vep);
   *aGMPVE = vep;
   mVideoEncoders.AppendElement(vep);
 
   return NS_OK;
 }
 
-PChromiumCDMParent* GMPContentParent::AllocPChromiumCDMParent() {
-  GMP_LOG("GMPContentParent::AllocPChromiumCDMParent(this=%p)", this);
-  ChromiumCDMParent* parent = new ChromiumCDMParent(this, GetPluginId());
-  NS_ADDREF(parent);
-  return parent;
-}
-
 PGMPVideoDecoderParent* GMPContentParent::AllocPGMPVideoDecoderParent(
     const uint32_t& aDecryptorId) {
   GMP_LOG("GMPContentParent::AllocPGMPVideoDecoderParent(this=%p)", this);
   GMPVideoDecoderParent* vdp = new GMPVideoDecoderParent(this);
   NS_ADDREF(vdp);
   return vdp;
 }
 
-bool GMPContentParent::DeallocPChromiumCDMParent(PChromiumCDMParent* aActor) {
-  GMP_LOG("GMPContentParent::DeallocPChromiumCDMParent(this=%p, aActor=%p)",
-          this, aActor);
-  ChromiumCDMParent* parent = static_cast<ChromiumCDMParent*>(aActor);
-  NS_RELEASE(parent);
-  return true;
-}
-
 bool GMPContentParent::DeallocPGMPVideoDecoderParent(
     PGMPVideoDecoderParent* aActor) {
   GMP_LOG("GMPContentParent::DeallocPGMPVideoDecoderParent(this=%p, aActor=%p)",
           this, aActor);
   GMPVideoDecoderParent* vdp = static_cast<GMPVideoDecoderParent*>(aActor);
   NS_RELEASE(vdp);
   return true;
 }
--- a/dom/media/gmp/GMPContentParent.h
+++ b/dom/media/gmp/GMPContentParent.h
@@ -71,19 +71,16 @@ class GMPContentParent final : public PG
 
   PGMPVideoDecoderParent* AllocPGMPVideoDecoderParent(
       const uint32_t& aDecryptorId) override;
   bool DeallocPGMPVideoDecoderParent(PGMPVideoDecoderParent* aActor) override;
 
   PGMPVideoEncoderParent* AllocPGMPVideoEncoderParent() override;
   bool DeallocPGMPVideoEncoderParent(PGMPVideoEncoderParent* aActor) override;
 
-  PChromiumCDMParent* AllocPChromiumCDMParent() override;
-  bool DeallocPChromiumCDMParent(PChromiumCDMParent* aActor) override;
-
   void CloseIfUnused();
   // Needed because NewRunnableMethod tried to use the class that the method
   // lives on to store the receiver, but PGMPContentParent isn't refcounted.
   void Close() { PGMPContentParent::Close(); }
 
   nsTArray<RefPtr<GMPVideoDecoderParent>> mVideoDecoders;
   nsTArray<RefPtr<GMPVideoEncoderParent>> mVideoEncoders;
   nsTArray<RefPtr<ChromiumCDMParent>> mChromiumCDMs;
--- a/dom/media/gmp/PChromiumCDM.ipdl
+++ b/dom/media/gmp/PChromiumCDM.ipdl
@@ -4,17 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 include protocol PGMPContent;
 include GMPTypes;
 
 namespace mozilla {
 namespace gmp {
 
-async protocol PChromiumCDM
+async refcounted protocol PChromiumCDM
 {
   manager PGMPContent;
 child:
 
   // cdm::ContentDecryptionModule9+10
   async Init(bool aAllowDistinctiveIdentifier,
              bool aAllowPersistentState) returns (bool unused);