Bug 1522951 - Make ChromiumCDMProxy::mCrashHelper into a strong reference. r=jya a=lizzard
authorAndrew McCreight <continuation@gmail.com>
Fri, 01 Feb 2019 00:20:19 +0000
changeset 515777 70ad33dab5d6cdbf3e39bce0eb81142323d077c8
parent 515776 be69f7164f217491b3219b0182f331e8209cba5e
child 515778 9d24a22bcd5d0abf805100786335d4b2c603a635
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya, lizzard
bugs1522951
milestone66.0
Bug 1522951 - Make ChromiumCDMProxy::mCrashHelper into a strong reference. r=jya a=lizzard Refcounted objects should be put into refptrs when they are created. This patch also moves the crash helper out of the object early in Init, to maybe reduce the chance of a leak if it fails early. This field is only used to pass in a value to the Init() method. It can't be passed in directly because on Android there are two implementations of CDMProxy, and MediaDrmCDMProxy doesn't take a crash helper. Differential Revision: https://phabricator.services.mozilla.com/D17707
dom/media/gmp/ChromiumCDMProxy.cpp
dom/media/gmp/ChromiumCDMProxy.h
--- a/dom/media/gmp/ChromiumCDMProxy.cpp
+++ b/dom/media/gmp/ChromiumCDMProxy.cpp
@@ -33,16 +33,19 @@ ChromiumCDMProxy::ChromiumCDMProxy(dom::
 }
 
 ChromiumCDMProxy::~ChromiumCDMProxy() { MOZ_COUNT_DTOR(ChromiumCDMProxy); }
 
 void ChromiumCDMProxy::Init(PromiseId aPromiseId, const nsAString& aOrigin,
                             const nsAString& aTopLevelOrigin,
                             const nsAString& aGMPName) {
   MOZ_ASSERT(NS_IsMainThread());
+
+  RefPtr<GMPCrashHelper> helper(std::move(mCrashHelper));
+
   NS_ENSURE_TRUE_VOID(!mKeys.IsNull());
 
   EME_LOG(
       "ChromiumCDMProxy::Init (pid=%u, origin=%s, topLevelOrigin=%s, gmp=%s)",
       aPromiseId, NS_ConvertUTF16toUTF8(aOrigin).get(),
       NS_ConvertUTF16toUTF8(aTopLevelOrigin).get(),
       NS_ConvertUTF16toUTF8(aGMPName).get());
 
@@ -57,17 +60,16 @@ void ChromiumCDMProxy::Init(PromiseId aP
     RejectPromise(aPromiseId, NS_ERROR_DOM_INVALID_STATE_ERR,
                   nsPrintfCString("Unknown GMP for keysystem '%s'",
                                   NS_ConvertUTF16toUTF8(mKeySystem).get()));
     return;
   }
 
   gmp::NodeId nodeId(aOrigin, aTopLevelOrigin, aGMPName);
   RefPtr<AbstractThread> thread = mGMPThread;
-  RefPtr<GMPCrashHelper> helper(mCrashHelper);
   RefPtr<ChromiumCDMProxy> self(this);
   nsCString keySystem = NS_ConvertUTF16toUTF8(mKeySystem);
   RefPtr<Runnable> task(NS_NewRunnableFunction(
       "ChromiumCDMProxy::Init",
       [self, nodeId, helper, aPromiseId, thread, keySystem]() -> void {
         MOZ_ASSERT(self->IsOnOwnerThread());
 
         RefPtr<gmp::GeckoMediaPluginService> service =
--- a/dom/media/gmp/ChromiumCDMProxy.h
+++ b/dom/media/gmp/ChromiumCDMProxy.h
@@ -106,17 +106,17 @@ class ChromiumCDMProxy : public CDMProxy
   void OnResolvePromiseWithKeyStatus(uint32_t aPromiseId,
                                      dom::MediaKeyStatus aKeyStatus);
 
  private:
   void OnCDMCreated(uint32_t aPromiseId);
 
   ~ChromiumCDMProxy();
 
-  GMPCrashHelper* mCrashHelper;
+  RefPtr<GMPCrashHelper> mCrashHelper;
 
   Mutex mCDMMutex;
   RefPtr<gmp::ChromiumCDMParent> mCDM;
   RefPtr<AbstractThread> mGMPThread;
   UniquePtr<ChromiumCDMCallbackProxy> mCallback;
 };
 
 }  // namespace mozilla