OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/shell/runner/host/child_process_host.h" | 5 #include "mojo/shell/runner/host/child_process_host.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/process/kill.h" | 17 #include "base/process/kill.h" |
18 #include "base/process/launch.h" | 18 #include "base/process/launch.h" |
| 19 #include "base/synchronization/lock.h" |
19 #include "base/task_runner.h" | 20 #include "base/task_runner.h" |
20 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
21 #include "mojo/edk/embedder/embedder.h" | 22 #include "mojo/edk/embedder/embedder.h" |
22 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 23 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
23 #include "mojo/public/cpp/system/core.h" | 24 #include "mojo/public/cpp/system/core.h" |
24 #include "mojo/shell/native_runner_delegate.h" | 25 #include "mojo/shell/native_runner_delegate.h" |
25 #include "mojo/shell/runner/common/client_util.h" | 26 #include "mojo/shell/runner/common/client_util.h" |
26 #include "mojo/shell/runner/common/switches.h" | 27 #include "mojo/shell/runner/common/switches.h" |
27 | 28 |
28 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 29 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
29 #include "sandbox/linux/services/namespace_sandbox.h" | 30 #include "sandbox/linux/services/namespace_sandbox.h" |
30 #endif | 31 #endif |
31 | 32 |
32 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
33 #include "base/win/windows_version.h" | 34 #include "base/win/windows_version.h" |
34 #endif | 35 #endif |
35 | 36 |
| 37 #if defined(OS_MACOSX) |
| 38 #include "mojo/shell/runner/host/mach_broker.h" |
| 39 #endif |
| 40 |
36 namespace mojo { | 41 namespace mojo { |
37 namespace shell { | 42 namespace shell { |
38 | 43 |
39 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner, | 44 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner, |
40 NativeRunnerDelegate* delegate, | 45 NativeRunnerDelegate* delegate, |
41 bool start_sandboxed, | 46 bool start_sandboxed, |
42 const Identity& target, | 47 const Identity& target, |
43 const base::FilePath& app_path) | 48 const base::FilePath& app_path) |
44 : launch_process_runner_(launch_process_runner), | 49 : launch_process_runner_(launch_process_runner), |
45 delegate_(delegate), | 50 delegate_(delegate), |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 177 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
173 if (start_sandboxed_) { | 178 if (start_sandboxed_) { |
174 child_process_ = | 179 child_process_ = |
175 sandbox::NamespaceSandbox::LaunchProcess(*child_command_line, options); | 180 sandbox::NamespaceSandbox::LaunchProcess(*child_command_line, options); |
176 if (!child_process_.IsValid()) { | 181 if (!child_process_.IsValid()) { |
177 LOG(ERROR) << "Starting the process with a sandbox failed. Missing kernel" | 182 LOG(ERROR) << "Starting the process with a sandbox failed. Missing kernel" |
178 << " support."; | 183 << " support."; |
179 } | 184 } |
180 } else | 185 } else |
181 #endif | 186 #endif |
| 187 { |
| 188 #if defined(OS_MACOSX) |
| 189 MachBroker* mach_broker = MachBroker::GetInstance(); |
| 190 base::AutoLock locker(mach_broker->GetLock()); |
| 191 #endif |
182 child_process_ = base::LaunchProcess(*child_command_line, options); | 192 child_process_ = base::LaunchProcess(*child_command_line, options); |
| 193 #if defined(OS_MACOSX) |
| 194 mach_broker->ExpectPid(child_process_.Handle()); |
| 195 #endif |
| 196 } |
183 | 197 |
184 if (child_process_.IsValid()) { | 198 if (child_process_.IsValid()) { |
185 if (mojo_ipc_channel_.get()) { | 199 if (mojo_ipc_channel_.get()) { |
186 mojo_ipc_channel_->ChildProcessLaunched(); | 200 mojo_ipc_channel_->ChildProcessLaunched(); |
187 mojo::edk::ChildProcessLaunched( | 201 mojo::edk::ChildProcessLaunched( |
188 child_process_.Handle(), | 202 child_process_.Handle(), |
189 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle( | 203 mojo::edk::ScopedPlatformHandle(mojo::edk::PlatformHandle( |
190 mojo_ipc_channel_->PassServerHandle().release().handle))); | 204 mojo_ipc_channel_->PassServerHandle().release().handle))); |
191 } | 205 } |
192 } | 206 } |
193 start_child_process_event_.Signal(); | 207 start_child_process_event_.Signal(); |
194 } | 208 } |
195 | 209 |
196 } // namespace shell | 210 } // namespace shell |
197 } // namespace mojo | 211 } // namespace mojo |
OLD | NEW |