| 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 edk::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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 bool ChildProcessHost::DoLaunch() { | 117 bool ChildProcessHost::DoLaunch() { |
| 104 const base::CommandLine* parent_command_line = | 118 const base::CommandLine* parent_command_line = |
| 105 base::CommandLine::ForCurrentProcess(); | 119 base::CommandLine::ForCurrentProcess(); |
| 106 base::CommandLine child_command_line(parent_command_line->GetProgram()); | 120 base::CommandLine child_command_line(parent_command_line->GetProgram()); |
| 107 child_command_line.AppendArguments(*parent_command_line, false); | 121 child_command_line.AppendArguments(*parent_command_line, false); |
| 108 child_command_line.AppendSwitchPath(switches::kChildProcess, app_path_); | 122 child_command_line.AppendSwitchPath(switches::kChildProcess, app_path_); |
| 109 | 123 |
| 110 if (start_sandboxed_) | 124 if (start_sandboxed_) |
| 111 child_command_line.AppendSwitch(switches::kEnableSandbox); | 125 child_command_line.AppendSwitch(switches::kEnableSandbox); |
| 112 | 126 |
| 127 #if defined(USE_CHROME_EDK) |
| 128 edk::HandlePassingInformation handle_passing_info; |
| 129 platform_channel_pair_.PrepareToPassClientHandleToChildProcess( |
| 130 &child_command_line, &handle_passing_info); |
| 131 #else |
| 113 embedder::HandlePassingInformation handle_passing_info; | 132 embedder::HandlePassingInformation handle_passing_info; |
| 114 platform_channel_pair_.PrepareToPassClientHandleToChildProcess( | 133 platform_channel_pair_.PrepareToPassClientHandleToChildProcess( |
| 115 &child_command_line, &handle_passing_info); | 134 &child_command_line, &handle_passing_info); |
| 135 #endif |
| 116 | 136 |
| 117 base::LaunchOptions options; | 137 base::LaunchOptions options; |
| 118 #if defined(OS_WIN) | 138 #if defined(OS_WIN) |
| 119 options.handles_to_inherit = &handle_passing_info; | 139 options.handles_to_inherit = &handle_passing_info; |
| 120 #elif defined(OS_POSIX) | 140 #elif defined(OS_POSIX) |
| 121 handle_passing_info.push_back(std::make_pair(STDIN_FILENO, STDIN_FILENO)); | 141 handle_passing_info.push_back(std::make_pair(STDIN_FILENO, STDIN_FILENO)); |
| 122 handle_passing_info.push_back(std::make_pair(STDOUT_FILENO, STDOUT_FILENO)); | 142 handle_passing_info.push_back(std::make_pair(STDOUT_FILENO, STDOUT_FILENO)); |
| 123 handle_passing_info.push_back(std::make_pair(STDERR_FILENO, STDERR_FILENO)); | 143 handle_passing_info.push_back(std::make_pair(STDERR_FILENO, STDERR_FILENO)); |
| 124 options.fds_to_remap = &handle_passing_info; | 144 options.fds_to_remap = &handle_passing_info; |
| 125 #endif | 145 #endif |
| (...skipping 20 matching lines...) Expand all Loading... |
| 146 } | 166 } |
| 147 | 167 |
| 148 void ChildProcessHost::AppCompleted(int32_t result) { | 168 void ChildProcessHost::AppCompleted(int32_t result) { |
| 149 if (!on_app_complete_.is_null()) { | 169 if (!on_app_complete_.is_null()) { |
| 150 auto on_app_complete = on_app_complete_; | 170 auto on_app_complete = on_app_complete_; |
| 151 on_app_complete_.reset(); | 171 on_app_complete_.reset(); |
| 152 on_app_complete.Run(result); | 172 on_app_complete.Run(result); |
| 153 } | 173 } |
| 154 } | 174 } |
| 155 | 175 |
| 176 #if !defined(USE_CHROME_EDK) |
| 156 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { | 177 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { |
| 157 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; | 178 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; |
| 158 | 179 |
| 159 CHECK(channel_info); | 180 CHECK(channel_info); |
| 160 channel_info_ = channel_info; | 181 channel_info_ = channel_info; |
| 161 } | 182 } |
| 183 #endif |
| 162 | 184 |
| 163 } // namespace runner | 185 } // namespace runner |
| 164 } // namespace mojo | 186 } // namespace mojo |
| OLD | NEW |