summaryrefslogtreecommitdiffstats
path: root/dom/media/gmp/ChromiumCDMProxy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/media/gmp/ChromiumCDMProxy.cpp')
-rw-r--r--dom/media/gmp/ChromiumCDMProxy.cpp72
1 files changed, 47 insertions, 25 deletions
diff --git a/dom/media/gmp/ChromiumCDMProxy.cpp b/dom/media/gmp/ChromiumCDMProxy.cpp
index f00b4bc..4af9473 100644
--- a/dom/media/gmp/ChromiumCDMProxy.cpp
+++ b/dom/media/gmp/ChromiumCDMProxy.cpp
@@ -22,17 +22,18 @@ ChromiumCDMProxy::ChromiumCDMProxy(dom::MediaKeys* aKeys,
GMPCrashHelper* aCrashHelper,
bool aDistinctiveIdentifierRequired,
bool aPersistentStateRequired,
- nsIEventTarget* aMainThread)
+ nsISerialEventTarget* aMainThread)
: CDMProxy(aKeys, aKeySystem, aDistinctiveIdentifierRequired,
aPersistentStateRequired, aMainThread),
mCrashHelper(aCrashHelper),
mCDMMutex("ChromiumCDMProxy"),
mGMPThread(GetGMPAbstractThread()) {
MOZ_ASSERT(NS_IsMainThread());
- MOZ_COUNT_CTOR(ChromiumCDMProxy);
}
-ChromiumCDMProxy::~ChromiumCDMProxy() { MOZ_COUNT_DTOR(ChromiumCDMProxy); }
+ChromiumCDMProxy::~ChromiumCDMProxy() {
+ EME_LOG("ChromiumCDMProxy::~ChromiumCDMProxy(this=%p)", this);
+}
void ChromiumCDMProxy::Init(PromiseId aPromiseId, const nsAString& aOrigin,
const nsAString& aTopLevelOrigin,
@@ -90,13 +91,25 @@ void ChromiumCDMProxy::Init(PromiseId aPromiseId, const nsAString& aOrigin,
cdm->Init(self->mCallback.get(),
self->mDistinctiveIdentifierRequired,
self->mPersistentStateRequired, self->mMainThread)
- ->Then(thread, __func__,
+ ->Then(self->mMainThread, __func__,
[self, aPromiseId, cdm](bool /* unused */) {
// CDM init succeeded
{
MutexAutoLock lock(self->mCDMMutex);
self->mCDM = cdm;
}
+ if (self->mIsShutdown) {
+ self->RejectPromise(
+ aPromiseId, NS_ERROR_DOM_INVALID_STATE_ERR,
+ NS_LITERAL_CSTRING(
+ "ChromiumCDMProxy shutdown during "
+ "ChromiumCDMProxy::Init"));
+ // If shutdown happened while waiting to init, we
+ // need to explicitly shutdown the CDM to avoid it
+ // referencing this proxy which is on its way out.
+ self->ShutdownCDMIfExists();
+ return;
+ }
self->OnCDMCreated(aPromiseId);
},
[self, aPromiseId](MediaResult aResult) {
@@ -118,13 +131,6 @@ void ChromiumCDMProxy::OnCDMCreated(uint32_t aPromiseId) {
EME_LOG("ChromiumCDMProxy::OnCDMCreated(pid=%u) isMainThread=%d this=%p",
aPromiseId, NS_IsMainThread(), this);
- if (!NS_IsMainThread()) {
- mMainThread->Dispatch(NewRunnableMethod<PromiseId>(
- "ChromiumCDMProxy::OnCDMCreated", this,
- &ChromiumCDMProxy::OnCDMCreated, aPromiseId),
- NS_DISPATCH_NORMAL);
- return;
- }
MOZ_ASSERT(NS_IsMainThread());
if (mKeys.IsNull()) {
return;
@@ -141,6 +147,29 @@ void ChromiumCDMProxy::OnCDMCreated(uint32_t aPromiseId) {
}
}
+void ChromiumCDMProxy::ShutdownCDMIfExists() {
+ EME_LOG(
+ "ChromiumCDMProxy::ShutdownCDMIfExists(this=%p) mCDM=%p, mIsShutdown=%s",
+ this, mCDM.get(), mIsShutdown ? "true" : "false");
+ MOZ_ASSERT(NS_IsMainThread());
+ MOZ_ASSERT(mGMPThread);
+ MOZ_ASSERT(mIsShutdown,
+ "Should only shutdown the CDM if the proxy is shutting down");
+ RefPtr<gmp::ChromiumCDMParent> cdm;
+ {
+ MutexAutoLock lock(mCDMMutex);
+ cdm.swap(mCDM);
+ }
+ if (cdm) {
+ // We need to keep this proxy alive until the parent has finished its
+ // Shutdown (as it may still try to use the proxy until then).
+ RefPtr<ChromiumCDMProxy> self(this);
+ nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction(
+ "ChromiumCDMProxy::Shutdown", [self, cdm]() { cdm->Shutdown(); });
+ mGMPThread->Dispatch(task.forget());
+ }
+}
+
#ifdef DEBUG
bool ChromiumCDMProxy::IsOnOwnerThread() {
return mGMPThread->IsCurrentThreadIn();
@@ -294,21 +323,14 @@ void ChromiumCDMProxy::RemoveSession(const nsAString& aSessionId,
void ChromiumCDMProxy::Shutdown() {
MOZ_ASSERT(NS_IsMainThread());
- EME_LOG("ChromiumCDMProxy::Shutdown()");
- mKeys.Clear();
- RefPtr<gmp::ChromiumCDMParent> cdm;
- {
- MutexAutoLock lock(mCDMMutex);
- cdm.swap(mCDM);
- }
- if (cdm) {
- // We need to keep this proxy alive until the parent has finished its
- // Shutdown (as it may still try to use the proxy until then).
- RefPtr<ChromiumCDMProxy> self(this);
- nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction(
- "ChromiumCDMProxy::Shutdown", [self, cdm]() { cdm->Shutdown(); });
- mGMPThread->Dispatch(task.forget());
+ EME_LOG("ChromiumCDMProxy::Shutdown(this=%p) mCDM=%p, mIsShutdown=%s", this,
+ mCDM.get(), mIsShutdown ? "true" : "false");
+ if (mIsShutdown) {
+ return;
}
+ mIsShutdown = true;
+ mKeys.Clear();
+ ShutdownCDMIfExists();
}
void ChromiumCDMProxy::RejectPromise(PromiseId aId, nsresult aCode,