Bug 1366930 - Correct error handling in mozilla::MediaShutdownManager::InitStatics.
Resetting sInstance in MediaShutdownManager::InitStatics() will cause
MediaShutdownManager::Instance().Register() to crash immediately without
a chance to handle the error in Register().
Instead, we keep an error code to know whether to bail out in Register().
MozReview-Commit-ID: EGqL1407Gh
--- a/dom/media/MediaShutdownManager.cpp
+++ b/dom/media/MediaShutdownManager.cpp
@@ -73,17 +73,17 @@ MediaShutdownManager::InitStatics()
sInitDone = true;
sInstance = new MediaShutdownManager();
nsresult rv = GetShutdownBarrier()->AddBlocker(
sInstance, NS_LITERAL_STRING(__FILE__), __LINE__,
NS_LITERAL_STRING("MediaShutdownManager shutdown"));
if (NS_FAILED(rv)) {
LOGW("Failed to add shutdown blocker! rv=%x", uint32_t(rv));
- sInstance = nullptr;
+ sInstance->mError = rv;
}
}
void
MediaShutdownManager::RemoveBlocker()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mIsDoingXPCOMShutDown);
@@ -94,17 +94,17 @@ MediaShutdownManager::RemoveBlocker()
sInstance = nullptr;
DECODER_LOG(LogLevel::Debug, ("MediaShutdownManager::BlockShutdown() end."));
}
nsresult
MediaShutdownManager::Register(MediaDecoder* aDecoder)
{
MOZ_ASSERT(NS_IsMainThread());
- if (!sInstance) {
+ if (NS_FAILED(mError)) {
return NS_ERROR_NOT_INITIALIZED;
}
if (mIsDoingXPCOMShutDown) {
return NS_ERROR_ABORT;
}
// Don't call Register() after you've Unregistered() all the decoders,
// that's not going to work.
MOZ_ASSERT(!mDecoders.Contains(aDecoder));
--- a/dom/media/MediaShutdownManager.h
+++ b/dom/media/MediaShutdownManager.h
@@ -78,13 +78,14 @@ private:
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;
bool mIsDoingXPCOMShutDown = false;
+ nsresult mError = NS_OK;
};
} // namespace mozilla
#endif