Skip to content

Commit

Permalink
Bug 1146874 Part 3: Add LaunchSubprocess function to ContentParent to…
Browse files Browse the repository at this point in the history
… remove fallible code from constructor. r=billm
  • Loading branch information
bobowen committed May 11, 2015
1 parent 00483a1 commit 4870b4d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 30 deletions.
84 changes: 56 additions & 28 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,12 @@ ContentParent::RunNuwaProcess()
/* aOpener = */ nullptr,
/* aIsForBrowser = */ false,
/* aIsForPreallocated = */ true,
PROCESS_PRIORITY_BACKGROUND,
/* aIsNuwaProcess = */ true);

if (!nuwaProcess->LaunchSubprocess(PROCESS_PRIORITY_BACKGROUND)) {
return nullptr;
}

nuwaProcess->Init();
#ifdef MOZ_NUWA_PROCESS
sNuwaPid = nuwaProcess->Pid();
Expand All @@ -699,8 +703,12 @@ ContentParent::PreallocateAppProcess()
new ContentParent(/* app = */ nullptr,
/* aOpener = */ nullptr,
/* isForBrowserElement = */ false,
/* isForPreallocated = */ true,
PROCESS_PRIORITY_PREALLOC);
/* isForPreallocated = */ true);

if (!process->LaunchSubprocess(PROCESS_PRIORITY_PREALLOC)) {
return nullptr;
}

process->Init();
return process.forget();
}
Expand Down Expand Up @@ -743,8 +751,12 @@ ContentParent::GetNewOrPreallocatedAppProcess(mozIApplication* aApp,
process = new ContentParent(aApp,
/* aOpener = */ aOpener,
/* isForBrowserElement = */ false,
/* isForPreallocated = */ false,
aInitialPriority);
/* isForPreallocated = */ false);

if (!process->LaunchSubprocess(aInitialPriority)) {
return nullptr;
}

process->Init();
process->ForwardKnownInfo();

Expand Down Expand Up @@ -888,8 +900,12 @@ ContentParent::GetNewOrUsedBrowserProcess(bool aForBrowserElement,
p = new ContentParent(/* app = */ nullptr,
aOpener,
aForBrowserElement,
/* isForPreallocated = */ false,
aPriority);
/* isForPreallocated = */ false);

if (!p->LaunchSubprocess(aPriority)) {
return nullptr;
}

p->Init();
}
p->ForwardKnownInfo();
Expand Down Expand Up @@ -1158,6 +1174,9 @@ ContentParent::CreateBrowserOrApp(const TabContext& aContext,
constructorSender =
GetNewOrUsedBrowserProcess(aContext.IsBrowserElement(),
initialPriority);
if (!constructorSender) {
return nullptr;
}
}
tabId = AllocateTabId(openerTabId,
aContext.AsIPCTabContext(),
Expand Down Expand Up @@ -2189,11 +2208,40 @@ ContentParent::InitializeMembers()
mHangMonitorActor = nullptr;
}

bool
ContentParent::LaunchSubprocess(ProcessPriority aInitialPriority /* = PROCESS_PRIORITY_FOREGROUND */)
{
std::vector<std::string> extraArgs;
if (mIsNuwaProcess) {
extraArgs.push_back("-nuwa");
}

if (!mSubprocess->LaunchAndWaitForProcessHandle(extraArgs)) {
MarkAsDead();
return false;
}

Open(mSubprocess->GetChannel(),
base::GetProcId(mSubprocess->GetChildProcessHandle()));

InitInternal(aInitialPriority,
true, /* Setup off-main thread compositing */
true /* Send registered chrome */);

ContentProcessManager::GetSingleton()->AddContentProcess(this);

ProcessHangMonitor::AddProcess(this);

// Set a reply timeout for CPOWs.
SetReplyTimeoutMs(Preferences::GetInt("dom.ipc.cpow.timeout", 0));

return true;
}

ContentParent::ContentParent(mozIApplication* aApp,
ContentParent* aOpener,
bool aIsForBrowser,
bool aIsForPreallocated,
ProcessPriority aInitialPriority /* = PROCESS_PRIORITY_FOREGROUND */,
bool aIsNuwaProcess /* = false */)
: nsIContentParent()
, mOpener(aOpener)
Expand Down Expand Up @@ -2247,26 +2295,6 @@ ContentParent::ContentParent(mozIApplication* aApp,
mSubprocess = new GeckoChildProcessHost(GeckoProcessType_Content, privs);

IToplevelProtocol::SetTransport(mSubprocess->GetChannel());

std::vector<std::string> extraArgs;
if (aIsNuwaProcess) {
extraArgs.push_back("-nuwa");
}
mSubprocess->LaunchAndWaitForProcessHandle(extraArgs);

Open(mSubprocess->GetChannel(),
base::GetProcId(mSubprocess->GetChildProcessHandle()));

InitInternal(aInitialPriority,
true, /* Setup off-main thread compositing */
true /* Send registered chrome */);

ContentProcessManager::GetSingleton()->AddContentProcess(this);

ProcessHangMonitor::AddProcess(this);

// Set a reply timeout for CPOWs.
SetReplyTimeoutMs(Preferences::GetInt("dom.ipc.cpow.timeout", 0));
}

#ifdef MOZ_NUWA_PROCESS
Expand Down
7 changes: 5 additions & 2 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ class ContentParent final : public PContentParent
ContentParent* aOpener,
bool aIsForBrowser,
bool aIsForPreallocated,
hal::ProcessPriority aInitialPriority = hal::PROCESS_PRIORITY_FOREGROUND,
bool aIsNuwaProcess = false);

#ifdef MOZ_NUWA_PROCESS
Expand All @@ -446,7 +445,11 @@ class ContentParent final : public PContentParent
// The common initialization for the constructors.
void InitializeMembers();

// The common initialization logic shared by all constuctors.
// Launch the subprocess and associated initialization.
// Returns false if the process fails to start.
bool LaunchSubprocess(hal::ProcessPriority aInitialPriority = hal::PROCESS_PRIORITY_FOREGROUND);

// Common initialization after sub process launch or adoption.
void InitInternal(ProcessPriority aPriority,
bool aSetupOffMainThreadCompositing,
bool aSendRegisteredChrome);
Expand Down

0 comments on commit 4870b4d

Please sign in to comment.