Chromium Code Reviews| Index: content/browser/child_process_launcher.cc |
| diff --git a/content/browser/child_process_launcher.cc b/content/browser/child_process_launcher.cc |
| index c705b7db4972e4b339d5a84473f90738a63d139a..a02d05e7329ec47fbaae02df9b7ca5606898f568 100644 |
| --- a/content/browser/child_process_launcher.cc |
| +++ b/content/browser/child_process_launcher.cc |
| @@ -39,6 +39,7 @@ |
| #elif defined(OS_POSIX) |
| #include "base/memory/singleton.h" |
| #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
| +#include "content/browser/zygote_host/zygote_communication_linux.h" |
| #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
| #include "content/common/child_process_sandbox_support_impl_linux.h" |
| #endif |
| @@ -53,7 +54,7 @@ namespace content { |
| namespace { |
| -typedef base::Callback<void(bool, |
| +typedef base::Callback<void(ZygoteHandle, |
| #if defined(OS_ANDROID) |
| base::ScopedFD, |
| #endif |
| @@ -87,7 +88,7 @@ void OnChildProcessStartedAndroid(const NotifyCallback& callback, |
| base::Bind(&RecordHistogramsOnLauncherThread, launch_time)); |
| base::Closure callback_on_client_thread( |
| - base::Bind(callback, false, base::Passed(&ipcfd), |
| + base::Bind(callback, ZygoteHandle(), base::Passed(&ipcfd), |
| base::Passed(base::Process(handle)))); |
| if (BrowserThread::CurrentlyOn(client_thread_id)) { |
| callback_on_client_thread.Run(); |
| @@ -108,15 +109,15 @@ void LaunchOnLauncherThread(const NotifyCallback& callback, |
| base::CommandLine* cmd_line) { |
| DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); |
| +#if !defined(OS_ANDROID) |
| + ZygoteHandle zygote; |
| +#endif |
| #if defined(OS_WIN) |
| - bool use_zygote = false; |
| bool launch_elevated = delegate->ShouldLaunchElevated(); |
| #elif defined(OS_MACOSX) |
| - bool use_zygote = false; |
| base::EnvironmentMap env = delegate->GetEnvironment(); |
| base::ScopedFD ipcfd = delegate->TakeIpcFd(); |
| #elif defined(OS_POSIX) && !defined(OS_ANDROID) |
| - bool use_zygote = delegate->ShouldUseZygote(); |
| base::EnvironmentMap env = delegate->GetEnvironment(); |
| base::ScopedFD ipcfd = delegate->TakeIpcFd(); |
| #endif |
| @@ -199,8 +200,15 @@ void LaunchOnLauncherThread(const NotifyCallback& callback, |
| // child termination. |
| #if !defined(OS_MACOSX) |
| - if (use_zygote) { |
| - base::ProcessHandle handle = ZygoteHostImpl::GetInstance()->ForkRequest( |
| + zygote = nullptr; |
|
mdempsky
2015/12/22 21:21:33
Hm, so if you use
using ZygoteHandle = std::n
Greg K
2016/01/05 21:42:13
Done.
|
| + ZygoteHandle* zygote_handle = delegate->GetZygote(); |
| + if (zygote_handle) { |
| + if (*zygote_handle == nullptr) { |
|
mdempsky
2015/12/22 21:21:33
I'd suggest adding a comment that mentions we're r
Greg K
2016/01/05 21:42:13
Done.
|
| + *zygote_handle = new ZygoteCommunication(); |
| + (*zygote_handle)->Init(); |
| + } |
| + zygote = *zygote_handle; |
| + base::ProcessHandle handle = zygote->ForkRequest( |
| cmd_line->argv(), std::move(files_to_register), process_type); |
| process = base::Process(handle); |
| } else |
| @@ -282,13 +290,11 @@ void LaunchOnLauncherThread(const NotifyCallback& callback, |
| begin_launch_time); |
| } |
| BrowserThread::PostTask(client_thread_id, FROM_HERE, |
| - base::Bind(callback, |
| - use_zygote, |
| - base::Passed(&process))); |
| + base::Bind(callback, zygote, base::Passed(&process))); |
| #endif // !defined(OS_ANDROID) |
| } |
| -void TerminateOnLauncherThread(bool zygote, base::Process process) { |
| +void TerminateOnLauncherThread(ZygoteHandle zygote, base::Process process) { |
| DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| #if defined(OS_ANDROID) |
| VLOG(1) << "ChromeProcess: Stopping process with handle " |
| @@ -304,7 +310,7 @@ void TerminateOnLauncherThread(bool zygote, base::Process process) { |
| if (zygote) { |
| // If the renderer was created via a zygote, we have to proxy the reaping |
| // through the zygote process. |
| - ZygoteHostImpl::GetInstance()->EnsureProcessTerminated(process.Handle()); |
| + zygote->EnsureProcessTerminated(process.Handle()); |
| } else |
| #endif // !OS_MACOSX |
| base::EnsureProcessTerminated(std::move(process)); |
| @@ -334,7 +340,7 @@ ChildProcessLauncher::ChildProcessLauncher( |
| : client_(client), |
| termination_status_(base::TERMINATION_STATUS_NORMAL_TERMINATION), |
| exit_code_(RESULT_CODE_NORMAL_EXIT), |
| - zygote_(false), |
| + zygote_(), |
|
mdempsky
2015/12/22 21:21:33
(And explicitly initialize to nullptr here if you
Greg K
2016/01/05 21:42:13
Done.
|
| starting_(true), |
| #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ |
| defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ |
| @@ -404,8 +410,8 @@ void ChildProcessLauncher::UpdateTerminationStatus(bool known_dead) { |
| DCHECK(CalledOnValidThread()); |
| #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| if (zygote_) { |
| - termination_status_ = ZygoteHostImpl::GetInstance()-> |
| - GetTerminationStatus(process_.Handle(), known_dead, &exit_code_); |
| + termination_status_ = zygote_->GetTerminationStatus( |
| + process_.Handle(), known_dead, &exit_code_); |
| } else if (known_dead) { |
| termination_status_ = |
| base::GetKnownDeadTerminationStatus(process_.Handle(), &exit_code_); |
| @@ -438,7 +444,7 @@ void ChildProcessLauncher::SetProcessBackgrounded(bool background) { |
| void ChildProcessLauncher::DidLaunch( |
| base::WeakPtr<ChildProcessLauncher> instance, |
| bool terminate_on_shutdown, |
| - bool zygote, |
| + ZygoteHandle zygote, |
| #if defined(OS_ANDROID) |
| base::ScopedFD ipcfd, |
| #endif |
| @@ -463,12 +469,11 @@ void ChildProcessLauncher::DidLaunch( |
| } |
| } |
| -void ChildProcessLauncher::Notify( |
| - bool zygote, |
| +void ChildProcessLauncher::Notify(ZygoteHandle zygote, |
| #if defined(OS_ANDROID) |
| - base::ScopedFD ipcfd, |
| + base::ScopedFD ipcfd, |
| #endif |
| - base::Process process) { |
| + base::Process process) { |
| DCHECK(CalledOnValidThread()); |
| starting_ = false; |
| process_ = std::move(process); |