| 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/host/child_process_host.h" | 5 #include "mojo/runner/host/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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner, | 33 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner, |
| 34 bool start_sandboxed, | 34 bool start_sandboxed, |
| 35 const base::FilePath& app_path) | 35 const base::FilePath& app_path) |
| 36 : launch_process_runner_(launch_process_runner), | 36 : launch_process_runner_(launch_process_runner), |
| 37 start_sandboxed_(start_sandboxed), | 37 start_sandboxed_(start_sandboxed), |
| 38 app_path_(app_path), | 38 app_path_(app_path), |
| 39 channel_info_(nullptr), | 39 channel_info_(nullptr), |
| 40 start_child_process_event_(false, false), | 40 start_child_process_event_(false, false), |
| 41 weak_factory_(this) { | 41 weak_factory_(this) { |
| 42 #if defined(OS_WIN) | |
| 43 // TODO(jam): enable on POSIX | |
| 44 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) | 42 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) |
| 45 serializer_platform_channel_pair_.reset(new edk::PlatformChannelPair(true)); | 43 serializer_platform_channel_pair_.reset(new edk::PlatformChannelPair(true)); |
| 46 #endif | |
| 47 | 44 |
| 48 child_message_pipe_ = embedder::CreateChannel( | 45 child_message_pipe_ = embedder::CreateChannel( |
| 49 platform_channel_pair_.PassServerHandle(), | 46 platform_channel_pair_.PassServerHandle(), |
| 50 base::Bind(&ChildProcessHost::DidCreateChannel, base::Unretained(this)), | 47 base::Bind(&ChildProcessHost::DidCreateChannel, base::Unretained(this)), |
| 51 base::ThreadTaskRunnerHandle::Get()); | 48 base::ThreadTaskRunnerHandle::Get()); |
| 52 } | 49 } |
| 53 | 50 |
| 54 ChildProcessHost::ChildProcessHost(ScopedHandle channel) | 51 ChildProcessHost::ChildProcessHost(ScopedHandle channel) |
| 55 : launch_process_runner_(nullptr), | 52 : launch_process_runner_(nullptr), |
| 56 start_sandboxed_(false), | 53 start_sandboxed_(false), |
| 57 channel_info_(nullptr), | 54 channel_info_(nullptr), |
| 58 start_child_process_event_(false, false), | 55 start_child_process_event_(false, false), |
| 59 weak_factory_(this) { | 56 weak_factory_(this) { |
| 60 CHECK(channel.is_valid()); | 57 CHECK(channel.is_valid()); |
| 61 ScopedMessagePipeHandle handle(MessagePipeHandle(channel.release().value())); | 58 ScopedMessagePipeHandle handle(MessagePipeHandle(channel.release().value())); |
| 62 controller_.Bind(InterfacePtrInfo<ChildController>(handle.Pass(), 0u)); | 59 controller_.Bind(InterfacePtrInfo<ChildController>(handle.Pass(), 0u)); |
| 63 } | 60 } |
| 64 | 61 |
| 65 ChildProcessHost::~ChildProcessHost() { | 62 ChildProcessHost::~ChildProcessHost() { |
| 66 if (!app_path_.empty()) | 63 if (!app_path_.empty()) |
| 67 CHECK(!controller_) << "Destroying ChildProcessHost before calling Join"; | 64 CHECK(!controller_) << "Destroying ChildProcessHost before calling Join"; |
| 68 } | 65 } |
| 69 | 66 |
| 70 void ChildProcessHost::Start() { | 67 void ChildProcessHost::Start() { |
| 71 DCHECK(!child_process_.IsValid()); | 68 DCHECK(!child_process_.IsValid()); |
| 72 DCHECK(child_message_pipe_.is_valid()); | 69 DCHECK(child_message_pipe_.is_valid()); |
| 73 | 70 |
| 74 #if defined(OS_WIN) | |
| 75 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { | 71 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { |
| 76 std::string client_handle_as_string = | 72 std::string client_handle_as_string = |
| 77 serializer_platform_channel_pair_ | 73 serializer_platform_channel_pair_ |
| 78 ->PrepareToPassClientHandleToChildProcessAsString( | 74 ->PrepareToPassClientHandleToChildProcessAsString( |
| 79 &handle_passing_info_); | 75 &handle_passing_info_); |
| 80 // We can't send the MP for the token serializer implementation as a | 76 // We can't send the MP for the token serializer implementation as a |
| 81 // platform handle, because that would require the other side to use the | 77 // platform handle, because that would require the other side to use the |
| 82 // token initializer itself! So instead we send it as a string. | 78 // token initializer itself! So instead we send it as a string. |
| 83 MojoResult rv = MojoWriteMessage( | 79 MojoResult rv = MojoWriteMessage( |
| 84 child_message_pipe_.get().value(), client_handle_as_string.c_str(), | 80 child_message_pipe_.get().value(), client_handle_as_string.c_str(), |
| 85 static_cast<uint32_t>(client_handle_as_string.size()), nullptr, 0, | 81 static_cast<uint32_t>(client_handle_as_string.size()), nullptr, 0, |
| 86 MOJO_WRITE_MESSAGE_FLAG_NONE); | 82 MOJO_WRITE_MESSAGE_FLAG_NONE); |
| 87 DCHECK_EQ(rv, MOJO_RESULT_OK); | 83 DCHECK_EQ(rv, MOJO_RESULT_OK); |
| 88 } | 84 } |
| 89 #endif | |
| 90 | 85 |
| 91 controller_.Bind( | 86 controller_.Bind( |
| 92 InterfacePtrInfo<ChildController>(child_message_pipe_.Pass(), 0u)); | 87 InterfacePtrInfo<ChildController>(child_message_pipe_.Pass(), 0u)); |
| 93 | 88 |
| 94 launch_process_runner_->PostTaskAndReply( | 89 launch_process_runner_->PostTaskAndReply( |
| 95 FROM_HERE, | 90 FROM_HERE, |
| 96 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), | 91 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), |
| 97 base::Bind(&ChildProcessHost::DidStart, weak_factory_.GetWeakPtr())); | 92 base::Bind(&ChildProcessHost::DidStart, weak_factory_.GetWeakPtr())); |
| 98 } | 93 } |
| 99 | 94 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 if (!child_process_.IsValid()) { | 194 if (!child_process_.IsValid()) { |
| 200 LOG(ERROR) << "Starting the process with a sandbox failed. Missing kernel" | 195 LOG(ERROR) << "Starting the process with a sandbox failed. Missing kernel" |
| 201 << " support."; | 196 << " support."; |
| 202 } | 197 } |
| 203 } else | 198 } else |
| 204 #endif | 199 #endif |
| 205 child_process_ = base::LaunchProcess(child_command_line, options); | 200 child_process_ = base::LaunchProcess(child_command_line, options); |
| 206 | 201 |
| 207 if (child_process_.IsValid()) { | 202 if (child_process_.IsValid()) { |
| 208 platform_channel_pair_.ChildProcessLaunched(); | 203 platform_channel_pair_.ChildProcessLaunched(); |
| 209 #if defined(OS_WIN) | |
| 210 if (serializer_platform_channel_pair_.get()) { | 204 if (serializer_platform_channel_pair_.get()) { |
| 211 serializer_platform_channel_pair_->ChildProcessLaunched(); | 205 serializer_platform_channel_pair_->ChildProcessLaunched(); |
| 212 mojo::embedder::ChildProcessLaunched( | 206 mojo::embedder::ChildProcessLaunched( |
| 213 child_process_.Handle(), | 207 child_process_.Handle(), |
| 214 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( | 208 mojo::embedder::ScopedPlatformHandle(mojo::embedder::PlatformHandle( |
| 215 serializer_platform_channel_pair_->PassServerHandle().release(). | 209 serializer_platform_channel_pair_->PassServerHandle().release(). |
| 216 #if defined(OS_WIN) | 210 #if defined(OS_WIN) |
| 217 handle | 211 handle |
| 218 #else | 212 #else |
| 219 fd | 213 fd |
| 220 #endif | 214 #endif |
| 221 ))); | 215 ))); |
| 222 } | 216 } |
| 223 #endif | |
| 224 } | 217 } |
| 225 start_child_process_event_.Signal(); | 218 start_child_process_event_.Signal(); |
| 226 } | 219 } |
| 227 | 220 |
| 228 void ChildProcessHost::AppCompleted(int32_t result) { | 221 void ChildProcessHost::AppCompleted(int32_t result) { |
| 229 if (!on_app_complete_.is_null()) { | 222 if (!on_app_complete_.is_null()) { |
| 230 auto on_app_complete = on_app_complete_; | 223 auto on_app_complete = on_app_complete_; |
| 231 on_app_complete_.reset(); | 224 on_app_complete_.reset(); |
| 232 on_app_complete.Run(result); | 225 on_app_complete.Run(result); |
| 233 } | 226 } |
| 234 } | 227 } |
| 235 | 228 |
| 236 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { | 229 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { |
| 237 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; | 230 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; |
| 238 | 231 |
| 239 DCHECK(channel_info || | 232 DCHECK(channel_info || |
| 240 base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")); | 233 base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")); |
| 241 channel_info_ = channel_info; | 234 channel_info_ = channel_info; |
| 242 } | 235 } |
| 243 | 236 |
| 244 } // namespace runner | 237 } // namespace runner |
| 245 } // namespace mojo | 238 } // namespace mojo |
| OLD | NEW |