Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/child_process_launcher.h" | |
| 6 | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/metrics/field_trial.h" | |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 #include "base/win/scoped_handle.h" | |
| 11 #include "base/win/win_util.h" | |
| 12 #include "content/common/sandbox_win.h" | |
| 13 #include "content/public/common/result_codes.h" | |
| 14 #include "content/public/common/sandbox_init.h" | |
| 15 #include "content/public/common/sandboxed_process_launcher_delegate.h" | |
| 16 #include "mojo/edk/embedder/named_platform_channel_pair.h" | |
| 17 #include "mojo/edk/embedder/platform_channel_pair.h" | |
| 18 #include "mojo/edk/embedder/scoped_platform_handle.h" | |
| 19 #include "sandbox/win/src/sandbox_types.h" | |
| 20 | |
| 21 namespace content { | |
| 22 | |
| 23 void ChildProcessLauncher::Helper::BeforeLaunchOnClientThread() { | |
| 24 DCHECK_CURRENTLY_ON(client_thread_id_); | |
| 25 } | |
| 26 | |
| 27 mojo::edk::ScopedPlatformHandle | |
| 28 ChildProcessLauncher::Helper::PrepareMojoPipeHandlesOnClientThread() { | |
| 29 DCHECK_CURRENTLY_ON(client_thread_id_); | |
| 30 | |
| 31 if (!delegate_->ShouldLaunchElevated()) | |
| 32 return mojo::edk::ScopedPlatformHandle(); | |
| 33 | |
| 34 mojo::edk::NamedPlatformChannelPair named_pair; | |
| 35 named_pair.PrepareToPassClientHandleToChildProcess(command_line()); | |
| 36 return named_pair.PassServerHandle(); | |
| 37 } | |
| 38 | |
| 39 std::unique_ptr<FileMappedForLaunch> | |
| 40 ChildProcessLauncher::Helper::GetFilesToMap() { | |
| 41 return std::unique_ptr<FileMappedForLaunch>(); | |
| 42 } | |
| 43 | |
| 44 bool ChildProcessLauncher::Helper::ShouldForkAsZygote() { | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 ZygoteHandle ChildProcessLauncher::Helper::ForkAsZygote( | |
| 49 std::unique_ptr<FileMappedForLaunch> files_to_register, | |
| 50 base::Process* process) { | |
| 51 NOTREACHED(); | |
| 52 return nullptr; | |
| 53 } | |
| 54 | |
| 55 void ChildProcessLauncher::Helper::BeforeLaunchOnLauncherThread( | |
| 56 const FileMappedForLaunch& files_to_register, | |
| 57 base::LaunchOptions* options) { | |
| 58 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | |
| 59 } | |
| 60 | |
| 61 base::Process ChildProcessLauncher::Helper::LaunchProcessOnLauncherThread( | |
| 62 const base::LaunchOptions& options, | |
| 63 FileMappedForLaunch* files_to_register, | |
| 64 bool* is_synchronous_launch, | |
| 65 int* launch_result) { | |
| 66 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | |
| 67 *is_synchronous_launch = true; | |
| 68 if (delegate_->ShouldLaunchElevated()) { | |
| 69 // When establishing a Mojo connection, the pipe path has already been added | |
| 70 // to the command line. | |
| 71 base::LaunchOptions win_options; | |
| 72 win_options.start_hidden = true; | |
| 73 return base::LaunchElevatedProcess(*command_line(), win_options); | |
| 74 } | |
| 75 base::HandlesToInheritVector handles; | |
| 76 handles.push_back(mojo_client_handle().handle); | |
| 77 base::FieldTrialList::AppendFieldTrialHandleIfNeeded(&handles); | |
| 78 command_line()->AppendSwitchASCII( | |
| 79 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, | |
| 80 base::UintToString(base::win::HandleToUint32(handles[0]))); | |
| 81 base::Process process; | |
| 82 *launch_result = | |
| 83 StartSandboxedProcess(delegate_.get(), command_line(), handles, &process); | |
| 84 // 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.
| |
| 85 return process; | |
|
boliu
2017/01/13 19:00:56
nit: extra space
Jay Civelli
2017/01/17 17:50:02
Done.
| |
| 86 } | |
| 87 | |
| 88 void ChildProcessLauncher::Helper::AfterLaunchOnLauncherThread( | |
| 89 const base::Process& process, | |
| 90 const base::LaunchOptions& options) { | |
| 91 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | |
| 92 } | |
| 93 | |
| 94 void ChildProcessLauncher::UpdateTerminationStatus(bool known_dead) { | |
| 95 DCHECK(CalledOnValidThread()); | |
| 96 termination_status_ = | |
| 97 base::GetTerminationStatus(process_.Handle(), &exit_code_); | |
| 98 } | |
| 99 | |
| 100 // static | |
| 101 bool ChildProcessLauncher::TerminateProcess( | |
| 102 const base::Process& process, int exit_code, bool wait) { | |
| 103 return process.Terminate(exit_code, wait); | |
| 104 } | |
| 105 | |
| 106 void ChildProcessLauncher::TerminateOnLauncherThread( | |
| 107 ZygoteHandle zygote, base::Process process) { | |
| 108 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | |
| 109 // Client has gone away, so just kill the process. Using exit code 0 means | |
| 110 // that UMA won't treat this as a crash. | |
| 111 process.Terminate(RESULT_CODE_NORMAL_EXIT, false); | |
| 112 } | |
| 113 | |
| 114 // static | |
| 115 void ChildProcessLauncher::SetProcessBackgroundedOnLauncherThread( | |
| 116 base::Process process, bool background) { | |
| 117 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | |
| 118 if (process.CanBackgroundProcesses()) | |
| 119 process.SetProcessBackgrounded(background); | |
| 120 } | |
| 121 | |
| 122 } // namespace content | |
| OLD | NEW |