| 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 "shell/child_process_host.h" | 5 #include "shell/child_process_host.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.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 "shell/context.h" | 17 #include "shell/context.h" |
| 18 #include "shell/switches.h" | 18 #include "shell/switches.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 namespace shell { | 21 namespace shell { |
| 22 | 22 |
| 23 ChildProcessHost::ChildProcessHost(Context* context, Delegate* delegate) | 23 ChildProcessHost::ChildProcessHost(Context* context) : context_(context) { |
| 24 : context_(context), delegate_(delegate) { | |
| 25 DCHECK(delegate); | |
| 26 platform_channel_ = platform_channel_pair_.PassServerHandle(); | 24 platform_channel_ = platform_channel_pair_.PassServerHandle(); |
| 27 CHECK(platform_channel_.is_valid()); | 25 CHECK(platform_channel_.is_valid()); |
| 28 } | 26 } |
| 29 | 27 |
| 30 ChildProcessHost::~ChildProcessHost() { | 28 ChildProcessHost::~ChildProcessHost() { |
| 31 if (child_process_.IsValid()) { | 29 if (child_process_.IsValid()) { |
| 32 LOG(WARNING) << "Destroying ChildProcessHost with unjoined child"; | 30 LOG(WARNING) << "Destroying ChildProcessHost with unjoined child"; |
| 33 child_process_.Close(); | 31 child_process_.Close(); |
| 34 } | 32 } |
| 35 } | 33 } |
| 36 | 34 |
| 37 void ChildProcessHost::Start() { | 35 void ChildProcessHost::Start() { |
| 38 DCHECK(!child_process_.IsValid()); | 36 DCHECK(!child_process_.IsValid()); |
| 39 | 37 |
| 40 delegate_->WillStart(); | 38 WillStart(); |
| 41 | 39 |
| 42 CHECK(base::PostTaskAndReplyWithResult( | 40 CHECK(base::PostTaskAndReplyWithResult( |
| 43 context_->task_runners()->blocking_pool(), FROM_HERE, | 41 context_->task_runners()->blocking_pool(), FROM_HERE, |
| 44 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), | 42 base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), |
| 45 base::Bind(&ChildProcessHost::DidLaunch, base::Unretained(this)))); | 43 base::Bind(&ChildProcessHost::DidStart, base::Unretained(this)))); |
| 46 } | 44 } |
| 47 | 45 |
| 48 int ChildProcessHost::Join() { | 46 int ChildProcessHost::Join() { |
| 49 DCHECK(child_process_.IsValid()); | 47 DCHECK(child_process_.IsValid()); |
| 50 int rv = -1; | 48 int rv = -1; |
| 51 LOG_IF(ERROR, !child_process_.WaitForExit(&rv)) | 49 LOG_IF(ERROR, !child_process_.WaitForExit(&rv)) |
| 52 << "Failed to wait for child process"; | 50 << "Failed to wait for child process"; |
| 53 child_process_.Close(); | 51 child_process_.Close(); |
| 54 return rv; | 52 return rv; |
| 55 } | 53 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 80 DVLOG(2) << "Launching child with command line: " | 78 DVLOG(2) << "Launching child with command line: " |
| 81 << child_command_line.GetCommandLineString(); | 79 << child_command_line.GetCommandLineString(); |
| 82 child_process_ = base::LaunchProcess(child_command_line, options); | 80 child_process_ = base::LaunchProcess(child_command_line, options); |
| 83 if (!child_process_.IsValid()) | 81 if (!child_process_.IsValid()) |
| 84 return false; | 82 return false; |
| 85 | 83 |
| 86 platform_channel_pair_.ChildProcessLaunched(); | 84 platform_channel_pair_.ChildProcessLaunched(); |
| 87 return true; | 85 return true; |
| 88 } | 86 } |
| 89 | 87 |
| 90 void ChildProcessHost::DidLaunch(bool success) { | |
| 91 delegate_->DidStart(success); | |
| 92 } | |
| 93 | |
| 94 } // namespace shell | 88 } // namespace shell |
| 95 } // namespace mojo | 89 } // namespace mojo |
| OLD | NEW |