Skip to content

Commit 49de508

Browse files
committed
Bug 1937908 - Move GMPServiceChild to ShutdownBlockingTicket. r=aosmond,media-playback-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D234854
1 parent 99f9d6e commit 49de508

File tree

2 files changed

+26
-68
lines changed

2 files changed

+26
-68
lines changed

dom/media/gmp/GMPServiceChild.cpp

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "mozilla/ipc/Endpoint.h"
1919
#include "nsCOMPtr.h"
2020
#include "nsComponentManagerUtils.h"
21+
#include "nsFmtString.h"
2122
#include "nsIObserverService.h"
2223
#include "nsReadableUtils.h"
2324
#include "nsXPCOMPrivate.h"
@@ -62,37 +63,8 @@ nsresult GeckoMediaPluginServiceChild::Init() {
6263
return GeckoMediaPluginService::Init();
6364
}
6465

65-
NS_IMPL_ISUPPORTS_INHERITED(GeckoMediaPluginServiceChild,
66-
GeckoMediaPluginService, nsIAsyncShutdownBlocker)
67-
68-
// Used to identify blockers that we put in place.
69-
static const nsLiteralString kShutdownBlockerName =
70-
u"GeckoMediaPluginServiceChild: shutdown"_ns;
71-
72-
// nsIAsyncShutdownBlocker members
73-
NS_IMETHODIMP
74-
GeckoMediaPluginServiceChild::GetName(nsAString& aName) {
75-
aName = kShutdownBlockerName;
76-
return NS_OK;
77-
}
78-
79-
NS_IMETHODIMP
80-
GeckoMediaPluginServiceChild::GetState(nsIPropertyBag**) { return NS_OK; }
81-
82-
NS_IMETHODIMP
83-
GeckoMediaPluginServiceChild::BlockShutdown(nsIAsyncShutdownClient*) {
84-
MOZ_ASSERT(NS_IsMainThread());
85-
GMP_LOG_DEBUG("%s::%s", __CLASS__, __FUNCTION__);
86-
87-
mXPCOMWillShutdown = true;
88-
89-
MutexAutoLock lock(mMutex);
90-
Unused << NS_WARN_IF(NS_FAILED(mGMPThread->Dispatch(
91-
NewRunnableMethod("GeckoMediaPluginServiceChild::BeginShutdown", this,
92-
&GeckoMediaPluginServiceChild::BeginShutdown))));
93-
return NS_OK;
94-
}
95-
// End nsIAsyncShutdownBlocker members
66+
NS_IMPL_ISUPPORTS_INHERITED0(GeckoMediaPluginServiceChild,
67+
GeckoMediaPluginService)
9668

