Bug 1340665 - Fix warnings on shutdown. r=billm

The code to make a ValidatingDispatcher break cycles when we're done with it
assumes that XPCOM is still up and running. This isn't the case during
shutdown. When XPCOM shuts down, we should avoid do_GetMainThread.

MozReview-Commit-ID: 5Gpko9FbFxl

--HG--
extra : rebase_source : 8c00c83b06e890802ade0d6df2a93f64dc8ea376
This commit is contained in:
Blake Kaplan 2017-03-10 17:55:35 -08:00
Родитель b46bfc918b
Коммит b48fcd2501
4 изменённых файлов: 10 добавлений и 5 удалений

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

@ -167,7 +167,7 @@ TabGroup::Leave(nsPIDOMWindowOuter* aWindow)
// out after the last window leaves.
if (!mIsChrome && mWindows.IsEmpty()) {
mLastWindowLeft = true;
Shutdown();
Shutdown(false);
}
}

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

@ -152,6 +152,7 @@ nsIEventTarget*
ValidatingDispatcher::EventTargetFor(TaskCategory aCategory) const
{
MOZ_ASSERT(aCategory != TaskCategory::Count);
MOZ_ASSERT(mEventTargets[size_t(aCategory)]);
return mEventTargets[size_t(aCategory)];
}
@ -160,6 +161,7 @@ ValidatingDispatcher::AbstractMainThreadForImpl(TaskCategory aCategory)
{
MOZ_RELEASE_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aCategory != TaskCategory::Count);
MOZ_ASSERT(mEventTargets[size_t(aCategory)]);
if (!mAbstractThreads[size_t(aCategory)]) {
mAbstractThreads[size_t(aCategory)] =
@ -187,14 +189,14 @@ ValidatingDispatcher::CreateEventTargets(bool aNeedValidation)
}
void
ValidatingDispatcher::Shutdown()
ValidatingDispatcher::Shutdown(bool aXPCOMShutdown)
{
// There is a RefPtr cycle TabGroup -> DispatcherEventTarget -> TabGroup. To
// avoid leaks, we need to break the chain somewhere. We shouldn't be using
// the ThrottledEventQueue for this TabGroup when no windows belong to it,
// so it's safe to null out the queue here.
for (size_t i = 0; i < size_t(TaskCategory::Count); i++) {
mEventTargets[i] = do_GetMainThread();
mEventTargets[i] = aXPCOMShutdown ? nullptr : do_GetMainThread();
mAbstractThreads[i] = nullptr;
}
}

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

@ -112,7 +112,10 @@ protected:
already_AddRefed<nsIRunnable>&& aRunnable);
void CreateEventTargets(bool aNeedValidation);
void Shutdown();
// Shuts down this dispatcher. If aXPCOMShutdown is true, invalidates this
// dispatcher.
void Shutdown(bool aXPCOMShutdown);
enum ValidationType {
StartValidation,

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

@ -53,7 +53,7 @@ SystemGroupImpl::InitStatic()
/* static */ void
SystemGroupImpl::ShutdownStatic()
{
sSingleton->Shutdown();
sSingleton->Shutdown(true);
sSingleton = nullptr;
}