Skip to content

Commit e94fd49

Browse files
committed
Bug 1937908 - Move GMPServiceParent to ShutdownBlockingTicket and make members const. r=aosmond,media-playback-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D234855
1 parent 49de508 commit e94fd49

File tree

3 files changed

+14
-56
lines changed

3 files changed

+14
-56
lines changed

dom/media/gmp/GMPService.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -370,25 +370,6 @@ 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-
392373
nsresult GeckoMediaPluginService::GMPDispatch(nsIRunnable* event,
393374
uint32_t flags) {
394375
nsCOMPtr<nsIRunnable> r(event);

dom/media/gmp/GMPServiceParent.cpp

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "mozilla/SchedulerGroup.h"
2020
#include "mozilla/dom/ContentParent.h"
2121
#include "mozilla/ipc/Endpoint.h"
22+
#include "nsFmtString.h"
2223
#include "nsThreadUtils.h"
2324
#if defined(XP_LINUX) && defined(MOZ_SANDBOX)
2425
# include "mozilla/SandboxInfo.h"
@@ -82,8 +83,7 @@ GeckoMediaPluginServiceParent::GetSingleton() {
8283

8384
NS_IMPL_ISUPPORTS_INHERITED(GeckoMediaPluginServiceParent,
8485
GeckoMediaPluginService,
85-
mozIGeckoMediaPluginChromeService,
86-
nsIAsyncShutdownBlocker)
86+
mozIGeckoMediaPluginChromeService)
8787

8888
GeckoMediaPluginServiceParent::GeckoMediaPluginServiceParent()
8989
: mScannedPluginOnDisk(false),
@@ -1821,20 +1821,6 @@ static bool IsNodeIdValid(GMPParent* aParent) {
18211821
return !aParent->GetNodeId().IsEmpty();
18221822
}
18231823

1824-
NS_IMETHODIMP
1825-
GeckoMediaPluginServiceParent::GetName(nsAString& aName) {
1826-
aName = u"GeckoMediaPluginServiceParent: shutdown"_ns;
1827-
return NS_OK;
1828-
}
1829-
1830-
NS_IMETHODIMP
1831-
GeckoMediaPluginServiceParent::GetState(nsIPropertyBag**) { return NS_OK; }
1832-
1833-
NS_IMETHODIMP
1834-
GeckoMediaPluginServiceParent::BlockShutdown(nsIAsyncShutdownClient*) {
1835-
return NS_OK;
1836-
}
1837-
18381824
// Called from GMPServiceParent::Create() which holds the lock
18391825
void GeckoMediaPluginServiceParent::ServiceUserCreated(
18401826
GMPServiceParent* aServiceParent) {
@@ -1843,15 +1829,6 @@ void GeckoMediaPluginServiceParent::ServiceUserCreated(
18431829

18441830
MOZ_ASSERT(!mServiceParents.Contains(aServiceParent));
18451831
mServiceParents.AppendElement(aServiceParent);
1846-
if (mServiceParents.Length() == 1) {
1847-
nsCOMPtr<nsIAsyncShutdownClient> barrier = GetShutdownBarrier();
1848-
MOZ_RELEASE_ASSERT(barrier);
1849-
1850-
nsresult rv = barrier->AddBlocker(
1851-
this, NS_LITERAL_STRING_FROM_CSTRING(__FILE__), __LINE__,
1852-
u"GeckoMediaPluginServiceParent shutdown"_ns);
1853-
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
1854-
}
18551832
}
18561833

18571834
void GeckoMediaPluginServiceParent::ServiceUserDestroyed(
@@ -1861,12 +1838,6 @@ void GeckoMediaPluginServiceParent::ServiceUserDestroyed(
18611838
MOZ_ASSERT(mServiceParents.Length() > 0);
18621839
MOZ_ASSERT(mServiceParents.Contains(aServiceParent));
18631840
mServiceParents.RemoveElement(aServiceParent);
1864-
if (mServiceParents.IsEmpty()) {
1865-
nsCOMPtr<nsIAsyncShutdownClient> barrier = GetShutdownBarrier();
1866-
MOZ_RELEASE_ASSERT(barrier);
1867-
nsresult rv = barrier->RemoveBlocker(this);
1868-
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
1869-
}
18701841
}
18711842

18721843
void GeckoMediaPluginServiceParent::ClearStorage() {
@@ -1908,15 +1879,19 @@ already_AddRefed<GMPParent> GeckoMediaPluginServiceParent::GetById(
19081879
}
19091880

19101881
GMPServiceParent::GMPServiceParent(GeckoMediaPluginServiceParent* aService)
1911-
: mService(aService) {
1882+
: mService(aService), mShutdownBlocker([](GMPServiceParent* aThis) {
1883+
nsFmtString name(u"GMPServiceParent {}", static_cast<void*>(aThis));
1884+
return media::ShutdownBlockingTicket::Create(
1885+
name, NS_LITERAL_STRING_FROM_CSTRING(__FILE__), __LINE__);
1886+
}(this)) {
19121887
MOZ_ASSERT(NS_IsMainThread(), "Should be constructed on the main thread");
19131888
MOZ_ASSERT(mService);
1889+
MOZ_RELEASE_ASSERT(mShutdownBlocker);
19141890
mService->ServiceUserCreated(this);
19151891
}
19161892

19171893
GMPServiceParent::~GMPServiceParent() {
19181894
MOZ_ASSERT(NS_IsMainThread(), "Should be destroyted on the main thread");
1919-
MOZ_ASSERT(mService);
19201895
mService->ServiceUserDestroyed(this);
19211896
}
19221897

dom/media/gmp/GMPServiceParent.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "nsRefPtrHashtable.h"
1919
#include "nsThreadUtils.h"
2020
#include "mozilla/gmp/PGMPParent.h"
21+
#include "mozilla/media/MediaUtils.h"
2122
#include "mozilla/MozPromise.h"
2223
#include "GMPStorage.h"
2324

@@ -36,16 +37,14 @@ class GMPServiceParent;
3637

3738
class GeckoMediaPluginServiceParent final
3839
: public GeckoMediaPluginService,
39-
public mozIGeckoMediaPluginChromeService,
40-
public nsIAsyncShutdownBlocker {
40+
public mozIGeckoMediaPluginChromeService {
4141
public:
4242
static already_AddRefed<GeckoMediaPluginServiceParent> GetSingleton();
4343

4444
GeckoMediaPluginServiceParent();
4545
nsresult Init() override;
4646

4747
NS_DECL_ISUPPORTS_INHERITED
48-
NS_DECL_NSIASYNCSHUTDOWNBLOCKER
4948

5049
// mozIGeckoMediaPluginService
5150
NS_IMETHOD HasPluginForAPI(const nsACString& aAPI,
@@ -292,7 +291,10 @@ class GMPServiceParent final : public PGMPServiceParent {
292291
private:
293292
~GMPServiceParent();
294293

295-
RefPtr<GeckoMediaPluginServiceParent> mService;
294+
const RefPtr<GeckoMediaPluginServiceParent> mService;
295+
296+
// Ticket that controls the shutdown blocker.
297+
const UniquePtr<media::ShutdownBlockingTicket> mShutdownBlocker;
296298
};
297299

298300
} // namespace gmp

0 commit comments

Comments
 (0)