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; 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 { namespace mozilla {
#ifdef LOG #ifdef LOG
@ -2025,8 +2007,6 @@ MediaManager* MediaManager::Get() {
// Prepare async shutdown // Prepare async shutdown
nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase = GetShutdownPhase();
class Blocker : public media::ShutdownBlocker { class Blocker : public media::ShutdownBlocker {
public: public:
Blocker() Blocker()
@ -2042,7 +2022,7 @@ MediaManager* MediaManager::Get() {
}; };
sSingleton->mShutdownBlocker = new Blocker(); sSingleton->mShutdownBlocker = new Blocker();
nsresult rv = shutdownPhase->AddBlocker( nsresult rv = media::GetShutdownBarrier()->AddBlocker(
sSingleton->mShutdownBlocker, NS_LITERAL_STRING(__FILE__), __LINE__, sSingleton->mShutdownBlocker, NS_LITERAL_STRING(__FILE__), __LINE__,
NS_LITERAL_STRING("Media shutdown")); NS_LITERAL_STRING("Media shutdown"));
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv)); MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
@ -3651,8 +3631,8 @@ void MediaManager::Shutdown() {
mMediaThread->Stop(); mMediaThread->Stop();
} }
// Remove async shutdown blocker // Remove async shutdown blocker
nsCOMPtr<nsIAsyncShutdownClient> shutdownPhase = GetShutdownPhase(); media::GetShutdownBarrier()->RemoveBlocker(
shutdownPhase->RemoveBlocker(sSingleton->mShutdownBlocker); sSingleton->mShutdownBlocker);
// we hold a ref to 'self' which is the same as sSingleton // we hold a ref to 'self' which is the same as sSingleton
sSingleton = nullptr; sSingleton = nullptr;

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

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

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

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

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

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