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 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 81 } |
82 | 82 |
83 ChildProcessHost::ChildProcessHost(ScopedHandle channel) | 83 ChildProcessHost::ChildProcessHost(ScopedHandle channel) |
84 : launch_process_runner_(nullptr), | 84 : launch_process_runner_(nullptr), |
85 start_sandboxed_(false), | 85 start_sandboxed_(false), |
86 channel_info_(nullptr), | 86 channel_info_(nullptr), |
87 start_child_process_event_(false, false), | 87 start_child_process_event_(false, false), |
88 weak_factory_(this) { | 88 weak_factory_(this) { |
89 CHECK(channel.is_valid()); | 89 CHECK(channel.is_valid()); |
90 ScopedMessagePipeHandle handle(MessagePipeHandle(channel.release().value())); | 90 ScopedMessagePipeHandle handle(MessagePipeHandle(channel.release().value())); |
91 controller_.Bind(InterfacePtrInfo<ChildController>(std::move(handle), 0u)); | 91 controller_.Bind( |
| 92 InterfacePtrInfo<mojom::ChildController>(std::move(handle), 0u)); |
92 } | 93 } |
93 | 94 |
94 ChildProcessHost::~ChildProcessHost() { | 95 ChildProcessHost::~ChildProcessHost() { |
95 if (!app_path_.empty()) | 96 if (!app_path_.empty()) |
96 CHECK(!controller_) << "Destroying ChildProcessHost before calling Join"; | 97 CHECK(!controller_) << "Destroying ChildProcessHost before calling Join"; |
97 } | 98 } |
98 | 99 |
99 void ChildProcessHost::Start(const ProcessReadyCallback& callback) { | 100 void ChildProcessHost::Start(const ProcessReadyCallback& callback) { |
100 DCHECK(!child_process_.IsValid()); | 101 DCHECK(!child_process_.IsValid()); |
101 DCHECK(process_ready_callback_.is_null()); | 102 DCHECK(process_ready_callback_.is_null()); |
(...skipping 29 matching lines...) Expand all Loading... |
131 launch_process_runner_->PostTaskAndReply( | 132 launch_process_runner_->PostTaskAndReply( |
132 FROM_HERE, | 133 FROM_HERE, |
133 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), | 134 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), |
134 base::Bind(&ChildProcessHost::DidStart, weak_factory_.GetWeakPtr())); | 135 base::Bind(&ChildProcessHost::DidStart, weak_factory_.GetWeakPtr())); |
135 } | 136 } |
136 | 137 |
137 int ChildProcessHost::Join() { | 138 int ChildProcessHost::Join() { |
138 if (controller_) // We use this as a signal that Start was called. | 139 if (controller_) // We use this as a signal that Start was called. |
139 start_child_process_event_.Wait(); | 140 start_child_process_event_.Wait(); |
140 | 141 |
141 controller_ = ChildControllerPtr(); | 142 controller_ = mojom::ChildControllerPtr(); |
142 DCHECK(child_process_.IsValid()); | 143 DCHECK(child_process_.IsValid()); |
143 | 144 |
144 // Ensure the child pipe is closed even if it wasn't yet connected to the | 145 // Ensure the child pipe is closed even if it wasn't yet connected to the |
145 // controller. | 146 // controller. |
146 pipe_holder_->Reject(); | 147 pipe_holder_->Reject(); |
147 | 148 |
148 int rv = -1; | 149 int rv = -1; |
149 LOG_IF(ERROR, !child_process_.WaitForExit(&rv)) | 150 LOG_IF(ERROR, !child_process_.WaitForExit(&rv)) |
150 << "Failed to wait for child process"; | 151 << "Failed to wait for child process"; |
151 | 152 |
152 child_process_.Close(); | 153 child_process_.Close(); |
153 | 154 |
154 return rv; | 155 return rv; |
155 } | 156 } |
156 | 157 |
157 void ChildProcessHost::StartApp( | 158 void ChildProcessHost::StartApp( |
158 InterfaceRequest<Application> application_request, | 159 InterfaceRequest<mojom::Application> application_request, |
159 const ChildController::StartAppCallback& on_app_complete) { | 160 const mojom::ChildController::StartAppCallback& on_app_complete) { |
160 DCHECK(controller_); | 161 DCHECK(controller_); |
161 | 162 |
162 on_app_complete_ = on_app_complete; | 163 on_app_complete_ = on_app_complete; |
163 controller_->StartApp( | 164 controller_->StartApp( |
164 std::move(application_request), | 165 std::move(application_request), |
165 base::Bind(&ChildProcessHost::AppCompleted, weak_factory_.GetWeakPtr())); | 166 base::Bind(&ChildProcessHost::AppCompleted, weak_factory_.GetWeakPtr())); |
166 } | 167 } |
167 | 168 |
168 void ChildProcessHost::ExitNow(int32_t exit_code) { | 169 void ChildProcessHost::ExitNow(int32_t exit_code) { |
169 DCHECK(controller_); | 170 DCHECK(controller_); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { | 281 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { |
281 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; | 282 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; |
282 | 283 |
283 DCHECK(channel_info || | 284 DCHECK(channel_info || |
284 base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")); | 285 base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")); |
285 channel_info_ = channel_info; | 286 channel_info_ = channel_info; |
286 } | 287 } |
287 | 288 |
288 void ChildProcessHost::OnMessagePipeCreated() { | 289 void ChildProcessHost::OnMessagePipeCreated() { |
289 controller_.Bind( | 290 controller_.Bind( |
290 InterfacePtrInfo<ChildController>(pipe_holder_->PassPipe(), 0u)); | 291 InterfacePtrInfo<mojom::ChildController>(pipe_holder_->PassPipe(), 0u)); |
291 MaybeNotifyProcessReady(); | 292 MaybeNotifyProcessReady(); |
292 } | 293 } |
293 | 294 |
294 void ChildProcessHost::MaybeNotifyProcessReady() { | 295 void ChildProcessHost::MaybeNotifyProcessReady() { |
295 if (controller_.is_bound() && child_process_.IsValid()) | 296 if (controller_.is_bound() && child_process_.IsValid()) |
296 process_ready_callback_.Run(child_process_.Pid()); | 297 process_ready_callback_.Run(child_process_.Pid()); |
297 } | 298 } |
298 | 299 |
299 // static | 300 // static |
300 void ChildProcessHost::OnParentMessagePipeCreated( | 301 void ChildProcessHost::OnParentMessagePipeCreated( |
301 scoped_refptr<PipeHolder> holder, | 302 scoped_refptr<PipeHolder> holder, |
302 scoped_refptr<base::TaskRunner> callback_task_runner, | 303 scoped_refptr<base::TaskRunner> callback_task_runner, |
303 const base::Closure& callback, | 304 const base::Closure& callback, |
304 ScopedMessagePipeHandle pipe) { | 305 ScopedMessagePipeHandle pipe) { |
305 holder->SetPipe(std::move(pipe)); | 306 holder->SetPipe(std::move(pipe)); |
306 callback_task_runner->PostTask(FROM_HERE, callback); | 307 callback_task_runner->PostTask(FROM_HERE, callback); |
307 } | 308 } |
308 | 309 |
309 } // namespace shell | 310 } // namespace shell |
310 } // namespace mojo | 311 } // namespace mojo |
OLD | NEW |