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