Bug 1407415 - Consolidate media::GetShutdownBarrier() use and return a RefPtr r=dminor

Differential Revision: https://phabricator.services.mozilla.com/D29700

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan-Ivar Bruaroey 2019-05-03 21:08:42 +00:00
Родитель 2a825b2d8a
Коммит e52e8837ef
4 изменённых файлов: 9 добавлений и 33 удалений

Просмотреть файл

@ -168,24 +168,6 @@ class nsMainThreadPtrHolder<
nsMainThreadPtrHolder(const nsMainThreadPtrHolder& aOther) = delete;
};
namespace {
already_AddRefed<nsIAsyncShutdownClient> GetShutdownPhase() {
nsCOMPtr<nsIAsyncShutdownService> svc = mozilla::services::GetAsyncShutdown();
MOZ_RELEASE_ASSERT(svc);
nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase;
nsresult rv = svc->GetProfileBeforeChange(getter_AddRefs(shutdownPhase));
if (!shutdownPhase) {
// We are probably in a content process. We need to do cleanup at
// XPCOM shutdown in leakchecking builds.
rv = svc->GetXpcomWillShutdown(getter_AddRefs(shutdownPhase));
}
MOZ_RELEASE_ASSERT(shutdownPhase);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
return shutdownPhase.forget();
}
} // namespace
namespace mozilla {
#ifdef LOG
@ -2025,8 +2007,6 @@ MediaManager* MediaManager::Get() {
// Prepare async shutdown
nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase = GetShutdownPhase();
class Blocker : public media::ShutdownBlocker {
public:
Blocker()
@ -2042,7 +2022,7 @@ MediaManager* MediaManager::Get() {
};
sSingleton->mShutdownBlocker = new Blocker();
nsresult rv = shutdownPhase->AddBlocker(
nsresult rv = media::GetShutdownBarrier()->AddBlocker(
sSingleton->mShutdownBlocker, NS_LITERAL_STRING(__FILE__), __LINE__,
NS_LITERAL_STRING("Media shutdown"));
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
@ -3651,8 +3631,8 @@ void MediaManager::Shutdown() {
mMediaThread->Stop();
}
// Remove async shutdown blocker
nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase = GetShutdownPhase();
shutdownPhase->RemoveBlocker(sSingleton->mShutdownBlocker);
media::GetShutdownBarrier()->RemoveBlocker(
sSingleton->mShutdownBlocker);
// we hold a ref to 'self' which is the same as sSingleton
sSingleton = nullptr;

Просмотреть файл

@ -3293,8 +3293,7 @@ MediaStreamGraph* MediaStreamGraph::GetInstance(
};
gMediaStreamGraphShutdownBlocker = new Blocker();
nsCOMPtr<nsIAsyncShutdownClient> barrier = media::GetShutdownBarrier();
nsresult rv = barrier->AddBlocker(
nsresult rv = media::GetShutdownBarrier()->AddBlocker(
gMediaStreamGraphShutdownBlocker, NS_LITERAL_STRING(__FILE__),
__LINE__, NS_LITERAL_STRING("MediaStreamGraph shutdown"));
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));

Просмотреть файл

@ -9,11 +9,11 @@
namespace mozilla {
namespace media {
already_AddRefed<nsIAsyncShutdownClient> GetShutdownBarrier() {
RefPtr<nsIAsyncShutdownClient> GetShutdownBarrier() {
nsCOMPtr<nsIAsyncShutdownService> svc = services::GetAsyncShutdown();
MOZ_RELEASE_ASSERT(svc);
nsCOMPtr<nsIAsyncShutdownClient> barrier;
RefPtr<nsIAsyncShutdownClient> barrier;
nsresult rv = svc->GetProfileBeforeChange(getter_AddRefs(barrier));
if (!barrier) {
// We are probably in a content process. We need to do cleanup at
@ -22,7 +22,7 @@ already_AddRefed<nsIAsyncShutdownClient> GetShutdownBarrier() {
}
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
MOZ_RELEASE_ASSERT(barrier);
return barrier.forget();
return barrier;
}
NS_IMPL_ISUPPORTS(ShutdownBlocker, nsIAsyncShutdownBlocker)

Просмотреть файл

@ -132,7 +132,7 @@ class Refcountable<UniquePtr<T>> : public UniquePtr<T> {
/* Async shutdown helpers
*/
already_AddRefed<nsIAsyncShutdownClient> GetShutdownBarrier();
RefPtr<nsIAsyncShutdownClient> GetShutdownBarrier();
class ShutdownBlocker : public nsIAsyncShutdownBlocker {
public:
@ -162,10 +162,7 @@ class ShutdownTicket final {
: mBlocker(aBlocker) {}
NS_INLINE_DECL_REFCOUNTING(ShutdownTicket)
private:
~ShutdownTicket() {
nsCOMPtr<nsIAsyncShutdownClient> barrier = GetShutdownBarrier();
barrier->RemoveBlocker(mBlocker);
}
~ShutdownTicket() { GetShutdownBarrier()->RemoveBlocker(mBlocker); }
nsCOMPtr<nsIAsyncShutdownBlocker> mBlocker;
};