Chromium Code Reviews| Index: content/browser/child_process_launcher_win.cc |
| diff --git a/content/browser/child_process_launcher_win.cc b/content/browser/child_process_launcher_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7c69f98efcf55dcf06416c13656a899a8fc17c74 |
| --- /dev/null |
| +++ b/content/browser/child_process_launcher_win.cc |
| @@ -0,0 +1,122 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/child_process_launcher.h" |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/metrics/field_trial.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/win/scoped_handle.h" |
| +#include "base/win/win_util.h" |
| +#include "content/common/sandbox_win.h" |
| +#include "content/public/common/result_codes.h" |
| +#include "content/public/common/sandbox_init.h" |
| +#include "content/public/common/sandboxed_process_launcher_delegate.h" |
| +#include "mojo/edk/embedder/named_platform_channel_pair.h" |
| +#include "mojo/edk/embedder/platform_channel_pair.h" |
| +#include "mojo/edk/embedder/scoped_platform_handle.h" |
| +#include "sandbox/win/src/sandbox_types.h" |
| + |
| +namespace content { |
| + |
| +void ChildProcessLauncher::Helper::BeforeLaunchOnClientThread() { |
| + DCHECK_CURRENTLY_ON(client_thread_id_); |
| +} |
| + |
| +mojo::edk::ScopedPlatformHandle |
| +ChildProcessLauncher::Helper::PrepareMojoPipeHandlesOnClientThread() { |
| + DCHECK_CURRENTLY_ON(client_thread_id_); |
| + |
| + if (!delegate_->ShouldLaunchElevated()) |
| + return mojo::edk::ScopedPlatformHandle(); |
| + |
| + mojo::edk::NamedPlatformChannelPair named_pair; |
| + named_pair.PrepareToPassClientHandleToChildProcess(command_line()); |
| + return named_pair.PassServerHandle(); |
| +} |
| + |
| +std::unique_ptr<FileMappedForLaunch> |
| +ChildProcessLauncher::Helper::GetFilesToMap() { |
| + return std::unique_ptr<FileMappedForLaunch>(); |
| +} |
| + |
| +bool ChildProcessLauncher::Helper::ShouldForkAsZygote() { |
| + return false; |
| +} |
| + |
| +ZygoteHandle ChildProcessLauncher::Helper::ForkAsZygote( |
| + std::unique_ptr<FileMappedForLaunch> files_to_register, |
| + base::Process* process) { |
| + NOTREACHED(); |
| + return nullptr; |
| +} |
| + |
| +void ChildProcessLauncher::Helper::BeforeLaunchOnLauncherThread( |
| + const FileMappedForLaunch& files_to_register, |
| + base::LaunchOptions* options) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| +} |
| + |
| +base::Process ChildProcessLauncher::Helper::LaunchProcessOnLauncherThread( |
| + const base::LaunchOptions& options, |
| + FileMappedForLaunch* files_to_register, |
| + bool* is_synchronous_launch, |
| + int* launch_result) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| + *is_synchronous_launch = true; |
| + if (delegate_->ShouldLaunchElevated()) { |
| + // When establishing a Mojo connection, the pipe path has already been added |
| + // to the command line. |
| + base::LaunchOptions win_options; |
| + win_options.start_hidden = true; |
| + return base::LaunchElevatedProcess(*command_line(), win_options); |
| + } |
| + base::HandlesToInheritVector handles; |
| + handles.push_back(mojo_client_handle().handle); |
| + base::FieldTrialList::AppendFieldTrialHandleIfNeeded(&handles); |
| + command_line()->AppendSwitchASCII( |
| + mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, |
| + base::UintToString(base::win::HandleToUint32(handles[0]))); |
| + base::Process process; |
| + *launch_result = |
| + StartSandboxedProcess(delegate_.get(), command_line(), handles, &process); |
| + // TODO: deal with the result. |
|
boliu
2017/01/13 19:00:56
is this already addressed?
Jay Civelli
2017/01/17 17:50:02
Yes, removed.
|
| + return process; |
|
boliu
2017/01/13 19:00:56
nit: extra space
Jay Civelli
2017/01/17 17:50:02
Done.
|
| +} |
| + |
| +void ChildProcessLauncher::Helper::AfterLaunchOnLauncherThread( |
| + const base::Process& process, |
| + const base::LaunchOptions& options) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| +} |
| + |
| +void ChildProcessLauncher::UpdateTerminationStatus(bool known_dead) { |
| + DCHECK(CalledOnValidThread()); |
| + termination_status_ = |
| + base::GetTerminationStatus(process_.Handle(), &exit_code_); |
| +} |
| + |
| +// static |
| +bool ChildProcessLauncher::TerminateProcess( |
| + const base::Process& process, int exit_code, bool wait) { |
| + return process.Terminate(exit_code, wait); |
| +} |
| + |
| +void ChildProcessLauncher::TerminateOnLauncherThread( |
| + ZygoteHandle zygote, base::Process process) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| + // Client has gone away, so just kill the process. Using exit code 0 means |
| + // that UMA won't treat this as a crash. |
| + process.Terminate(RESULT_CODE_NORMAL_EXIT, false); |
| +} |
| + |
| +// static |
| +void ChildProcessLauncher::SetProcessBackgroundedOnLauncherThread( |
| + base::Process process, bool background) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| + if (process.CanBackgroundProcesses()) |
| + process.SetProcessBackgrounded(background); |
| +} |
| + |
| +} // namespace content |