Bug 1663747: Part 1 - Fix sCurrentShutdownPhase and add PastShutdownPhase() API. r=nika

Differential Revision: https://phabricator.services.mozilla.com/D89809
This commit is contained in:
Kris Maglione 2020-09-22 17:13:27 +00:00
Родитель 32f5a61f56
Коммит afcc0476d6
6 изменённых файлов: 43 добавлений и 7 удалений

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

@ -2565,6 +2565,14 @@ ContentParent::~ContentParent() {
}
bool ContentParent::InitInternal(ProcessPriority aInitialPriority) {
// We can't access the locale service after shutdown has started. Since we
// can't init the process without it, and since we're going to be canceling
// whatever load attempt that initiated this process creation anyway, just
// bail out now if shutdown has already started.
if (PastShutdownPhase(ShutdownPhase::Shutdown)) {
return false;
}
XPCOMInitData xpcomInit;
MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug,

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

@ -237,7 +237,10 @@ void VRServiceHost::SendPuppetSubmitToVRProcess(
}
void VRServiceHost::PuppetReset() {
if (!mVRProcessEnabled) {
// If we're already into ShutdownFinal, the VRPuppetCommandBuffer instance
// will have been cleared, so don't try to access it after that point.
if (!mVRProcessEnabled &&
!(NS_IsMainThread() && PastShutdownPhase(ShutdownPhase::ShutdownFinal))) {
// Puppet is running in this process, tell it to reset directly.
VRPuppetCommandBuffer::Get().Reset();
}

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

@ -26,6 +26,7 @@
#include "nsSimpleEnumerator.h"
#include "nsStringStream.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/URLPreloader.h"
#include "mozilla/ResultExtensions.h"
@ -483,6 +484,19 @@ nsresult SharedStringBundle::LoadProperties() {
return NS_OK;
}
MOZ_ASSERT(NS_IsMainThread(),
"String bundles must be initialized on the main thread "
"before they may be used off-main-thread");
// We can't access the locale service after shutdown has started, which
// means we can't attempt to load chrome: locale resources (which most of
// our string bundles come from). Since shared string bundles won't be
// useful after shutdown has started anyway (and we almost certainly got
// here from a pre-load attempt in an idle task), just bail out.
if (PastShutdownPhase(ShutdownPhase::Shutdown)) {
return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
}
// We should only populate shared memory string bundles in the parent
// process. Instances in the child process should always be instantiated
// with a shared memory file descriptor sent from the parent.

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

@ -16,8 +16,7 @@ ShutdownPhase sCurrentShutdownPhase = ShutdownPhase::NotInShutdown;
void InsertIntoShutdownList(ShutdownObserver* aObserver, ShutdownPhase aPhase) {
// Adding a ClearOnShutdown for a "past" phase is an error.
if (!(static_cast<size_t>(sCurrentShutdownPhase) <
static_cast<size_t>(aPhase))) {
if (PastShutdownPhase(aPhase)) {
MOZ_ASSERT(false, "ClearOnShutdown for phase that already was cleared");
aObserver->Shutdown();
delete aObserver;
@ -39,8 +38,11 @@ void KillClearOnShutdown(ShutdownPhase aPhase) {
MOZ_ASSERT(NS_IsMainThread());
// Shutdown only goes one direction...
MOZ_ASSERT(static_cast<size_t>(sCurrentShutdownPhase) <
static_cast<size_t>(aPhase));
MOZ_ASSERT(!PastShutdownPhase(aPhase));
// Set the phase before notifying observers to make sure that they can't run
// any code which isn't allowed to run after the start of this phase.
sCurrentShutdownPhase = aPhase;
// It's impossible to add an entry for a "past" phase; this is blocked in
// ClearOnShutdown, but clear them out anyways in case there are phases

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

@ -129,6 +129,13 @@ inline void RunOnShutdown(CallableT&& aCallable,
new FunctionInvoker(std::forward<CallableT>(aCallable)), aPhase);
}
inline bool PastShutdownPhase(ShutdownPhase aPhase) {
MOZ_ASSERT(NS_IsMainThread());
return size_t(ClearOnShutdown_Internal::sCurrentShutdownPhase) >=
size_t(aPhase);
}
// Called when XPCOM is shutting down, after all shutdown notifications have
// been sent and after all threads' event loops have been purged.
void KillClearOnShutdown(ShutdownPhase aPhase);

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

@ -261,8 +261,10 @@ class ThrottledEventQueue::Inner final : public nsISupports {
static already_AddRefed<Inner> Create(nsISerialEventTarget* aBaseTarget,
const char* aName, uint32_t aPriority) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(ClearOnShutdown_Internal::sCurrentShutdownPhase ==
ShutdownPhase::NotInShutdown);
// FIXME: This assertion only worked when `sCurrentShutdownPhase` was not
// being updated.
// MOZ_ASSERT(ClearOnShutdown_Internal::sCurrentShutdownPhase ==
// ShutdownPhase::NotInShutdown);
RefPtr<Inner> ref = new Inner(aBaseTarget, aName, aPriority);
return ref.forget();