OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_CHILD_CONNECTION_H_ | 5 #ifndef CONTENT_BROWSER_MOJO_MOJO_CHILD_CONNECTION_H_ |
6 #define CONTENT_BROWSER_MOJO_MOJO_CHILD_CONNECTION_H_ | 6 #define CONTENT_BROWSER_MOJO_MOJO_CHILD_CONNECTION_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/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" |
12 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
| 15 #include "base/sequenced_task_runner.h" |
| 16 #include "services/shell/public/cpp/interface_provider.h" |
| 17 #include "services/shell/public/cpp/interface_registry.h" |
13 #include "services/shell/public/interfaces/connector.mojom.h" | 18 #include "services/shell/public/interfaces/connector.mojom.h" |
14 | 19 |
15 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
16 #include "content/public/browser/android/service_registry_android.h" | 21 #include "content/public/browser/android/service_registry_android.h" |
17 #endif | 22 #endif |
18 | 23 |
19 namespace shell { | 24 namespace shell { |
20 class Connection; | 25 class Connection; |
21 class Connector; | 26 class Connector; |
22 } | 27 } |
23 | 28 |
24 namespace content { | 29 namespace content { |
25 | 30 |
26 // Helper class to establish a connection between the shell and a single child | 31 // Helper class to establish a connection between the shell and a single child |
27 // process. Process hosts can use this when launching new processes which | 32 // process. Process hosts can use this when launching new processes which |
28 // should be registered with the shell. | 33 // should be registered with the shell. |
29 class MojoChildConnection { | 34 class MojoChildConnection { |
30 public: | 35 public: |
31 // Prepares a new child connection for a child process which will be | 36 // Prepares a new child connection for a child process which will be |
32 // identified to the shell as |application_name|. |instance_id| must be | 37 // identified to the shell as |application_name|. |instance_id| must be |
33 // unique among all child connections using the same |application_name|. | 38 // unique among all child connections using the same |application_name|. |
34 // |connector| is the connector to use to establish the connection. | 39 // |connector| is the connector to use to establish the connection. |
35 MojoChildConnection(const std::string& application_name, | 40 MojoChildConnection(const std::string& application_name, |
36 const std::string& instance_id, | 41 const std::string& instance_id, |
37 const std::string& child_token, | 42 const std::string& child_token, |
38 shell::Connector* connector); | 43 shell::Connector* connector, |
| 44 scoped_refptr<base::SequencedTaskRunner> io_task_runner); |
39 ~MojoChildConnection(); | 45 ~MojoChildConnection(); |
40 | 46 |
41 shell::Connection* connection() const { | 47 shell::InterfaceRegistry* GetInterfaceRegistry() { |
42 return connection_.get(); | 48 return &interface_registry_; |
| 49 } |
| 50 |
| 51 shell::InterfaceProvider* GetRemoteInterfaces() { |
| 52 return &remote_interfaces_; |
43 } | 53 } |
44 | 54 |
45 // A token which must be passed to the child process via | 55 // A token which must be passed to the child process via |
46 // |switches::kPrimordialPipeToken| in order for the child to initialize its | 56 // |switches::kPrimordialPipeToken| in order for the child to initialize its |
47 // end of the shell connection pipe. | 57 // end of the shell connection pipe. |
48 std::string service_token() const { return service_token_; } | 58 std::string service_token() const { return service_token_; } |
49 | 59 |
50 // Sets the child connection's process handle. This should be called as soon | 60 // Sets the child connection's process handle. This should be called as soon |
51 // as the process has been launched, and the connection will not be fully | 61 // as the process has been launched, and the connection will not be fully |
52 // functional until this is called. | 62 // functional until this is called. |
53 void SetProcessHandle(base::ProcessHandle handle); | 63 void SetProcessHandle(base::ProcessHandle handle); |
54 | 64 |
55 #if defined(OS_ANDROID) | 65 #if defined(OS_ANDROID) |
56 ServiceRegistryAndroid* service_registry_android() { | 66 ServiceRegistryAndroid* service_registry_android() { |
57 return service_registry_android_.get(); | 67 return service_registry_android_.get(); |
58 } | 68 } |
59 #endif | 69 #endif |
60 | 70 |
61 private: | 71 private: |
| 72 class IOThreadContext; |
| 73 |
| 74 void GetInterface(const mojo::String& interface_name, |
| 75 mojo::ScopedMessagePipeHandle request_handle); |
| 76 |
| 77 scoped_refptr<IOThreadContext> context_; |
| 78 |
62 const std::string service_token_; | 79 const std::string service_token_; |
63 std::unique_ptr<shell::Connection> connection_; | 80 |
64 shell::mojom::PIDReceiverPtr pid_receiver_; | 81 shell::InterfaceRegistry interface_registry_; |
| 82 shell::InterfaceProvider remote_interfaces_; |
| 83 |
65 #if defined(OS_ANDROID) | 84 #if defined(OS_ANDROID) |
66 std::unique_ptr<ServiceRegistryAndroid> service_registry_android_; | 85 std::unique_ptr<ServiceRegistryAndroid> service_registry_android_; |
67 #endif | 86 #endif |
68 | 87 |
| 88 base::WeakPtrFactory<MojoChildConnection> weak_factory_; |
| 89 |
69 DISALLOW_COPY_AND_ASSIGN(MojoChildConnection); | 90 DISALLOW_COPY_AND_ASSIGN(MojoChildConnection); |
70 }; | 91 }; |
71 | 92 |
72 } // namespace content | 93 } // namespace content |
73 | 94 |
74 #endif // CONTENT_BROWSER_MOJO_MOJO_CHILD_CONNECTION_H_ | 95 #endif // CONTENT_BROWSER_MOJO_MOJO_CHILD_CONNECTION_H_ |
OLD | NEW |