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 <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
9 #include "base/location.h" | 11 #include "base/location.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
13 #include "base/process/kill.h" | 15 #include "base/process/kill.h" |
14 #include "base/process/launch.h" | 16 #include "base/process/launch.h" |
15 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
16 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 } | 51 } |
50 | 52 |
51 ChildProcessHost::ChildProcessHost(ScopedHandle channel) | 53 ChildProcessHost::ChildProcessHost(ScopedHandle channel) |
52 : launch_process_runner_(nullptr), | 54 : launch_process_runner_(nullptr), |
53 start_sandboxed_(false), | 55 start_sandboxed_(false), |
54 channel_info_(nullptr), | 56 channel_info_(nullptr), |
55 start_child_process_event_(false, false), | 57 start_child_process_event_(false, false), |
56 weak_factory_(this) { | 58 weak_factory_(this) { |
57 CHECK(channel.is_valid()); | 59 CHECK(channel.is_valid()); |
58 ScopedMessagePipeHandle handle(MessagePipeHandle(channel.release().value())); | 60 ScopedMessagePipeHandle handle(MessagePipeHandle(channel.release().value())); |
59 controller_.Bind(InterfacePtrInfo<ChildController>(handle.Pass(), 0u)); | 61 controller_.Bind(InterfacePtrInfo<ChildController>(std::move(handle), 0u)); |
60 } | 62 } |
61 | 63 |
62 ChildProcessHost::~ChildProcessHost() { | 64 ChildProcessHost::~ChildProcessHost() { |
63 if (!app_path_.empty()) | 65 if (!app_path_.empty()) |
64 CHECK(!controller_) << "Destroying ChildProcessHost before calling Join"; | 66 CHECK(!controller_) << "Destroying ChildProcessHost before calling Join"; |
65 } | 67 } |
66 | 68 |
67 void ChildProcessHost::Start() { | 69 void ChildProcessHost::Start() { |
68 DCHECK(!child_process_.IsValid()); | 70 DCHECK(!child_process_.IsValid()); |
69 DCHECK(child_message_pipe_.is_valid()); | 71 DCHECK(child_message_pipe_.is_valid()); |
70 | 72 |
71 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { | 73 if (base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")) { |
72 std::string client_handle_as_string = | 74 std::string client_handle_as_string = |
73 serializer_platform_channel_pair_ | 75 serializer_platform_channel_pair_ |
74 ->PrepareToPassClientHandleToChildProcessAsString( | 76 ->PrepareToPassClientHandleToChildProcessAsString( |
75 &handle_passing_info_); | 77 &handle_passing_info_); |
76 // We can't send the MP for the token serializer implementation as a | 78 // We can't send the MP for the token serializer implementation as a |
77 // platform handle, because that would require the other side to use the | 79 // platform handle, because that would require the other side to use the |
78 // token initializer itself! So instead we send it as a string. | 80 // token initializer itself! So instead we send it as a string. |
79 MojoResult rv = MojoWriteMessage( | 81 MojoResult rv = MojoWriteMessage( |
80 child_message_pipe_.get().value(), client_handle_as_string.c_str(), | 82 child_message_pipe_.get().value(), client_handle_as_string.c_str(), |
81 static_cast<uint32_t>(client_handle_as_string.size()), nullptr, 0, | 83 static_cast<uint32_t>(client_handle_as_string.size()), nullptr, 0, |
82 MOJO_WRITE_MESSAGE_FLAG_NONE); | 84 MOJO_WRITE_MESSAGE_FLAG_NONE); |
83 DCHECK_EQ(rv, MOJO_RESULT_OK); | 85 DCHECK_EQ(rv, MOJO_RESULT_OK); |
84 } | 86 } |
85 | 87 |
86 controller_.Bind( | 88 controller_.Bind( |
87 InterfacePtrInfo<ChildController>(child_message_pipe_.Pass(), 0u)); | 89 InterfacePtrInfo<ChildController>(std::move(child_message_pipe_), 0u)); |
88 | 90 |
89 launch_process_runner_->PostTaskAndReply( | 91 launch_process_runner_->PostTaskAndReply( |
90 FROM_HERE, | 92 FROM_HERE, |
91 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), | 93 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), |
92 base::Bind(&ChildProcessHost::DidStart, weak_factory_.GetWeakPtr())); | 94 base::Bind(&ChildProcessHost::DidStart, weak_factory_.GetWeakPtr())); |
93 } | 95 } |
94 | 96 |
95 base::ProcessId ChildProcessHost::GetChildPID() const { | 97 base::ProcessId ChildProcessHost::GetChildPID() const { |
96 return child_process_.IsValid() ? child_process_.Pid() : base::kNullProcessId; | 98 return child_process_.IsValid() ? child_process_.Pid() : base::kNullProcessId; |
97 } | 99 } |
(...skipping 10 matching lines...) Expand all Loading... |
108 return rv; | 110 return rv; |
109 } | 111 } |
110 | 112 |
111 void ChildProcessHost::StartApp( | 113 void ChildProcessHost::StartApp( |
112 InterfaceRequest<Application> application_request, | 114 InterfaceRequest<Application> application_request, |
113 const ChildController::StartAppCallback& on_app_complete) { | 115 const ChildController::StartAppCallback& on_app_complete) { |
114 DCHECK(controller_); | 116 DCHECK(controller_); |
115 | 117 |
116 on_app_complete_ = on_app_complete; | 118 on_app_complete_ = on_app_complete; |
117 controller_->StartApp( | 119 controller_->StartApp( |
118 application_request.Pass(), | 120 std::move(application_request), |
119 base::Bind(&ChildProcessHost::AppCompleted, weak_factory_.GetWeakPtr())); | 121 base::Bind(&ChildProcessHost::AppCompleted, weak_factory_.GetWeakPtr())); |
120 } | 122 } |
121 | 123 |
122 void ChildProcessHost::ExitNow(int32_t exit_code) { | 124 void ChildProcessHost::ExitNow(int32_t exit_code) { |
123 DCHECK(controller_); | 125 DCHECK(controller_); |
124 | 126 |
125 controller_->ExitNow(exit_code); | 127 controller_->ExitNow(exit_code); |
126 } | 128 } |
127 | 129 |
128 void ChildProcessHost::DidStart() { | 130 void ChildProcessHost::DidStart() { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { | 230 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { |
229 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; | 231 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; |
230 | 232 |
231 DCHECK(channel_info || | 233 DCHECK(channel_info || |
232 base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")); | 234 base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")); |
233 channel_info_ = channel_info; | 235 channel_info_ = channel_info; |
234 } | 236 } |
235 | 237 |
236 } // namespace runner | 238 } // namespace runner |
237 } // namespace mojo | 239 } // namespace mojo |
OLD | NEW |