Skip to content

Commit ee12db0

Browse files
committed
Backed out 5 changesets (bug 1937908) for causing build bustages @ GMPParent.cpp CLOSED TREE
Backed out changeset de6301e43b81 (bug 1937908) Backed out changeset 4723190b3ae4 (bug 1937908) Backed out changeset f0b7d22731bc (bug 1937908) Backed out changeset 1cf5ffd4299a (bug 1937908) Backed out changeset 866fa8510165 (bug 1937908)
1 parent 0a66124 commit ee12db0

File tree

9 files changed

+157
-74
lines changed

9 files changed

+157
-74
lines changed

dom/media/gmp/GMPParent.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ GMPParent::GMPParent()
8181
mChildLaunchArch(base::PROCESS_ARCH_INVALID),
8282
#endif
8383
mMainThread(GetMainThreadSerialEventTarget()) {
84-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
84+
MOZ_ASSERT(IsOnGMPEventTarget());
8585
GMP_PARENT_LOG_DEBUG("GMPParent ctor id=%u", mPluginId);
8686
}
8787

@@ -92,7 +92,7 @@ GMPParent::~GMPParent() {
9292
}
9393

9494
void GMPParent::CloneFrom(const GMPParent* aOther) {
95-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
95+
MOZ_ASSERT(IsOnGMPEventTarget());
9696
MOZ_ASSERT(aOther->mDirectory && aOther->mService, "null plugin directory");
9797

9898
mService = aOther->mService;
@@ -169,7 +169,7 @@ RefPtr<GenericPromise> GMPParent::Init(GeckoMediaPluginServiceParent* aService,
169169
nsIFile* aPluginDir) {
170170
MOZ_ASSERT(aPluginDir);
171171
MOZ_ASSERT(aService);
172-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
172+
MOZ_ASSERT(IsOnGMPEventTarget());
173173

174174
mService = aService;
175175
mDirectory = aPluginDir;
@@ -343,7 +343,7 @@ class NotifyGMPProcessLoadedTask : public Runnable {
343343

344344
nsresult GMPParent::LoadProcess() {
345345
MOZ_ASSERT(mDirectory, "Plugin directory cannot be NULL!");
346-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
346+
MOZ_ASSERT(IsOnGMPEventTarget());
347347
MOZ_ASSERT(mState == GMPState::NotLoaded);
348348

349349
if (NS_WARN_IF(mPluginType == GMPPluginType::WidevineL1)) {
@@ -433,7 +433,7 @@ nsresult GMPParent::LoadProcess() {
433433
}
434434

435435
void GMPParent::OnPreferenceChange(const mozilla::dom::Pref& aPref) {
436-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
436+
MOZ_ASSERT(IsOnGMPEventTarget());
437437
GMP_PARENT_LOG_DEBUG("%s", __FUNCTION__);
438438

439439
if (!mProcess || !mProcess->UseXPCOM()) {
@@ -501,7 +501,7 @@ mozilla::ipc::IPCResult GMPParent::RecvGetModulesTrust(
501501
#endif // defined(XP_WIN)
502502

503503
void GMPParent::CloseIfUnused() {
504-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
504+
MOZ_ASSERT(IsOnGMPEventTarget());
505505
GMP_PARENT_LOG_DEBUG("%s", __FUNCTION__);
506506

507507
if ((mDeleteProcessOnlyOnUnload || mState == GMPState::Loaded ||
@@ -524,7 +524,7 @@ void GMPParent::CloseIfUnused() {
524524
}
525525

526526
void GMPParent::CloseActive(bool aDieWhenUnloaded) {
527-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
527+
MOZ_ASSERT(IsOnGMPEventTarget());
528528
GMP_PARENT_LOG_DEBUG("%s: state %u", __FUNCTION__,
529529
uint32_t(GMPState(mState)));
530530

@@ -548,7 +548,7 @@ void GMPParent::MarkForDeletion() {
548548
bool GMPParent::IsMarkedForDeletion() { return mIsBlockingDeletion; }
549549

550550
void GMPParent::Shutdown() {
551-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
551+
MOZ_ASSERT(IsOnGMPEventTarget());
552552
GMP_PARENT_LOG_DEBUG("%s", __FUNCTION__);
553553

554554
if (mAbnormalShutdownInProgress) {
@@ -615,7 +615,7 @@ void GMPParent::ChildTerminated() {
615615
}
616616

617617
void GMPParent::DeleteProcess() {
618-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
618+
MOZ_ASSERT(IsOnGMPEventTarget());
619619

620620
switch (mState) {
621621
case GMPState::Closed:
@@ -701,7 +701,17 @@ void GMPParent::DeleteProcess() {
701701

702702
GMPState GMPParent::State() const { return mState; }
703703

704-
nsCOMPtr<nsISerialEventTarget> GMPParent::GMPEventTarget() {
704+
bool GMPParent::IsOnGMPEventTarget() const {
705+
auto target = GMPEventTarget();
706+
if (!target) {
707+
// We can't get the GMP event target if it has started shutting down, but it
708+
// may still run tasks.
709+
return AppShutdown::IsInOrBeyond(ShutdownPhase::XPCOMShutdownThreads);
710+
}
711+
return target->IsOnCurrentThread();
712+
}
713+
714+
nsCOMPtr<nsISerialEventTarget> GMPParent::GMPEventTarget() const {
705715
nsCOMPtr<mozIGeckoMediaPluginService> mps =
706716
do_GetService("@mozilla.org/gecko-media-plugin-service;1");
707717
MOZ_ASSERT(mps);
@@ -813,9 +823,8 @@ static void GMPNotifyObservers(const uint32_t aPluginID,
813823
}
814824

815825
void GMPParent::ActorDestroy(ActorDestroyReason aWhy) {
816-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
817-
GMP_PARENT_LOG_DEBUG("%s: (%d), state=%u", __FUNCTION__, (int)aWhy,
818-
static_cast<GMPState>(mState));
826+
MOZ_ASSERT(IsOnGMPEventTarget());
827+
GMP_PARENT_LOG_DEBUG("%s: (%d)", __FUNCTION__, (int)aWhy);
819828

820829
if (AbnormalShutdown == aWhy) {
821830
Telemetry::Accumulate(Telemetry::SUBPROCESS_ABNORMAL_ABORT, "gmplugin"_ns,
@@ -840,8 +849,7 @@ void GMPParent::ActorDestroy(ActorDestroyReason aWhy) {
840849
mAbnormalShutdownInProgress = true;
841850
CloseActive(false);
842851

843-
// Normal Shutdown() will delete the process on unwind. GMPProcessParent
844-
// blocks shutdown to avoid races.
852+
// Normal Shutdown() will delete the process on unwind.
845853
if (AbnormalShutdown == aWhy) {
846854
RefPtr<GMPParent> self(this);
847855
// Must not call Close() again in DeleteProcess(), as we'll recurse
@@ -908,7 +916,7 @@ bool ReadInfoField(GMPInfoFileParser& aParser, const nsCString& aKey,
908916
}
909917

910918
RefPtr<GenericPromise> GMPParent::ReadGMPMetaData() {
911-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
919+
MOZ_ASSERT(IsOnGMPEventTarget());
912920
MOZ_ASSERT(mDirectory, "Plugin directory cannot be NULL!");
913921
MOZ_ASSERT(!mName.IsEmpty(), "Plugin mName cannot be empty!");
914922

@@ -997,7 +1005,7 @@ static nsresult ParseVersion(const nsACString& aVersion,
9971005
}
9981006

9991007
RefPtr<GenericPromise> GMPParent::ReadGMPInfoFile(nsIFile* aFile) {
1000-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
1008+
MOZ_ASSERT(IsOnGMPEventTarget());
10011009
GMPInfoFileParser parser;
10021010
if (!parser.Init(aFile)) {
10031011
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
@@ -1105,7 +1113,7 @@ RefPtr<GenericPromise> GMPParent::ReadGMPInfoFile(nsIFile* aFile) {
11051113
}
11061114

11071115
RefPtr<GenericPromise> GMPParent::ReadChromiumManifestFile(nsIFile* aFile) {
1108-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
1116+
MOZ_ASSERT(IsOnGMPEventTarget());
11091117
nsAutoCString json;
11101118
if (!ReadIntoString(aFile, json, 5 * 1024)) {
11111119
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
@@ -1335,7 +1343,7 @@ void GMPParent::ResolveGetContentParentPromises() {
13351343
}
13361344

13371345
bool GMPParent::OpenPGMPContent() {
1338-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
1346+
MOZ_ASSERT(IsOnGMPEventTarget());
13391347
MOZ_ASSERT(!mGMPContentParent);
13401348

13411349
Endpoint<PGMPContentParent> parent;
@@ -1372,7 +1380,7 @@ void GMPParent::RejectGetContentParentPromises() {
13721380

13731381
void GMPParent::GetGMPContentParent(
13741382
UniquePtr<MozPromiseHolder<GetGMPContentParentPromise>>&& aPromiseHolder) {
1375-
MOZ_ASSERT(GMPEventTarget()->IsOnCurrentThread());
1383+
MOZ_ASSERT(IsOnGMPEventTarget());
13761384
GMP_PARENT_LOG_DEBUG("%s %p", __FUNCTION__, this);
13771385

13781386
if (mGMPContentParent) {

dom/media/gmp/GMPParent.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class GMPParent final
9191
void DeleteProcess();
9292

9393
GMPState State() const;
94-
nsCOMPtr<nsISerialEventTarget> GMPEventTarget();
94+
bool IsOnGMPEventTarget() const;
95+
nsCOMPtr<nsISerialEventTarget> GMPEventTarget() const;
9596

9697
void OnPreferenceChange(const mozilla::dom::Pref& aPref);
9798

@@ -129,6 +130,8 @@ class GMPParent final
129130
return nsCOMPtr<nsIFile>(mDirectory).forget();
130131
}
131132

133+
void AbortAsyncShutdown();
134+
132135
// Called when the child process has died.
133136
void ChildTerminated();
134137

dom/media/gmp/GMPProcessParent.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "mozilla/ipc/ProcessChild.h"
1616
#include "mozilla/ipc/ProcessUtils.h"
1717
#include "mozilla/StaticPrefs_media.h"
18-
#include "nsFmtString.h"
1918

2019
#include "base/string_util.h"
2120
#include "base/process_util.h"
@@ -233,14 +232,7 @@ bool GMPProcessParent::Launch(int32_t aTimeoutMs) {
233232
// We need to wait until OnChannelConnected to clear the pref serializer, but
234233
// SyncLaunch will block until that is called, so we don't actually need to do
235234
// any overriding, and it only lives on the stack.
236-
bool launched = SyncLaunch(std::move(args), aTimeoutMs);
237-
if (launched) {
238-
nsFmtString name{FMT_STRING(u"GMPProcessParent {}"),
239-
static_cast<void*>(this)};
240-
mShutdownBlocker = media::ShutdownBlockingTicket::Create(
241-
name, NS_LITERAL_STRING_FROM_CSTRING(__FILE__), __LINE__);
242-
}
243-
return launched;
235+
return SyncLaunch(std::move(args), aTimeoutMs);
244236
}
245237

246238
void GMPProcessParent::Delete(nsCOMPtr<nsIRunnable> aCallback) {

dom/media/gmp/GMPProcessParent.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "base/file_path.h"
1313
#include "base/thread.h"
1414
#include "mozilla/ipc/GeckoChildProcessHost.h"
15-
#include "mozilla/media/MediaUtils.h"
1615
#include "nsIFile.h"
1716

1817
class nsIRunnable;
@@ -90,9 +89,6 @@ class GMPProcessParent final : public mozilla::ipc::GeckoChildProcessHost {
9089
# endif
9190
#endif
9291

93-
// Ticket for blocking shutdown while the process is live.
94-
UniquePtr<media::ShutdownBlockingTicket> mShutdownBlocker;
95-
9692
// For normalizing paths to be compatible with sandboxing.
9793
// We use normalized paths to generate the sandbox ruleset. Once
9894
// the sandbox has been started, resolving symlinks that point to

dom/media/gmp/GMPService.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,25 @@ void GeckoMediaPluginService::ShutdownGMPThread() {
370370
}
371371
}
372372

373+
/* static */
374+
nsCOMPtr<nsIAsyncShutdownClient> GeckoMediaPluginService::GetShutdownBarrier() {
375+
nsCOMPtr<nsIAsyncShutdownService> svc = services::GetAsyncShutdownService();
376+
if (NS_WARN_IF(!svc)) {
377+
MOZ_ASSERT_UNREACHABLE("No async shutdown service!");
378+
return nullptr;
379+
}
380+
381+
nsCOMPtr<nsIAsyncShutdownClient> barrier;
382+
nsresult rv = svc->GetXpcomWillShutdown(getter_AddRefs(barrier));
383+
if (NS_WARN_IF(NS_FAILED(rv))) {
384+
MOZ_ASSERT_UNREACHABLE("Could not create shutdown barrier!");
385+
return nullptr;
386+
}
387+
388+
MOZ_RELEASE_ASSERT(barrier);
389+
return barrier;
390+
}
391+
373392
nsresult GeckoMediaPluginService::GMPDispatch(nsIRunnable* event,
374393
uint32_t flags) {
375394
nsCOMPtr<nsIRunnable> r(event);

dom/media/gmp/GMPServiceChild.cpp

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

66-
NS_IMPL_ISUPPORTS_INHERITED0(GeckoMediaPluginServiceChild,
67-
GeckoMediaPluginService)
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
6896

6997
GeckoMediaPluginServiceChild::~GeckoMediaPluginServiceChild() {
7098
MOZ_ASSERT(!mServiceChild);
@@ -452,28 +480,21 @@ nsresult GeckoMediaPluginServiceChild::AddShutdownBlocker() {
452480
MOZ_ASSERT(NS_IsMainThread());
453481
MOZ_ASSERT(!mShuttingDownOnGMPThread,
454482
"No call paths should add blockers once we're shutting down!");
455-
MOZ_ASSERT(!mShutdownBlocker, "Should only add blocker once!");
483+
MOZ_ASSERT(!mShutdownBlockerAdded, "Should only add blocker once!");
456484
GMP_LOG_DEBUG("%s::%s ", __CLASS__, __FUNCTION__);
457485

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;
486+
nsCOMPtr<nsIAsyncShutdownClient> barrier = GetShutdownBarrier();
487+
if (NS_WARN_IF(!barrier)) {
488+
return NS_ERROR_NOT_AVAILABLE;
474489
}
475490

476-
return NS_ERROR_FAILURE;
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;
477498
}
478499

479500
void GeckoMediaPluginServiceChild::RemoveShutdownBlocker() {
@@ -482,7 +503,23 @@ void GeckoMediaPluginServiceChild::RemoveShutdownBlocker() {
482503
"We should only remove blockers once we're "
483504
"shutting down!");
484505
GMP_LOG_DEBUG("%s::%s ", __CLASS__, __FUNCTION__);
485-
mShutdownBlocker = nullptr;
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+
}
486523
}
487524

488525
void GeckoMediaPluginServiceChild::RemoveShutdownBlockerIfNeeded() {

0 commit comments

Comments
 (0)