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_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_ | 5 #ifndef CONTENT_PUBLIC_COMMON_SERVICE_MANAGER_CONNECTION_H_ |
6 #define CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_ | 6 #define CONTENT_PUBLIC_COMMON_SERVICE_MANAGER_CONNECTION_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
13 #include "content/public/common/mojo_application_info.h" | 13 #include "content/public/common/service_info.h" |
14 #include "services/shell/public/cpp/identity.h" | 14 #include "services/shell/public/cpp/identity.h" |
15 #include "services/shell/public/interfaces/service.mojom.h" | 15 #include "services/shell/public/interfaces/service.mojom.h" |
16 | 16 |
17 namespace shell { | 17 namespace shell { |
18 class Connection; | 18 class Connection; |
19 class Connector; | 19 class Connector; |
20 class InterfaceProvider; | 20 class InterfaceProvider; |
21 class InterfaceRegistry; | 21 class InterfaceRegistry; |
22 } | 22 } |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 | 25 |
26 class ConnectionFilter; | 26 class ConnectionFilter; |
27 | 27 |
28 // Encapsulates a connection to a //services/shell. | 28 // Encapsulates a connection to a //services/shell. |
29 // Access a global instance on the thread the ServiceContext was bound by | 29 // Access a global instance on the thread the ServiceContext was bound by |
30 // calling Holder::Get(). | 30 // calling Holder::Get(). |
31 // Clients can add shell::Service implementations whose exposed interfaces | 31 // Clients can add shell::Service implementations whose exposed interfaces |
32 // will be exposed to inbound connections to this object's Service. | 32 // will be exposed to inbound connections to this object's Service. |
33 // Alternatively clients can define named services that will be constructed when | 33 // Alternatively clients can define named services that will be constructed when |
34 // requests for those service names are received. | 34 // requests for those service names are received. |
35 // Clients must call any of the registration methods when receiving | 35 // Clients must call any of the registration methods when receiving |
36 // ContentBrowserClient::RegisterInProcessMojoApplications(). | 36 // ContentBrowserClient::RegisterInProcessServices(). |
37 class CONTENT_EXPORT MojoShellConnection { | 37 class CONTENT_EXPORT ServiceManagerConnection { |
38 public: | 38 public: |
39 using ServiceRequestHandler = | 39 using ServiceRequestHandler = |
40 base::Callback<void(shell::mojom::ServiceRequest)>; | 40 base::Callback<void(shell::mojom::ServiceRequest)>; |
41 using Factory = base::Callback<std::unique_ptr<MojoShellConnection>(void)>; | 41 using Factory = |
| 42 base::Callback<std::unique_ptr<ServiceManagerConnection>(void)>; |
42 | 43 |
43 // Stores an instance of |connection| in TLS for the current process. Must be | 44 // Stores an instance of |connection| in TLS for the current process. Must be |
44 // called on the thread the connection was created on. | 45 // called on the thread the connection was created on. |
45 static void SetForProcess(std::unique_ptr<MojoShellConnection> connection); | 46 static void SetForProcess( |
| 47 std::unique_ptr<ServiceManagerConnection> connection); |
46 | 48 |
47 // Returns the per-process instance, or nullptr if the Shell connection has | 49 // Returns the per-process instance, or nullptr if the Service Manager |
48 // not yet been bound. Must be called on the thread the connection was created | 50 // connection has not yet been bound. Must be called on the thread the |
49 // on. | 51 // connection was created on. |
50 static MojoShellConnection* GetForProcess(); | 52 static ServiceManagerConnection* GetForProcess(); |
51 | 53 |
52 // Destroys the per-process instance. Must be called on the thread the | 54 // Destroys the per-process instance. Must be called on the thread the |
53 // connection was created on. | 55 // connection was created on. |
54 static void DestroyForProcess(); | 56 static void DestroyForProcess(); |
55 | 57 |
56 virtual ~MojoShellConnection(); | 58 virtual ~ServiceManagerConnection(); |
57 | 59 |
58 // Sets the factory used to create the MojoShellConnection. This must be | 60 // Sets the factory used to create the ServiceManagerConnection. This must be |
59 // called before the MojoShellConnection has been created. | 61 // called before the ServiceManagerConnection has been created. |
60 static void SetFactoryForTest(Factory* factory); | 62 static void SetFactoryForTest(Factory* factory); |
61 | 63 |
62 // Creates a MojoShellConnection from |request|. The connection binds | 64 // Creates a ServiceManagerConnection from |request|. The connection binds |
63 // its interfaces and accept new connections on |io_task_runner| only. Note | 65 // its interfaces and accept new connections on |io_task_runner| only. Note |
64 // that no incoming connections are accepted until Start() is called. | 66 // that no incoming connections are accepted until Start() is called. |
65 static std::unique_ptr<MojoShellConnection> Create( | 67 static std::unique_ptr<ServiceManagerConnection> Create( |
66 shell::mojom::ServiceRequest request, | 68 shell::mojom::ServiceRequest request, |
67 scoped_refptr<base::SequencedTaskRunner> io_task_runner); | 69 scoped_refptr<base::SequencedTaskRunner> io_task_runner); |
68 | 70 |
69 // Begins accepting incoming connections. Connection filters MUST be added | 71 // Begins accepting incoming connections. Connection filters MUST be added |
70 // before calling this in order to avoid races. See AddConnectionFilter() | 72 // before calling this in order to avoid races. See AddConnectionFilter() |
71 // below. | 73 // below. |
72 virtual void Start() = 0; | 74 virtual void Start() = 0; |
73 | 75 |
74 // Sets a closure to be invoked once the connection receives an Initialize() | 76 // Sets a closure to be invoked once the connection receives an Initialize() |
75 // request from the shell. | 77 // request from the shell. |
76 virtual void SetInitializeHandler(const base::Closure& handler) = 0; | 78 virtual void SetInitializeHandler(const base::Closure& handler) = 0; |
77 | 79 |
78 // Returns the shell::Connector received via this connection's Service | 80 // Returns the shell::Connector received via this connection's Service |
79 // implementation. Use this to initiate connections as this object's Identity. | 81 // implementation. Use this to initiate connections as this object's Identity. |
80 virtual shell::Connector* GetConnector() = 0; | 82 virtual shell::Connector* GetConnector() = 0; |
81 | 83 |
82 // Returns this connection's identity with the shell. Connections initiated | 84 // Returns this connection's identity with the Service Manager. Connections |
83 // via the shell::Connector returned by GetConnector() will use this. | 85 // initiated via the shell::Connector returned by GetConnector() will use |
| 86 // this. |
84 virtual const shell::Identity& GetIdentity() const = 0; | 87 virtual const shell::Identity& GetIdentity() const = 0; |
85 | 88 |
86 // Sets a closure that is called when the connection is lost. Note that | 89 // Sets a closure that is called when the connection is lost. Note that |
87 // connection may already have been closed, in which case |closure| will be | 90 // connection may already have been closed, in which case |closure| will be |
88 // run immediately before returning from this function. | 91 // run immediately before returning from this function. |
89 virtual void SetConnectionLostClosure(const base::Closure& closure) = 0; | 92 virtual void SetConnectionLostClosure(const base::Closure& closure) = 0; |
90 | 93 |
91 // Provides an InterfaceRegistry to forward incoming interface requests to | 94 // Provides an InterfaceRegistry to forward incoming interface requests to |
92 // on the MojoShellConnection's own thread if they aren't bound by the | 95 // on the ServiceManagerConnection's own thread if they aren't bound by the |
93 // connection's internal InterfaceRegistry on the IO thread. | 96 // connection's internal InterfaceRegistry on the IO thread. |
94 // | 97 // |
95 // Also configures |interface_provider| to forward all of its outgoing | 98 // Also configures |interface_provider| to forward all of its outgoing |
96 // interface requests to the connection's internal remote interface provider. | 99 // interface requests to the connection's internal remote interface provider. |
97 // | 100 // |
98 // Note that neither |interface_registry| or |interface_provider| is owned | 101 // Note that neither |interface_registry| or |interface_provider| is owned |
99 // and both MUST outlive the MojoShellConnection. | 102 // and both MUST outlive the ServiceManagerConnection. |
100 // | 103 // |
101 // TODO(rockot): Remove this. It's a temporary solution to avoid porting all | 104 // TODO(rockot): Remove this. It's a temporary solution to avoid porting all |
102 // relevant code to ConnectionFilters at once. | 105 // relevant code to ConnectionFilters at once. |
103 virtual void SetupInterfaceRequestProxies( | 106 virtual void SetupInterfaceRequestProxies( |
104 shell::InterfaceRegistry* registry, | 107 shell::InterfaceRegistry* registry, |
105 shell::InterfaceProvider* provider) = 0; | 108 shell::InterfaceProvider* provider) = 0; |
106 | 109 |
107 static const int kInvalidConnectionFilterId = 0; | 110 static const int kInvalidConnectionFilterId = 0; |
108 | 111 |
109 // Allows the caller to filter inbound connections and/or expose interfaces | 112 // Allows the caller to filter inbound connections and/or expose interfaces |
(...skipping 10 matching lines...) Expand all Loading... |
120 std::unique_ptr<ConnectionFilter> filter) = 0; | 123 std::unique_ptr<ConnectionFilter> filter) = 0; |
121 | 124 |
122 // Removes a filter using the id value returned by AddConnectionFilter(). | 125 // Removes a filter using the id value returned by AddConnectionFilter(). |
123 // Removal (and destruction) happens asynchronously on the IO thread. | 126 // Removal (and destruction) happens asynchronously on the IO thread. |
124 virtual void RemoveConnectionFilter(int filter_id) = 0; | 127 virtual void RemoveConnectionFilter(int filter_id) = 0; |
125 | 128 |
126 // Adds an embedded service to this connection's ServiceFactory. | 129 // Adds an embedded service to this connection's ServiceFactory. |
127 // |info| provides details on how to construct new instances of the | 130 // |info| provides details on how to construct new instances of the |
128 // service when an incoming connection is made to |name|. | 131 // service when an incoming connection is made to |name|. |
129 virtual void AddEmbeddedService(const std::string& name, | 132 virtual void AddEmbeddedService(const std::string& name, |
130 const MojoApplicationInfo& info) = 0; | 133 const ServiceInfo& info) = 0; |
131 | 134 |
132 // Adds a generic ServiceRequestHandler for a given service name. This | 135 // Adds a generic ServiceRequestHandler for a given service name. This |
133 // will be used to satisfy any incoming calls to CreateService() which | 136 // will be used to satisfy any incoming calls to CreateService() which |
134 // reference the given name. | 137 // reference the given name. |
135 // | 138 // |
136 // For in-process services, it is preferable to use |AddEmbeddedService()| as | 139 // For in-process services, it is preferable to use |AddEmbeddedService()| as |
137 // defined above. | 140 // defined above. |
138 virtual void AddServiceRequestHandler( | 141 virtual void AddServiceRequestHandler( |
139 const std::string& name, | 142 const std::string& name, |
140 const ServiceRequestHandler& handler) = 0; | 143 const ServiceRequestHandler& handler) = 0; |
141 }; | 144 }; |
142 | 145 |
143 } // namespace content | 146 } // namespace content |
144 | 147 |
145 #endif // CONTENT_PUBLIC_COMMON_MOJO_SHELL_CONNECTION_H_ | 148 #endif // CONTENT_PUBLIC_COMMON_SERVICE_MANAGER_CONNECTION_H_ |
OLD | NEW |