mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1795964 - Replace PreallocatedProcessManagerImpl::sShutdown with AppShutdown::IsInOrBeyond and anticipate blocking to AppShutdownConfirmed. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D160051
This commit is contained in:
parent
0617b49417
commit
0adb93379a
@ -6,6 +6,7 @@
|
||||
|
||||
#include "mozilla/PreallocatedProcessManager.h"
|
||||
|
||||
#include "mozilla/AppShutdown.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/ProfilerMarkers.h"
|
||||
@ -58,6 +59,7 @@ class PreallocatedProcessManagerImpl final : public nsIObserver {
|
||||
|
||||
void Init();
|
||||
|
||||
bool CanTake();
|
||||
bool CanAllocate();
|
||||
void AllocateAfterDelay(bool aStartup = false);
|
||||
void AllocateOnIdle();
|
||||
@ -69,9 +71,11 @@ class PreallocatedProcessManagerImpl final : public nsIObserver {
|
||||
void CloseProcesses();
|
||||
|
||||
bool IsEmpty() const { return mPreallocatedProcesses.IsEmpty(); }
|
||||
static bool IsShutdown() {
|
||||
return AppShutdown::IsInOrBeyond(ShutdownPhase::AppShutdownConfirmed);
|
||||
}
|
||||
|
||||
bool mEnabled;
|
||||
static bool sShutdown;
|
||||
uint32_t mNumberPreallocs;
|
||||
AutoTArray<RefPtr<ContentParent>, 3> mPreallocatedProcesses;
|
||||
// Even if we have multiple PreallocatedProcessManagerImpls, we'll have
|
||||
@ -82,7 +86,6 @@ class PreallocatedProcessManagerImpl final : public nsIObserver {
|
||||
|
||||
/* static */
|
||||
uint32_t PreallocatedProcessManagerImpl::sNumBlockers = 0;
|
||||
bool PreallocatedProcessManagerImpl::sShutdown = false;
|
||||
|
||||
const char* const PreallocatedProcessManagerImpl::kObserverTopics[] = {
|
||||
"memory-pressure",
|
||||
@ -154,11 +157,6 @@ PreallocatedProcessManagerImpl::Observe(nsISupports* aSubject,
|
||||
for (auto topic : kObserverTopics) {
|
||||
os->RemoveObserver(this, topic);
|
||||
}
|
||||
// Let's prevent any new preallocated processes from starting. ContentParent
|
||||
// will handle the shutdown of the existing process and the
|
||||
// mPreallocatedProcesses reference will be cleared by the ClearOnShutdown
|
||||
// of the manager singleton.
|
||||
sShutdown = true;
|
||||
} else if (!strcmp("memory-pressure", aTopic)) {
|
||||
CloseProcesses();
|
||||
} else {
|
||||
@ -196,7 +194,7 @@ void PreallocatedProcessManagerImpl::RereadPrefs() {
|
||||
|
||||
already_AddRefed<ContentParent> PreallocatedProcessManagerImpl::Take(
|
||||
const nsACString& aRemoteType) {
|
||||
if (!mEnabled || sShutdown) {
|
||||
if (!CanTake()) {
|
||||
return nullptr;
|
||||
}
|
||||
RefPtr<ContentParent> process;
|
||||
@ -272,9 +270,13 @@ void PreallocatedProcessManagerImpl::RemoveBlocker(ContentParent* aParent) {
|
||||
}
|
||||
}
|
||||
|
||||
bool PreallocatedProcessManagerImpl::CanTake() {
|
||||
return mEnabled && !IsShutdown();
|
||||
}
|
||||
|
||||
bool PreallocatedProcessManagerImpl::CanAllocate() {
|
||||
return mEnabled && sNumBlockers == 0 &&
|
||||
mPreallocatedProcesses.Length() < mNumberPreallocs && !sShutdown &&
|
||||
mPreallocatedProcesses.Length() < mNumberPreallocs && !IsShutdown() &&
|
||||
(FissionAutostart() ||
|
||||
!ContentParent::IsMaxProcessCountReached(DEFAULT_REMOTE_TYPE));
|
||||
}
|
||||
@ -310,7 +312,7 @@ void PreallocatedProcessManagerImpl::AllocateNow() {
|
||||
MOZ_LOG(ContentParent::GetLog(), LogLevel::Debug,
|
||||
("Trying to start process now"));
|
||||
if (!CanAllocate()) {
|
||||
if (mEnabled && !sShutdown && IsEmpty() && sNumBlockers > 0) {
|
||||
if (mEnabled && !IsShutdown() && IsEmpty() && sNumBlockers > 0) {
|
||||
// If it's too early to allocate a process let's retry later.
|
||||
AllocateAfterDelay();
|
||||
}
|
||||
@ -343,7 +345,7 @@ void PreallocatedProcessManagerImpl::AllocateNow() {
|
||||
if (mPreallocatedProcesses.Length() < mNumberPreallocs) {
|
||||
AllocateOnIdle();
|
||||
}
|
||||
} else if (!mEnabled || sShutdown) {
|
||||
} else if (!mEnabled || IsShutdown()) {
|
||||
// if this has a remote type set, it's been allocated for use
|
||||
// already
|
||||
if (process->mRemoteType == PREALLOC_REMOTE_TYPE) {
|
||||
@ -387,7 +389,7 @@ void PreallocatedProcessManagerImpl::CloseProcesses() {
|
||||
|
||||
inline PreallocatedProcessManagerImpl*
|
||||
PreallocatedProcessManager::GetPPMImpl() {
|
||||
if (PreallocatedProcessManagerImpl::sShutdown) {
|
||||
if (PreallocatedProcessManagerImpl::IsShutdown()) {
|
||||
return nullptr;
|
||||
}
|
||||
return PreallocatedProcessManagerImpl::Singleton();
|
||||
|
Loading…
Reference in New Issue
Block a user