| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), | 78 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), |
| 79 base::Bind(&ChildProcessHost::DidStart, | 79 base::Bind(&ChildProcessHost::DidStart, |
| 80 weak_factory_.GetWeakPtr(), callback)); | 80 weak_factory_.GetWeakPtr(), callback)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 int ChildProcessHost::Join() { | 83 int ChildProcessHost::Join() { |
| 84 if (controller_) // We use this as a signal that Start was called. | 84 if (controller_) // We use this as a signal that Start was called. |
| 85 start_child_process_event_.Wait(); | 85 start_child_process_event_.Wait(); |
| 86 | 86 |
| 87 controller_ = mojom::ChildControllerPtr(); | 87 controller_ = mojom::ChildControllerPtr(); |
| 88 DCHECK(child_process_.IsValid()); | 88 // This host may be hosting a child process whose lifetime is controlled |
| 89 // elsewhere. In this case we have no known process handle to wait on. |
| 90 if (child_process_.IsValid()) { |
| 91 int rv = -1; |
| 92 LOG_IF(ERROR, !child_process_.WaitForExit(&rv)) |
| 93 << "Failed to wait for child process"; |
| 89 | 94 |
| 90 int rv = -1; | 95 child_process_.Close(); |
| 91 LOG_IF(ERROR, !child_process_.WaitForExit(&rv)) | 96 return rv; |
| 92 << "Failed to wait for child process"; | 97 } |
| 93 | 98 |
| 94 child_process_.Close(); | 99 return 0; |
| 95 | |
| 96 return rv; | |
| 97 } | 100 } |
| 98 | 101 |
| 99 void ChildProcessHost::StartApp( | 102 void ChildProcessHost::StartApp( |
| 100 InterfaceRequest<mojom::ShellClient> request, | 103 InterfaceRequest<mojom::ShellClient> request, |
| 101 const mojom::ChildController::StartAppCallback& on_app_complete) { | 104 const mojom::ChildController::StartAppCallback& on_app_complete) { |
| 102 DCHECK(controller_); | 105 DCHECK(controller_); |
| 103 | 106 |
| 107 // In this case the process must have already been launched. |
| 108 start_child_process_event_.Signal(); |
| 109 |
| 104 on_app_complete_ = on_app_complete; | 110 on_app_complete_ = on_app_complete; |
| 105 controller_->StartApp( | 111 controller_->StartApp( |
| 106 std::move(request), | 112 std::move(request), |
| 107 base::Bind(&ChildProcessHost::AppCompleted, weak_factory_.GetWeakPtr())); | 113 base::Bind(&ChildProcessHost::AppCompleted, weak_factory_.GetWeakPtr())); |
| 108 } | 114 } |
| 109 | 115 |
| 110 void ChildProcessHost::ExitNow(int32_t exit_code) { | 116 void ChildProcessHost::ExitNow(int32_t exit_code) { |
| 111 DCHECK(controller_); | 117 DCHECK(controller_); |
| 112 | 118 |
| 113 controller_->ExitNow(exit_code); | 119 controller_->ExitNow(exit_code); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 void ChildProcessHost::AppCompleted(int32_t result) { | 231 void ChildProcessHost::AppCompleted(int32_t result) { |
| 226 if (!on_app_complete_.is_null()) { | 232 if (!on_app_complete_.is_null()) { |
| 227 auto on_app_complete = on_app_complete_; | 233 auto on_app_complete = on_app_complete_; |
| 228 on_app_complete_.reset(); | 234 on_app_complete_.reset(); |
| 229 on_app_complete.Run(result); | 235 on_app_complete.Run(result); |
| 230 } | 236 } |
| 231 } | 237 } |
| 232 | 238 |
| 233 } // namespace shell | 239 } // namespace shell |
| 234 } // namespace mojo | 240 } // namespace mojo |
| OLD | NEW |