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
3 // found in the LICENSE file.
5 #include "mojo/shell/app_child_process_host.h"
7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h"
9 #include "mojo/embedder/embedder.h"
10 #include "mojo/public/cpp/system/core.h"
11 #include "mojo/shell/context.h"
12 #include "mojo/shell/task_runners.h"
17 AppChildProcessHost::AppChildProcessHost(
19 AppChildControllerClient* controller_client)
20 : ChildProcessHost(context, this, ChildProcess::TYPE_APP),
21 controller_client_(controller_client),
25 AppChildProcessHost::~AppChildProcessHost() {
28 void AppChildProcessHost::WillStart() {
29 DCHECK(platform_channel()->is_valid());
31 mojo::ScopedMessagePipeHandle handle(embedder::CreateChannel(
32 platform_channel()->Pass(),
33 context()->task_runners()->io_runner(),
34 base::Bind(&AppChildProcessHost::DidCreateChannel,
35 base::Unretained(this)),
36 base::MessageLoop::current()->message_loop_proxy()));
38 controller_.Bind(handle.Pass());
39 controller_->SetClient(controller_client_);
42 void AppChildProcessHost::DidStart(bool success) {
43 DVLOG(2) << "AppChildProcessHost::DidStart()";
46 LOG(ERROR) << "Failed to start app child process";
47 controller_client_->AppCompleted(MOJO_RESULT_UNKNOWN);
52 // Callback for |embedder::CreateChannel()|.
53 void AppChildProcessHost::DidCreateChannel(
54 embedder::ChannelInfo* channel_info) {
55 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()";
58 channel_info_ = channel_info;