| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/child_process_launcher.h" | 5 #include "content/browser/child_process_launcher.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 12 #include "base/i18n/icu_util.h" | 13 #include "base/i18n/icu_util.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/process/launch.h" | 16 #include "base/process/launch.h" |
| 17 #include "base/process/process.h" | 17 #include "base/process/process.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 20 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "content/public/browser/content_browser_client.h" | 22 #include "content/public/browser/content_browser_client.h" |
| 23 #include "content/public/common/content_descriptors.h" | 23 #include "content/public/common/content_descriptors.h" |
| 24 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 void LaunchOnLauncherThread(const NotifyCallback& callback, | 110 void LaunchOnLauncherThread(const NotifyCallback& callback, |
| 111 BrowserThread::ID client_thread_id, | 111 BrowserThread::ID client_thread_id, |
| 112 int child_process_id, | 112 int child_process_id, |
| 113 SandboxedProcessLauncherDelegate* delegate, | 113 SandboxedProcessLauncherDelegate* delegate, |
| 114 #if defined(OS_ANDROID) | 114 #if defined(OS_ANDROID) |
| 115 base::ScopedFD ipcfd, | 115 base::ScopedFD ipcfd, |
| 116 #endif | 116 #endif |
| 117 mojo::edk::ScopedPlatformHandle client_handle, | 117 mojo::edk::ScopedPlatformHandle client_handle, |
| 118 base::CommandLine* cmd_line) { | 118 base::CommandLine* cmd_line) { |
| 119 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | 119 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 120 scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); | 120 std::unique_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate); |
| 121 #if !defined(OS_ANDROID) | 121 #if !defined(OS_ANDROID) |
| 122 ZygoteHandle zygote = nullptr; | 122 ZygoteHandle zygote = nullptr; |
| 123 #endif | 123 #endif |
| 124 #if defined(OS_WIN) | 124 #if defined(OS_WIN) |
| 125 bool launch_elevated = delegate->ShouldLaunchElevated(); | 125 bool launch_elevated = delegate->ShouldLaunchElevated(); |
| 126 #elif defined(OS_MACOSX) | 126 #elif defined(OS_MACOSX) |
| 127 base::EnvironmentMap env = delegate->GetEnvironment(); | 127 base::EnvironmentMap env = delegate->GetEnvironment(); |
| 128 base::ScopedFD ipcfd = delegate->TakeIpcFd(); | 128 base::ScopedFD ipcfd = delegate->TakeIpcFd(); |
| 129 #elif defined(OS_POSIX) && !defined(OS_ANDROID) | 129 #elif defined(OS_POSIX) && !defined(OS_ANDROID) |
| 130 base::EnvironmentMap env = delegate->GetEnvironment(); | 130 base::EnvironmentMap env = delegate->GetEnvironment(); |
| 131 base::ScopedFD ipcfd = delegate->TakeIpcFd(); | 131 base::ScopedFD ipcfd = delegate->TakeIpcFd(); |
| 132 #endif | 132 #endif |
| 133 scoped_ptr<base::CommandLine> cmd_line_deleter(cmd_line); | 133 std::unique_ptr<base::CommandLine> cmd_line_deleter(cmd_line); |
| 134 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); | 134 base::TimeTicks begin_launch_time = base::TimeTicks::Now(); |
| 135 | 135 |
| 136 base::Process process; | 136 base::Process process; |
| 137 #if defined(OS_WIN) | 137 #if defined(OS_WIN) |
| 138 if (launch_elevated) { | 138 if (launch_elevated) { |
| 139 // TODO(rockot): We may want to support Mojo IPC to elevated processes as | 139 // TODO(rockot): We may want to support Mojo IPC to elevated processes as |
| 140 // well, but this isn't currently feasible without sharing a pipe path on | 140 // well, but this isn't currently feasible without sharing a pipe path on |
| 141 // the command line as elevated process launch goes through ShellExecuteEx. | 141 // the command line as elevated process launch goes through ShellExecuteEx. |
| 142 base::LaunchOptions options; | 142 base::LaunchOptions options; |
| 143 options.start_hidden = true; | 143 options.start_hidden = true; |
| 144 process = base::LaunchElevatedProcess(*cmd_line, options); | 144 process = base::LaunchElevatedProcess(*cmd_line, options); |
| 145 } else { | 145 } else { |
| 146 base::HandlesToInheritVector handles; | 146 base::HandlesToInheritVector handles; |
| 147 handles.push_back(client_handle.get().handle); | 147 handles.push_back(client_handle.get().handle); |
| 148 cmd_line->AppendSwitchASCII( | 148 cmd_line->AppendSwitchASCII( |
| 149 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, | 149 mojo::edk::PlatformChannelPair::kMojoPlatformChannelHandleSwitch, |
| 150 base::UintToString(base::win::HandleToUint32(handles[0]))); | 150 base::UintToString(base::win::HandleToUint32(handles[0]))); |
| 151 process = StartSandboxedProcess(delegate, cmd_line, handles); | 151 process = StartSandboxedProcess(delegate, cmd_line, handles); |
| 152 } | 152 } |
| 153 #elif defined(OS_POSIX) | 153 #elif defined(OS_POSIX) |
| 154 std::string process_type = | 154 std::string process_type = |
| 155 cmd_line->GetSwitchValueASCII(switches::kProcessType); | 155 cmd_line->GetSwitchValueASCII(switches::kProcessType); |
| 156 scoped_ptr<FileDescriptorInfo> files_to_register( | 156 std::unique_ptr<FileDescriptorInfo> files_to_register( |
| 157 FileDescriptorInfoImpl::Create()); | 157 FileDescriptorInfoImpl::Create()); |
| 158 | 158 |
| 159 base::ScopedFD mojo_fd(client_handle.release().handle); | 159 base::ScopedFD mojo_fd(client_handle.release().handle); |
| 160 DCHECK(mojo_fd.is_valid()); | 160 DCHECK(mojo_fd.is_valid()); |
| 161 | 161 |
| 162 #if defined(OS_ANDROID) | 162 #if defined(OS_ANDROID) |
| 163 if (ipcfd.get() != -1) | 163 if (ipcfd.get() != -1) |
| 164 files_to_register->Share(kPrimaryIPCChannel, ipcfd.get()); | 164 files_to_register->Share(kPrimaryIPCChannel, ipcfd.get()); |
| 165 files_to_register->Share(kMojoIPCChannel, mojo_fd.get()); | 165 files_to_register->Share(kMojoIPCChannel, mojo_fd.get()); |
| 166 #else | 166 #else |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 // port to the parent prior to the parent leaving LaunchProcess, the | 297 // port to the parent prior to the parent leaving LaunchProcess, the |
| 298 // order in which the record in MachBroker is updated is correct. | 298 // order in which the record in MachBroker is updated is correct. |
| 299 MachBroker* broker = MachBroker::GetInstance(); | 299 MachBroker* broker = MachBroker::GetInstance(); |
| 300 broker->GetLock().Acquire(); | 300 broker->GetLock().Acquire(); |
| 301 | 301 |
| 302 // Make sure the MachBroker is running, and inform it to expect a | 302 // Make sure the MachBroker is running, and inform it to expect a |
| 303 // check-in from the new process. | 303 // check-in from the new process. |
| 304 broker->EnsureRunning(); | 304 broker->EnsureRunning(); |
| 305 | 305 |
| 306 const SandboxType sandbox_type = delegate->GetSandboxType(); | 306 const SandboxType sandbox_type = delegate->GetSandboxType(); |
| 307 scoped_ptr<sandbox::PreExecDelegate> pre_exec_delegate; | 307 std::unique_ptr<sandbox::PreExecDelegate> pre_exec_delegate; |
| 308 if (BootstrapSandboxManager::ShouldEnable()) { | 308 if (BootstrapSandboxManager::ShouldEnable()) { |
| 309 BootstrapSandboxManager* sandbox_manager = | 309 BootstrapSandboxManager* sandbox_manager = |
| 310 BootstrapSandboxManager::GetInstance(); | 310 BootstrapSandboxManager::GetInstance(); |
| 311 if (sandbox_manager->EnabledForSandbox(sandbox_type)) { | 311 if (sandbox_manager->EnabledForSandbox(sandbox_type)) { |
| 312 pre_exec_delegate = sandbox_manager->sandbox()->NewClient(sandbox_type); | 312 pre_exec_delegate = sandbox_manager->sandbox()->NewClient(sandbox_type); |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 options.pre_exec_delegate = pre_exec_delegate.get(); | 315 options.pre_exec_delegate = pre_exec_delegate.get(); |
| 316 #endif // defined(OS_MACOSX) | 316 #endif // defined(OS_MACOSX) |
| 317 | 317 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 } | 587 } |
| 588 | 588 |
| 589 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 589 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
| 590 Client* client) { | 590 Client* client) { |
| 591 Client* ret = client_; | 591 Client* ret = client_; |
| 592 client_ = client; | 592 client_ = client; |
| 593 return ret; | 593 return ret; |
| 594 } | 594 } |
| 595 | 595 |
| 596 } // namespace content | 596 } // namespace content |
| OLD | NEW |