Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(550)

Unified Diff: shell/child_process_host.cc

Issue 1056593002: Merge AppChildProcessHost into ChildProcessHost. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « shell/child_process_host.h ('k') | shell/child_process_host_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: shell/child_process_host.cc
diff --git a/shell/child_process_host.cc b/shell/child_process_host.cc
index a88b3ed6a617cde84708d459fff109b2704f9e52..c4a3daab1741d277319052a79dcaaa1aa0a83e6c 100644
--- a/shell/child_process_host.cc
+++ b/shell/child_process_host.cc
@@ -10,32 +10,39 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
+#include "base/message_loop/message_loop.h"
#include "base/process/kill.h"
#include "base/process/launch.h"
#include "base/task_runner.h"
#include "base/task_runner_util.h"
+#include "mojo/edk/embedder/embedder.h"
+#include "mojo/public/cpp/system/message_pipe.h"
#include "shell/context.h"
#include "shell/switches.h"
+#include "shell/task_runners.h"
namespace mojo {
namespace shell {
-ChildProcessHost::ChildProcessHost(Context* context) : context_(context) {
- platform_channel_ = platform_channel_pair_.PassServerHandle();
- CHECK(platform_channel_.is_valid());
+ChildProcessHost::ChildProcessHost(Context* context)
+ : context_(context), channel_info_(nullptr) {
}
ChildProcessHost::~ChildProcessHost() {
- if (child_process_.IsValid()) {
- LOG(WARNING) << "Destroying ChildProcessHost with unjoined child";
- child_process_.Close();
- }
+ DCHECK(!child_process_.IsValid());
}
void ChildProcessHost::Start() {
DCHECK(!child_process_.IsValid());
- WillStart();
+ ScopedMessagePipeHandle handle(embedder::CreateChannel(
+ platform_channel_pair_.PassServerHandle(),
+ context_->task_runners()->io_runner(),
+ base::Bind(&ChildProcessHost::DidCreateChannel, base::Unretained(this)),
+ base::MessageLoop::current()->message_loop_proxy()));
+
+ controller_.Bind(handle.Pass());
+ controller_.set_error_handler(this);
CHECK(base::PostTaskAndReplyWithResult(
context_->task_runners()->blocking_pool(), FROM_HERE,
@@ -52,6 +59,43 @@ int ChildProcessHost::Join() {
return rv;
}
+void ChildProcessHost::StartApp(
+ const String& app_path,
+ bool clean_app_path,
+ InterfaceRequest<Application> application_request,
+ const AppChildController::StartAppCallback& on_app_complete) {
+ DCHECK(controller_);
+
+ on_app_complete_ = on_app_complete;
+ controller_->StartApp(
+ app_path, clean_app_path, application_request.Pass(),
+ base::Bind(&ChildProcessHost::AppCompleted, base::Unretained(this)));
+}
+
+void ChildProcessHost::ExitNow(int32_t exit_code) {
+ DCHECK(controller_);
+
+ controller_->ExitNow(exit_code);
+}
+
+void ChildProcessHost::DidStart(bool success) {
+ DVLOG(2) << "ChildProcessHost::DidStart()";
+
+ if (!success) {
+ LOG(ERROR) << "Failed to start app child process";
+ AppCompleted(MOJO_RESULT_UNKNOWN);
+ return;
+ }
+}
+
+// Callback for |embedder::CreateChannel()|.
+void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) {
+ DVLOG(2) << "ChildProcessHost::DidCreateChannel()";
+
+ CHECK(channel_info);
+ channel_info_ = channel_info;
+}
+
bool ChildProcessHost::DoLaunch() {
static const char* kForwardSwitches[] = {
switches::kTraceToConsole, switches::kV, switches::kVModule,
@@ -85,5 +129,17 @@ bool ChildProcessHost::DoLaunch() {
return true;
}
+void ChildProcessHost::AppCompleted(int32_t result) {
+ if (!on_app_complete_.is_null()) {
+ auto on_app_complete = on_app_complete_;
+ on_app_complete_.reset();
+ on_app_complete.Run(result);
+ }
+}
+
+void ChildProcessHost::OnConnectionError() {
+ AppCompleted(MOJO_RESULT_UNKNOWN);
+}
+
} // namespace shell
} // namespace mojo
« no previous file with comments | « shell/child_process_host.h ('k') | shell/child_process_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698