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 "content/child/mojo/mojo_application.h"
7 #include "content/child/child_process.h"
8 #include "content/common/application_setup.mojom.h"
9 #include "content/common/mojo/channel_init.h"
10 #include "content/common/mojo/mojo_messages.h"
11 #include "ipc/ipc_message.h"
12 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h"
16 MojoApplication::MojoApplication(
17 scoped_refptr
<base::SequencedTaskRunner
> io_task_runner
)
18 : io_task_runner_(io_task_runner
) {
19 DCHECK(io_task_runner_
);
22 MojoApplication::~MojoApplication() {
25 bool MojoApplication::OnMessageReceived(const IPC::Message
& msg
) {
27 IPC_BEGIN_MESSAGE_MAP(MojoApplication
, msg
)
28 IPC_MESSAGE_HANDLER(MojoMsg_Activate
, OnActivate
)
29 IPC_MESSAGE_UNHANDLED(handled
= false)
34 void MojoApplication::OnActivate(
35 const IPC::PlatformFileForTransit
& file
) {
37 base::PlatformFile handle
= file
.fd
;
39 base::PlatformFile handle
= file
;
42 mojo::ScopedMessagePipeHandle message_pipe
=
43 channel_init_
.Init(handle
, io_task_runner_
);
44 DCHECK(message_pipe
.is_valid());
46 ApplicationSetupPtr application_setup
;
47 application_setup
.Bind(
48 mojo::InterfacePtrInfo
<ApplicationSetup
>(message_pipe
.Pass(), 0u));
50 mojo::ServiceProviderPtr services
;
51 mojo::ServiceProviderPtr exposed_services
;
52 service_registry_
.Bind(GetProxy(&exposed_services
));
53 application_setup
->ExchangeServiceProviders(GetProxy(&services
),
54 exposed_services
.Pass());
55 service_registry_
.BindRemoteServiceProvider(services
.Pass());
58 } // namespace content