| 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/runner/child_process_host.h" | 5 #include "mojo/runner/child_process_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/process/kill.h" | 13 #include "base/process/kill.h" |
| 14 #include "base/process/launch.h" | 14 #include "base/process/launch.h" |
| 15 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 16 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 18 #include "mojo/edk/embedder/embedder.h" | |
| 19 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 18 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
| 20 #include "mojo/public/cpp/system/core.h" | 19 #include "mojo/public/cpp/system/core.h" |
| 21 #include "mojo/runner/context.h" | 20 #include "mojo/runner/context.h" |
| 22 #include "mojo/runner/switches.h" | 21 #include "mojo/runner/switches.h" |
| 23 #include "mojo/runner/task_runners.h" | 22 #include "mojo/runner/task_runners.h" |
| 24 | 23 |
| 24 #if defined(USE_CHROME_EDK) |
| 25 #include "mojo/edk/embedder/embedder.h" |
| 26 #else |
| 27 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
| 28 #endif |
| 29 |
| 25 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 30 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
| 26 #include "sandbox/linux/services/namespace_sandbox.h" | 31 #include "sandbox/linux/services/namespace_sandbox.h" |
| 27 #endif | 32 #endif |
| 28 | 33 |
| 29 namespace mojo { | 34 namespace mojo { |
| 30 namespace runner { | 35 namespace runner { |
| 31 | 36 |
| 32 ChildProcessHost::ChildProcessHost(Context* context, | 37 ChildProcessHost::ChildProcessHost(Context* context, |
| 33 bool start_sandboxed, | 38 bool start_sandboxed, |
| 34 const base::FilePath& app_path) | 39 const base::FilePath& app_path) |
| 35 : context_(context), | 40 : context_(context), |
| 36 start_sandboxed_(start_sandboxed), | 41 start_sandboxed_(start_sandboxed), |
| 37 app_path_(app_path), | 42 app_path_(app_path) |
| 38 channel_info_(nullptr) { | 43 #if !defined(USE_CHROME_EDK) |
| 44 , |
| 45 channel_info_(nullptr) |
| 46 #endif |
| 47 { |
| 39 platform_channel_ = platform_channel_pair_.PassServerHandle(); | 48 platform_channel_ = platform_channel_pair_.PassServerHandle(); |
| 40 CHECK(platform_channel_.is_valid()); | 49 CHECK(platform_channel_.is_valid()); |
| 41 } | 50 } |
| 42 | 51 |
| 43 ChildProcessHost::~ChildProcessHost() { | 52 ChildProcessHost::~ChildProcessHost() { |
| 44 if (child_process_.IsValid()) { | 53 if (child_process_.IsValid()) { |
| 45 LOG(WARNING) << "Destroying ChildProcessHost with unjoined child"; | 54 LOG(WARNING) << "Destroying ChildProcessHost with unjoined child"; |
| 46 child_process_.Close(); | 55 child_process_.Close(); |
| 47 } | 56 } |
| 48 } | 57 } |
| 49 | 58 |
| 50 void ChildProcessHost::Start() { | 59 void ChildProcessHost::Start() { |
| 51 DCHECK(!child_process_.IsValid()); | 60 DCHECK(!child_process_.IsValid()); |
| 52 DCHECK(platform_channel_.is_valid()); | 61 DCHECK(platform_channel_.is_valid()); |
| 53 | 62 |
| 63 #if defined(USE_CHROME_EDK) |
| 64 ScopedMessagePipeHandle handle( |
| 65 embedder::CreateMessagePipe(platform_channel_.Pass())); |
| 66 #else |
| 54 ScopedMessagePipeHandle handle(embedder::CreateChannel( | 67 ScopedMessagePipeHandle handle(embedder::CreateChannel( |
| 55 platform_channel_.Pass(), | 68 platform_channel_.Pass(), |
| 56 base::Bind(&ChildProcessHost::DidCreateChannel, base::Unretained(this)), | 69 base::Bind(&ChildProcessHost::DidCreateChannel, base::Unretained(this)), |
| 57 base::ThreadTaskRunnerHandle::Get())); | 70 base::ThreadTaskRunnerHandle::Get())); |
| 71 #endif |
| 58 | 72 |
| 59 controller_.Bind(InterfacePtrInfo<ChildController>(handle.Pass(), 0u)); | 73 controller_.Bind(InterfacePtrInfo<ChildController>(handle.Pass(), 0u)); |
| 60 | 74 |
| 61 CHECK(base::PostTaskAndReplyWithResult( | 75 CHECK(base::PostTaskAndReplyWithResult( |
| 62 context_->task_runners()->blocking_pool(), FROM_HERE, | 76 context_->task_runners()->blocking_pool(), FROM_HERE, |
| 63 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), | 77 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), |
| 64 base::Bind(&ChildProcessHost::DidStart, base::Unretained(this)))); | 78 base::Bind(&ChildProcessHost::DidStart, base::Unretained(this)))); |
| 65 } | 79 } |
| 66 | 80 |
| 67 int ChildProcessHost::Join() { | 81 int ChildProcessHost::Join() { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 } | 160 } |
| 147 | 161 |
| 148 void ChildProcessHost::AppCompleted(int32_t result) { | 162 void ChildProcessHost::AppCompleted(int32_t result) { |
| 149 if (!on_app_complete_.is_null()) { | 163 if (!on_app_complete_.is_null()) { |
| 150 auto on_app_complete = on_app_complete_; | 164 auto on_app_complete = on_app_complete_; |
| 151 on_app_complete_.reset(); | 165 on_app_complete_.reset(); |
| 152 on_app_complete.Run(result); | 166 on_app_complete.Run(result); |
| 153 } | 167 } |
| 154 } | 168 } |
| 155 | 169 |
| 170 #if !defined(USE_CHROME_EDK) |
| 156 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { | 171 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { |
| 157 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; | 172 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; |
| 158 | 173 |
| 159 CHECK(channel_info); | 174 CHECK(channel_info); |
| 160 channel_info_ = channel_info; | 175 channel_info_ = channel_info; |
| 161 } | 176 } |
| 177 #endif |
| 162 | 178 |
| 163 } // namespace runner | 179 } // namespace runner |
| 164 } // namespace mojo | 180 } // namespace mojo |
| OLD | NEW |