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 #ifndef CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ | 5 #ifndef CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ |
6 #define CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ | 6 #define CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "content/common/application_setup.mojom.h" | 12 #include "content/common/application_setup.mojom.h" |
13 #include "content/common/mojo/channel_init.h" | 13 #include "content/common/mojo/channel_init.h" |
14 #include "content/common/mojo/service_registry_impl.h" | 14 #include "content/common/mojo/service_registry_impl.h" |
15 #include "mojo/edk/embedder/scoped_platform_handle.h" | 15 #include "mojo/edk/embedder/scoped_platform_handle.h" |
16 #include "mojo/public/cpp/system/message_pipe.h" | 16 #include "mojo/public/cpp/system/message_pipe.h" |
17 | 17 |
18 #if defined(OS_ANDROID) | |
19 #include "content/browser/mojo/service_registry_android.h" | |
20 #endif | |
21 | |
22 namespace IPC { | 18 namespace IPC { |
23 class Sender; | 19 class Sender; |
24 } | 20 } |
25 | 21 |
26 namespace content { | 22 namespace content { |
27 | 23 |
28 // MojoApplicationHost represents the code needed on the browser side to setup | 24 // MojoApplicationHost represents the code needed on the browser side to setup |
29 // a child process as a Mojo application via Chrome IPC. The child process | 25 // a child process as a Mojo application via Chrome IPC. The child process |
30 // should use MojoApplication to handle messages generated by an instance of | 26 // should use MojoApplication to handle messages generated by an instance of |
31 // MojoApplicationHost. MojoApplicationHost makes the ServiceRegistry interface | 27 // MojoApplicationHost. MojoApplicationHost makes the ServiceRegistry interface |
32 // available so that child-provided services can be invoked. | 28 // available so that child-provided services can be invoked. |
33 class CONTENT_EXPORT MojoApplicationHost { | 29 class CONTENT_EXPORT MojoApplicationHost { |
34 public: | 30 public: |
35 MojoApplicationHost(); | 31 MojoApplicationHost(); |
36 ~MojoApplicationHost(); | 32 ~MojoApplicationHost(); |
37 | 33 |
38 // Two-phase initialization: | 34 // Two-phase initialization: |
39 // 1- Init makes service_registry() available synchronously. | 35 // 1- Init makes service_registry() available synchronously. |
40 // 2- Activate establishes the actual connection to the peer process. | 36 // 2- Activate establishes the actual connection to the peer process. |
41 bool Init(); | 37 bool Init(); |
42 void Activate(IPC::Sender* sender, base::ProcessHandle process_handle); | 38 void Activate(IPC::Sender* sender, base::ProcessHandle process_handle); |
43 | 39 |
44 ServiceRegistry* service_registry() { return &service_registry_; } | 40 ServiceRegistry* service_registry() { return &service_registry_; } |
45 | 41 |
46 #if defined(OS_ANDROID) | |
47 ServiceRegistryAndroid* service_registry_android() { | |
48 return service_registry_android_.get(); | |
49 } | |
50 #endif | |
51 | |
52 void OverrideIOTaskRunnerForTest( | 42 void OverrideIOTaskRunnerForTest( |
53 scoped_refptr<base::TaskRunner> io_task_runner); | 43 scoped_refptr<base::TaskRunner> io_task_runner); |
54 | 44 |
55 private: | 45 private: |
56 ChannelInit channel_init_; | 46 ChannelInit channel_init_; |
57 mojo::edk::ScopedPlatformHandle client_handle_; | 47 mojo::edk::ScopedPlatformHandle client_handle_; |
58 | 48 |
59 bool did_activate_; | 49 bool did_activate_; |
60 | 50 |
61 scoped_ptr<mojom::ApplicationSetup> application_setup_; | 51 scoped_ptr<mojom::ApplicationSetup> application_setup_; |
62 ServiceRegistryImpl service_registry_; | 52 ServiceRegistryImpl service_registry_; |
63 | 53 |
64 scoped_refptr<base::TaskRunner> io_task_runner_override_; | 54 scoped_refptr<base::TaskRunner> io_task_runner_override_; |
65 | 55 |
66 #if defined(OS_ANDROID) | |
67 scoped_ptr<ServiceRegistryAndroid> service_registry_android_; | |
68 #endif | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost); | 56 DISALLOW_COPY_AND_ASSIGN(MojoApplicationHost); |
71 }; | 57 }; |
72 | 58 |
73 } // namespace content | 59 } // namespace content |
74 | 60 |
75 #endif // CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ | 61 #endif // CONTENT_BROWSER_MOJO_MOJO_APPLICATION_HOST_H_ |
OLD | NEW |