9769
GeckoMediaPluginServiceChild::~GeckoMediaPluginServiceChild() {
9870
MOZ_ASSERT(!mServiceChild);
@@ -480,21 +452,28 @@ nsresult GeckoMediaPluginServiceChild::AddShutdownBlocker() {
480452
MOZ_ASSERT(NS_IsMainThread());
481453
MOZ_ASSERT(!mShuttingDownOnGMPThread,
482454
"No call paths should add blockers once we're shutting down!");
483-
MOZ_ASSERT(!mShutdownBlockerAdded, "Should only add blocker once!");
455+
MOZ_ASSERT(!mShutdownBlocker, "Should only add blocker once!");
484456
GMP_LOG_DEBUG("%s::%s ", __CLASS__, __FUNCTION__);
485457

486-
nsCOMPtr<nsIAsyncShutdownClient> barrier = GetShutdownBarrier();
487-
if (NS_WARN_IF(!barrier)) {
488-
return NS_ERROR_NOT_AVAILABLE;
458+
nsFmtString name(u"GeckoMediaPluginServiceChild {}",
459+
static_cast<void*>(this));
460+
mShutdownBlocker = media::ShutdownBlockingTicket::Create(
461+
name, NS_LITERAL_STRING_FROM_CSTRING(__FILE__), __LINE__);
462+
if (mShutdownBlocker) {
463+
mShutdownBlocker->ShutdownPromise()->Then(
464+
mMainThread, __func__, [this, self = RefPtr(this), name]() {
465+
GMP_LOG_DEBUG("GMPServiceChild::BlockShutdown: %s",
466+
NS_ConvertUTF16toUTF8(name).get());
467+
mXPCOMWillShutdown = true;
468+
nsCOMPtr gmpThread = GetGMPThread();
469+
gmpThread->Dispatch(
470+
NewRunnableMethod("GMPServiceChild::BeginShutdown", this,
471+
&GeckoMediaPluginServiceChild::BeginShutdown));
472+
});
473+
return NS_OK;
489474
}
490475

491-
nsresult rv =
492-
barrier->AddBlocker(this, NS_LITERAL_STRING_FROM_CSTRING(__FILE__),
493-
__LINE__, kShutdownBlockerName);
494-
#ifdef DEBUG
495-
mShutdownBlockerAdded = NS_SUCCEEDED(rv);
496-
#endif
497-
return rv;
476+
return NS_ERROR_FAILURE;
498477
}
499478

500479
void GeckoMediaPluginServiceChild::RemoveShutdownBlocker() {
@@ -503,23 +482,7 @@ void GeckoMediaPluginServiceChild::RemoveShutdownBlocker() {
503482
"We should only remove blockers once we're "
504483
"shutting down!");
505484
GMP_LOG_DEBUG("%s::%s ", __CLASS__, __FUNCTION__);
506-
nsresult rv = mMainThread->Dispatch(NS_NewRunnableFunction(
507-
"GeckoMediaPluginServiceChild::"
508-
"RemoveShutdownBlocker",
509-
[this, self = RefPtr<GeckoMediaPluginServiceChild>(this)]() {
510-
nsCOMPtr<nsIAsyncShutdownClient> barrier = GetShutdownBarrier();
511-
if (NS_WARN_IF(!barrier)) {
512-
return;
513-
}
514-
515-
nsresult rv = barrier->RemoveBlocker(this);
516-
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
517-
}));
518-
if (NS_WARN_IF(NS_FAILED(rv))) {
519-
MOZ_ASSERT_UNREACHABLE(
520-
"Main thread should always be alive when we "
521-
"call this!");
522-
}
485+
mShutdownBlocker = nullptr;
523486
}
524487

525488
void GeckoMediaPluginServiceChild::RemoveShutdownBlockerIfNeeded() {

dom/media/gmp/GMPServiceChild.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "base/process.h"
1212
#include "mozilla/dom/PContent.h"
1313
#include "mozilla/gmp/PGMPServiceChild.h"
14+
#include "mozilla/media/MediaUtils.h"
1415
#include "mozilla/MozPromise.h"
15-
#include "nsIAsyncShutdown.h"
1616
#include "nsRefPtrHashtable.h"
1717

1818
namespace mozilla::gmp {
@@ -21,16 +21,14 @@ class GMPContentParent;
2121
class GMPContentParentCloseBlocker;
2222
class GMPServiceChild;
2323

24-
class GeckoMediaPluginServiceChild : public GeckoMediaPluginService,
25-
public nsIAsyncShutdownBlocker {
24+
class GeckoMediaPluginServiceChild : public GeckoMediaPluginService {
2625
friend class GMPServiceChild;
2726

2827
public:
2928
static already_AddRefed<GeckoMediaPluginServiceChild> GetSingleton();
3029
nsresult Init() override;
3130

3231
NS_DECL_ISUPPORTS_INHERITED
33-
NS_DECL_NSIASYNCSHUTDOWNBLOCKER
3432

3533
NS_IMETHOD HasPluginForAPI(const nsACString& aAPI,
3634
const nsTArray<nsCString>& aTags,
@@ -124,11 +122,8 @@ class GeckoMediaPluginServiceChild : public GeckoMediaPluginService,
124122
// - mShutdownBlockerHasBeenAdded.
125123
void RemoveShutdownBlockerIfNeeded();
126124

127-
#ifdef DEBUG
128-
// Track if we've added a shutdown blocker for sanity checking. Main thread
129-
// only.
130-
bool mShutdownBlockerAdded = false;
131-
#endif // DEBUG
125+
// Ticket that controls the shutdown blocker.
126+
UniquePtr<media::ShutdownBlockingTicket> mShutdownBlocker;
132127
// The number of GetContentParent calls that have not yet been resolved or
133128
// rejected. We use this value to help determine if we need to block
134129
// shutdown. Should only be used on GMP thread to avoid races.

0 commit comments

Comments
 (0)