18
18
#include " mozilla/ipc/Endpoint.h"
19
19
#include " nsCOMPtr.h"
20
20
#include " nsComponentManagerUtils.h"
21
+ #include " nsFmtString.h"
21
22
#include " nsIObserverService.h"
22
23
#include " nsReadableUtils.h"
23
24
#include " nsXPCOMPrivate.h"
@@ -62,37 +63,8 @@ nsresult GeckoMediaPluginServiceChild::Init() {
62
63
return GeckoMediaPluginService::Init ();
63
64
}
64
65
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)
96
68
97
69
GeckoMediaPluginServiceChild::~GeckoMediaPluginServiceChild () {
98
70
MOZ_ASSERT (!mServiceChild );
@@ -480,21 +452,28 @@ nsresult GeckoMediaPluginServiceChild::AddShutdownBlocker() {
480
452
MOZ_ASSERT (NS_IsMainThread());
481
453
MOZ_ASSERT (!mShuttingDownOnGMPThread ,
482
454
" 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!" );
484
456
GMP_LOG_DEBUG (" %s::%s " , __CLASS__, __FUNCTION__);
485
457
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;
489
474
}
490
475
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;
498
477
}
499
478
500
479
void GeckoMediaPluginServiceChild::RemoveShutdownBlocker () {
@@ -503,23 +482,7 @@ void GeckoMediaPluginServiceChild::RemoveShutdownBlocker() {
503
482
" We should only remove blockers once we're "
504
483
" shutting down!" );
505
484
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 ;
523
486
}
524
487
525
488
void GeckoMediaPluginServiceChild::RemoveShutdownBlockerIfNeeded () {
0 commit comments