Bug 1336345. Part 2 - some code cleanup. r=gerald
MozReview-Commit-ID: 1XHkvz4aWxB
--- a/dom/media/MediaShutdownManager.cpp
+++ b/dom/media/MediaShutdownManager.cpp
@@ -14,18 +14,16 @@
namespace mozilla {
extern LazyLogModule gMediaDecoderLog;
#define DECODER_LOG(type, msg) MOZ_LOG(gMediaDecoderLog, type, msg)
NS_IMPL_ISUPPORTS(MediaShutdownManager, nsIAsyncShutdownBlocker)
MediaShutdownManager::MediaShutdownManager()
- : mIsObservingShutdown(false)
- , mIsDoingXPCOMShutDown(false)
{
MOZ_ASSERT(NS_IsMainThread());
}
MediaShutdownManager::~MediaShutdownManager()
{
MOZ_ASSERT(NS_IsMainThread());
}
@@ -83,46 +81,16 @@ MediaShutdownManager::InitStatics()
auto buf = new char[CAPACITY];
snprintf(buf, CAPACITY, "Failed to add shutdown blocker! rv=%x", uint32_t(rv));
MOZ_CRASH_ANNOTATE(buf);
MOZ_REALLY_CRASH();
}
}
void
-MediaShutdownManager::EnsureCorrectShutdownObserverState()
-{
- bool needShutdownObserver = mDecoders.Count() > 0;
- if (needShutdownObserver != mIsObservingShutdown) {
- mIsObservingShutdown = needShutdownObserver;
- if (mIsObservingShutdown) {
- nsresult rv = GetShutdownBarrier()->AddBlocker(
- this, NS_LITERAL_STRING(__FILE__), __LINE__,
- NS_LITERAL_STRING("MediaShutdownManager shutdown"));
- if (NS_FAILED(rv)) {
- // Leak the buffer on the heap to make sure that it lives long enough,
- // as MOZ_CRASH_ANNOTATE expects the pointer passed to it to live to
- // the end of the program.
- const size_t CAPACITY = 256;
- auto buf = new char[CAPACITY];
- snprintf(buf, CAPACITY, "Failed to add shutdown blocker! rv=%x", uint32_t(rv));
- MOZ_CRASH_ANNOTATE(buf);
- MOZ_REALLY_CRASH();
- }
- } else {
- GetShutdownBarrier()->RemoveBlocker(this);
- // Clear our singleton reference. This will probably delete
- // this instance, so don't deref |this| clearing sInstance.
- sInstance = nullptr;
- DECODER_LOG(LogLevel::Debug, ("MediaShutdownManager::BlockShutdown() end."));
- }
- }
-}
-
-void
MediaShutdownManager::RemoveBlocker()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mIsDoingXPCOMShutDown);
MOZ_ASSERT(mDecoders.Count() == 0);
GetShutdownBarrier()->RemoveBlocker(this);
// Clear our singleton reference. This will probably delete
// this instance, so don't deref |this| clearing sInstance.
--- a/dom/media/MediaShutdownManager.h
+++ b/dom/media/MediaShutdownManager.h
@@ -70,28 +70,21 @@ public:
void Unregister(MediaDecoder* aDecoder);
private:
MediaShutdownManager();
virtual ~MediaShutdownManager();
void RemoveBlocker();
- // Ensures we have a shutdown listener if we need one, and removes the
- // listener and destroys the singleton if we don't.
- void EnsureCorrectShutdownObserverState();
-
static StaticRefPtr<MediaShutdownManager> sInstance;
// References to the MediaDecoder. The decoders unregister themselves
// in their Shutdown() method, so we'll drop the reference naturally when
// we're shutting down (in the non xpcom-shutdown case).
nsTHashtable<nsRefPtrHashKey<MediaDecoder>> mDecoders;
- // True if we have an XPCOM shutdown observer.
- bool mIsObservingShutdown;
-
- bool mIsDoingXPCOMShutDown;
+ bool mIsDoingXPCOMShutDown = false;
};
} // namespace mozilla
#endif