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 "content/child/mojo/mojo_application.h" | 5 #include "content/child/mojo/mojo_application.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "content/child/child_process.h" | 10 #include "content/child/child_process.h" |
11 #include "content/common/application_setup.mojom.h" | 11 #include "content/common/application_setup.mojom.h" |
12 #include "content/common/mojo/channel_init.h" | 12 #include "content/common/mojo/channel_init.h" |
13 #include "content/common/mojo/mojo_messages.h" | 13 #include "content/common/mojo/mojo_messages.h" |
14 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
15 #include "mojo/public/cpp/bindings/interface_ptr.h" | 15 #include "mojo/public/cpp/bindings/interface_ptr.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 MojoApplication::MojoApplication( | 19 MojoApplication::MojoApplication( |
20 scoped_refptr<base::SequencedTaskRunner> io_task_runner) | 20 scoped_refptr<base::SequencedTaskRunner> io_task_runner) |
21 : io_task_runner_(io_task_runner) { | 21 : io_task_runner_(io_task_runner), |
| 22 weak_factory_(this) { |
22 DCHECK(io_task_runner_); | 23 DCHECK(io_task_runner_); |
23 } | 24 } |
24 | 25 |
25 MojoApplication::~MojoApplication() { | 26 MojoApplication::~MojoApplication() { |
26 } | 27 } |
27 | 28 |
28 bool MojoApplication::OnMessageReceived(const IPC::Message& msg) { | 29 bool MojoApplication::OnMessageReceived(const IPC::Message& msg) { |
29 bool handled = true; | 30 bool handled = true; |
30 IPC_BEGIN_MESSAGE_MAP(MojoApplication, msg) | 31 IPC_BEGIN_MESSAGE_MAP(MojoApplication, msg) |
31 IPC_MESSAGE_HANDLER(MojoMsg_Activate, OnActivate) | 32 IPC_MESSAGE_HANDLER(MojoMsg_Activate, OnActivate) |
32 IPC_MESSAGE_UNHANDLED(handled = false) | 33 IPC_MESSAGE_UNHANDLED(handled = false) |
33 IPC_END_MESSAGE_MAP() | 34 IPC_END_MESSAGE_MAP() |
34 return handled; | 35 return handled; |
35 } | 36 } |
36 | 37 |
37 void MojoApplication::OnActivate( | 38 void MojoApplication::OnActivate( |
38 const IPC::PlatformFileForTransit& file) { | 39 const IPC::PlatformFileForTransit& file) { |
39 #if defined(OS_POSIX) | 40 #if defined(OS_POSIX) |
40 base::PlatformFile handle = file.fd; | 41 base::PlatformFile handle = file.fd; |
41 #elif defined(OS_WIN) | 42 #elif defined(OS_WIN) |
42 base::PlatformFile handle = file; | 43 base::PlatformFile handle = file; |
43 #endif | 44 #endif |
44 | 45 |
45 mojo::ScopedMessagePipeHandle message_pipe = | 46 channel_init_.Init(handle, io_task_runner_, |
46 channel_init_.Init(handle, io_task_runner_); | 47 base::Bind(&MojoApplication::OnMessagePipeCreated, |
47 DCHECK(message_pipe.is_valid()); | 48 weak_factory_.GetWeakPtr())); |
| 49 } |
| 50 |
| 51 void MojoApplication::OnMessagePipeCreated(mojo::ScopedMessagePipeHandle pipe) { |
| 52 DCHECK(pipe.is_valid()); |
48 | 53 |
49 ApplicationSetupPtr application_setup; | 54 ApplicationSetupPtr application_setup; |
50 application_setup.Bind( | 55 application_setup.Bind( |
51 mojo::InterfacePtrInfo<ApplicationSetup>(std::move(message_pipe), 0u)); | 56 mojo::InterfacePtrInfo<ApplicationSetup>(std::move(pipe), 0u)); |
52 | 57 |
53 mojo::ServiceProviderPtr services; | 58 mojo::ServiceProviderPtr services; |
54 mojo::ServiceProviderPtr exposed_services; | 59 mojo::ServiceProviderPtr exposed_services; |
55 service_registry_.Bind(GetProxy(&exposed_services)); | 60 service_registry_.Bind(GetProxy(&exposed_services)); |
56 application_setup->ExchangeServiceProviders(GetProxy(&services), | 61 application_setup->ExchangeServiceProviders(GetProxy(&services), |
57 std::move(exposed_services)); | 62 std::move(exposed_services)); |
58 service_registry_.BindRemoteServiceProvider(std::move(services)); | 63 service_registry_.BindRemoteServiceProvider(std::move(services)); |
59 } | 64 } |
60 | 65 |
61 } // namespace content | 66 } // namespace content |
OLD | NEW |