Issue #2654 - Remove pre-allocated process manager.

Resolves #2654
This commit is contained in:
Moonchild 2024-11-19 13:18:31 +01:00 • committed by roytam1
commit 75d698133f
22 changed files with 16 additions and 879 deletions

View file

@ -144,7 +144,6 @@
#include "nsThreadUtils.h"
#include "nsToolkitCompsCID.h"
#include "nsWidgetsCID.h"
#include "PreallocatedProcessManager.h"
#include "ProcessPriorityManager.h"
#include "SandboxHal.h"
#include "ScreenManagerParent.h"
@ -493,25 +492,6 @@ static const char* sObserverTopics[] = {
"cacheservice:empty-cache",
};
// PreallocateAppProcess is called by the PreallocatedProcessManager.
// ContentParent then takes this process back within
// GetNewOrPreallocatedAppProcess.
/*static*/ already_AddRefed<ContentParent>
ContentParent::PreallocateAppProcess()
{
RefPtr<ContentParent> process =
new ContentParent(/* aOpener = */ nullptr,
/* isForBrowserElement = */ false,
/* isForPreallocated = */ true);
if (!process->LaunchSubprocess(PROCESS_PRIORITY_PREALLOC)) {
return nullptr;
}
process->Init();
return process.forget();
}
/*static*/ void
ContentParent::StartUp()
{
@ -533,9 +513,6 @@ ContentParent::StartUp()
BackgroundChild::Startup();
// Try to preallocate a process that we can transform into an app later.
PreallocatedProcessManager::AllocateAfterDelay();
sDisableUnsafeCPOWWarnings = PR_GetEnv("DISABLE_UNSAFE_CPOW_WARNINGS");
}
@ -640,23 +617,14 @@ ContentParent::GetNewOrUsedBrowserProcess(bool aForBrowserElement,
} while (currIdx != startIdx);
}
// Try to take and transform the preallocated process into browser.
RefPtr<ContentParent> p = PreallocatedProcessManager::Take();
if (p) {
p->TransformPreallocatedIntoBrowser(aOpener);
} else {
// Failed in using the preallocated process: fork from the chrome process.
p = new ContentParent(aOpener,
aForBrowserElement,
/* isForPreallocated = */ false);
RefPtr<ContentParent> p = new ContentParent(aOpener, aForBrowserElement);
if (!p->LaunchSubprocess(aPriority)) {
return nullptr;
}
p->Init();
if (!p->LaunchSubprocess(aPriority)) {
return nullptr;
}
p->Init();
p->mLargeAllocationProcess = aLargeAllocationProcess;
p->ForwardKnownInfo();
@ -711,12 +679,6 @@ ContentParent::SendAsyncUpdate(nsIWidget* aWidget)
}
#endif // defined(XP_WIN)
bool
ContentParent::PreallocatedProcessReady()
{
return true;
}
bool
ContentParent::RecvCreateChildProcess(const IPCTabContext& aContext,
const hal::ProcessPriority& aPriority,
@ -1124,15 +1086,6 @@ ContentParent::SetPriorityAndCheckIsAlive(ProcessPriority aPriority)
return true;
}
void
ContentParent::TransformPreallocatedIntoBrowser(ContentParent* aOpener)
{
// Reset mIsForBrowser and mOSPrivileges for browser.
mMetamorphosed = true;
mOpener = aOpener;
mIsForBrowser = true;
}
void
ContentParent::ShutDownProcess(ShutDownMethod aMethod)
{
@ -1683,20 +1636,14 @@ ContentParent::LaunchSubprocess(ProcessPriority aInitialPriority /* = PROCESS_PR
}
ContentParent::ContentParent(ContentParent* aOpener,
bool aIsForBrowser,
bool aIsForPreallocated)
bool aIsForBrowser)
: nsIContentParent()
, mOpener(aOpener)
, mIsForBrowser(aIsForBrowser)
, mIsPreallocated(aIsForPreallocated)
, mLargeAllocationProcess(false)
{
InitializeMembers(); // Perform common initialization.
// No more than one of aIsForBrowser, aIsForPreallocated should be
// true.
MOZ_ASSERT(aIsForBrowser + aIsForPreallocated <= 1);
mMetamorphosed = true;
// Insert ourselves into the global linked list of ContentParent objects.
@ -1806,11 +1753,6 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority,
}
}
if (gAppData) {
// Sending all information to content process.
Unused << SendAppInit();
}
nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance();
if (sheetService) {
// This looks like a lot of work, but in a normal browser session we just
@ -2110,17 +2052,6 @@ ContentParent::RecvGetShowPasswordSetting(bool* showPassword)
return true;
}
bool
ContentParent::RecvFirstIdle()
{
// When the ContentChild goes idle, it sends us a FirstIdle message
// which we use as a good time to prelaunch another process. If we
// prelaunch any sooner than this, then we'll be competing with the
// child process and slowing it down.
PreallocatedProcessManager::AllocateAfterDelay();
return true;
}
bool
ContentParent::RecvAudioChannelChangeDefVolChannel(const int32_t& aChannel,
const bool& aHidden)
@ -2511,19 +2442,11 @@ ContentParent::KillHard(const char* aReason)
otherProcessHandle, /*force=*/true));
}
bool
ContentParent::IsPreallocated() const
{
return mIsPreallocated;
}
void
ContentParent::FriendlyName(nsAString& aName, bool aAnonymize)
{
aName.Truncate();
if (IsPreallocated()) {
aName.AssignLiteral("(Preallocated)");
} else if (mIsForBrowser) {
if (mIsForBrowser) {
aName.AssignLiteral("Browser");
} else if (aAnonymize) {
aName.AssignLiteral("<anonymized-name>");