Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / mojo / shell / app_child_process_host.cc
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.
4
5 #include "mojo/shell/app_child_process_host.h"
6
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"
13
14 namespace mojo {
15 namespace shell {
16
17 AppChildProcessHost::AppChildProcessHost(
18     Context* context,
19     AppChildControllerClient* controller_client)
20     : ChildProcessHost(context, this, ChildProcess::TYPE_APP),
21       controller_client_(controller_client),
22       channel_info_(NULL) {
23 }
24
25 AppChildProcessHost::~AppChildProcessHost() {
26 }
27
28 void AppChildProcessHost::WillStart() {
29   DCHECK(platform_channel()->is_valid());
30
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()));
37
38   controller_.Bind(handle.Pass());
39   controller_->SetClient(controller_client_);
40 }
41
42 void AppChildProcessHost::DidStart(bool success) {
43   DVLOG(2) << "AppChildProcessHost::DidStart()";
44
45   if (!success) {
46     LOG(ERROR) << "Failed to start app child process";
47     controller_client_->AppCompleted(MOJO_RESULT_UNKNOWN);
48     return;
49   }
50 }
51
52 // Callback for |embedder::CreateChannel()|.
53 void AppChildProcessHost::DidCreateChannel(
54     embedder::ChannelInfo* channel_info) {
55   DVLOG(2) << "AppChildProcessHost::DidCreateChannel()";
56
57   CHECK(channel_info);
58   channel_info_ = channel_info;
59 }
60
61 }  // namespace shell
62 }  // namespace mojo