| Index: content/browser/child_process_launcher.cc
|
| diff --git a/content/browser/child_process_launcher.cc b/content/browser/child_process_launcher.cc
|
| index e497762aff8ebbd651e8467c6c0409ff7c8f8fe2..9bc7b374dfde9df24a9c9e5c2602483f13c41402 100644
|
| --- a/content/browser/child_process_launcher.cc
|
| +++ b/content/browser/child_process_launcher.cc
|
| @@ -339,19 +339,23 @@ class ChildProcessLauncher::Context
|
| if (!process_.handle())
|
| return;
|
|
|
| - if (!terminate_child_on_shutdown_)
|
| - return;
|
| -
|
| - // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So
|
| - // don't this on the UI/IO threads.
|
| - BrowserThread::PostTask(
|
| - BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
|
| - base::Bind(
|
| - &Context::TerminateInternal,
|
| + if (CommandLine::ForCurrentProcess()->
|
| + HasSwitch(switches::kWaitForChildrenBeforeExiting))
|
| + // When --wait-for-children-before-exiting is provided on the command
|
| + // line, we want the UI thread to wait for the zygote to exit before
|
| + // proceeding with the rest of the shut down.
|
| + TerminateAndWaitForExit(zygote_, process_.handle());
|
| + else
|
| + // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So
|
| + // don't this on the UI/IO threads.
|
| + BrowserThread::PostTask(
|
| + BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
|
| + base::Bind(
|
| + &Context::TerminateInternal,
|
| #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
|
| - zygote_,
|
| + zygote_,
|
| #endif
|
| - process_.handle()));
|
| + process_.handle()));
|
| process_.set_handle(base::kNullProcessHandle);
|
| }
|
|
|
| @@ -361,6 +365,20 @@ class ChildProcessLauncher::Context
|
| process.SetProcessBackgrounded(background);
|
| }
|
|
|
| + static void TerminateAndWaitForExit(
|
| + bool zygote,
|
| + base::ProcessHandle handle) {
|
| + base::Process process(handle);
|
| + if (zygote) {
|
| + while(ZygoteHostImpl::GetInstance()->GetTerminationStatus(
|
| + handle,
|
| + false,
|
| + NULL) == base::TERMINATION_STATUS_STILL_RUNNING)
|
| + sleep(2);
|
| + }
|
| + process.Close();
|
| + }
|
| +
|
| static void TerminateInternal(
|
| #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
|
| bool zygote,
|
|
|