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_SERVICE_MANAGER_CONNECTION_H_ | 5 #ifndef CONTENT_PUBLIC_COMMON_SERVICE_MANAGER_CONNECTION_H_ |
6 #define CONTENT_PUBLIC_COMMON_SERVICE_MANAGER_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/service_info.h" | 13 #include "content/public/common/service_info.h" |
14 #include "services/service_manager/public/cpp/identity.h" | 14 #include "services/service_manager/public/cpp/identity.h" |
15 #include "services/service_manager/public/interfaces/service.mojom.h" | 15 #include "services/service_manager/public/interfaces/service.mojom.h" |
16 | 16 |
17 namespace shell { | 17 namespace service_manager { |
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/service_manager. | 28 // Encapsulates a connection to a //services/service_manager. |
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 service_manager::Service implementations whose exposed |
| 32 // interfaces |
32 // will be exposed to inbound connections to this object's Service. | 33 // will be exposed to inbound connections to this object's Service. |
33 // Alternatively clients can define named services that will be constructed when | 34 // Alternatively clients can define named services that will be constructed when |
34 // requests for those service names are received. | 35 // requests for those service names are received. |
35 // Clients must call any of the registration methods when receiving | 36 // Clients must call any of the registration methods when receiving |
36 // ContentBrowserClient::RegisterInProcessServices(). | 37 // ContentBrowserClient::RegisterInProcessServices(). |
37 class CONTENT_EXPORT ServiceManagerConnection { | 38 class CONTENT_EXPORT ServiceManagerConnection { |
38 public: | 39 public: |
39 using ServiceRequestHandler = | 40 using ServiceRequestHandler = |
40 base::Callback<void(shell::mojom::ServiceRequest)>; | 41 base::Callback<void(service_manager::mojom::ServiceRequest)>; |
41 using Factory = | 42 using Factory = |
42 base::Callback<std::unique_ptr<ServiceManagerConnection>(void)>; | 43 base::Callback<std::unique_ptr<ServiceManagerConnection>(void)>; |
43 | 44 |
44 // Stores an instance of |connection| in TLS for the current process. Must be | 45 // Stores an instance of |connection| in TLS for the current process. Must be |
45 // called on the thread the connection was created on. | 46 // called on the thread the connection was created on. |
46 static void SetForProcess( | 47 static void SetForProcess( |
47 std::unique_ptr<ServiceManagerConnection> connection); | 48 std::unique_ptr<ServiceManagerConnection> connection); |
48 | 49 |
49 // Returns the per-process instance, or nullptr if the Service Manager | 50 // Returns the per-process instance, or nullptr if the Service Manager |
50 // connection has not yet been bound. Must be called on the thread the | 51 // connection has not yet been bound. Must be called on the thread the |
51 // connection was created on. | 52 // connection was created on. |
52 static ServiceManagerConnection* GetForProcess(); | 53 static ServiceManagerConnection* GetForProcess(); |
53 | 54 |
54 // Destroys the per-process instance. Must be called on the thread the | 55 // Destroys the per-process instance. Must be called on the thread the |
55 // connection was created on. | 56 // connection was created on. |
56 static void DestroyForProcess(); | 57 static void DestroyForProcess(); |
57 | 58 |
58 virtual ~ServiceManagerConnection(); | 59 virtual ~ServiceManagerConnection(); |
59 | 60 |
60 // Sets the factory used to create the ServiceManagerConnection. This must be | 61 // Sets the factory used to create the ServiceManagerConnection. This must be |
61 // called before the ServiceManagerConnection has been created. | 62 // called before the ServiceManagerConnection has been created. |
62 static void SetFactoryForTest(Factory* factory); | 63 static void SetFactoryForTest(Factory* factory); |
63 | 64 |
64 // Creates a ServiceManagerConnection from |request|. The connection binds | 65 // Creates a ServiceManagerConnection from |request|. The connection binds |
65 // its interfaces and accept new connections on |io_task_runner| only. Note | 66 // its interfaces and accept new connections on |io_task_runner| only. Note |
66 // that no incoming connections are accepted until Start() is called. | 67 // that no incoming connections are accepted until Start() is called. |
67 static std::unique_ptr<ServiceManagerConnection> Create( | 68 static std::unique_ptr<ServiceManagerConnection> Create( |
68 shell::mojom::ServiceRequest request, | 69 service_manager::mojom::ServiceRequest request, |
69 scoped_refptr<base::SequencedTaskRunner> io_task_runner); | 70 scoped_refptr<base::SequencedTaskRunner> io_task_runner); |
70 | 71 |
71 // Begins accepting incoming connections. Connection filters MUST be added | 72 // Begins accepting incoming connections. Connection filters MUST be added |
72 // before calling this in order to avoid races. See AddConnectionFilter() | 73 // before calling this in order to avoid races. See AddConnectionFilter() |
73 // below. | 74 // below. |
74 virtual void Start() = 0; | 75 virtual void Start() = 0; |
75 | 76 |
76 // Sets a closure to be invoked once the connection receives an Initialize() | 77 // Sets a closure to be invoked once the connection receives an Initialize() |
77 // request from the shell. | 78 // request from the shell. |
78 virtual void SetInitializeHandler(const base::Closure& handler) = 0; | 79 virtual void SetInitializeHandler(const base::Closure& handler) = 0; |
79 | 80 |
80 // Returns the shell::Connector received via this connection's Service | 81 // Returns the service_manager::Connector received via this connection's |
| 82 // Service |
81 // implementation. Use this to initiate connections as this object's Identity. | 83 // implementation. Use this to initiate connections as this object's Identity. |
82 virtual shell::Connector* GetConnector() = 0; | 84 virtual service_manager::Connector* GetConnector() = 0; |
83 | 85 |
84 // Returns this connection's identity with the Service Manager. Connections | 86 // Returns this connection's identity with the Service Manager. Connections |
85 // initiated via the shell::Connector returned by GetConnector() will use | 87 // initiated via the service_manager::Connector returned by GetConnector() |
| 88 // will use |
86 // this. | 89 // this. |
87 virtual const shell::Identity& GetIdentity() const = 0; | 90 virtual const service_manager::Identity& GetIdentity() const = 0; |
88 | 91 |
89 // Sets a closure that is called when the connection is lost. Note that | 92 // Sets a closure that is called when the connection is lost. Note that |
90 // connection may already have been closed, in which case |closure| will be | 93 // connection may already have been closed, in which case |closure| will be |
91 // run immediately before returning from this function. | 94 // run immediately before returning from this function. |
92 virtual void SetConnectionLostClosure(const base::Closure& closure) = 0; | 95 virtual void SetConnectionLostClosure(const base::Closure& closure) = 0; |
93 | 96 |
94 // Provides an InterfaceRegistry to forward incoming interface requests to | 97 // Provides an InterfaceRegistry to forward incoming interface requests to |
95 // on the ServiceManagerConnection's own thread if they aren't bound by the | 98 // on the ServiceManagerConnection's own thread if they aren't bound by the |
96 // connection's internal InterfaceRegistry on the IO thread. | 99 // connection's internal InterfaceRegistry on the IO thread. |
97 // | 100 // |
98 // Also configures |interface_provider| to forward all of its outgoing | 101 // Also configures |interface_provider| to forward all of its outgoing |
99 // interface requests to the connection's internal remote interface provider. | 102 // interface requests to the connection's internal remote interface provider. |
100 // | 103 // |
101 // Note that neither |interface_registry| or |interface_provider| is owned | 104 // Note that neither |interface_registry| or |interface_provider| is owned |
102 // and both MUST outlive the ServiceManagerConnection. | 105 // and both MUST outlive the ServiceManagerConnection. |
103 // | 106 // |
104 // TODO(rockot): Remove this. It's a temporary solution to avoid porting all | 107 // TODO(rockot): Remove this. It's a temporary solution to avoid porting all |
105 // relevant code to ConnectionFilters at once. | 108 // relevant code to ConnectionFilters at once. |
106 virtual void SetupInterfaceRequestProxies( | 109 virtual void SetupInterfaceRequestProxies( |
107 shell::InterfaceRegistry* registry, | 110 service_manager::InterfaceRegistry* registry, |
108 shell::InterfaceProvider* provider) = 0; | 111 service_manager::InterfaceProvider* provider) = 0; |
109 | 112 |
110 static const int kInvalidConnectionFilterId = 0; | 113 static const int kInvalidConnectionFilterId = 0; |
111 | 114 |
112 // Allows the caller to filter inbound connections and/or expose interfaces | 115 // Allows the caller to filter inbound connections and/or expose interfaces |
113 // on them. |filter| may be created on any thread, but will be used and | 116 // on them. |filter| may be created on any thread, but will be used and |
114 // destroyed exclusively on the IO thread (the thread corresponding to | 117 // destroyed exclusively on the IO thread (the thread corresponding to |
115 // |io_task_runner| passed to Create() above.) | 118 // |io_task_runner| passed to Create() above.) |
116 // | 119 // |
117 // Connection filters MUST be added before calling Start() in order to avoid | 120 // Connection filters MUST be added before calling Start() in order to avoid |
118 // races. | 121 // races. |
(...skipping 20 matching lines...) Expand all Loading... |
139 // For in-process services, it is preferable to use |AddEmbeddedService()| as | 142 // For in-process services, it is preferable to use |AddEmbeddedService()| as |
140 // defined above. | 143 // defined above. |
141 virtual void AddServiceRequestHandler( | 144 virtual void AddServiceRequestHandler( |
142 const std::string& name, | 145 const std::string& name, |
143 const ServiceRequestHandler& handler) = 0; | 146 const ServiceRequestHandler& handler) = 0; |
144 }; | 147 }; |
145 | 148 |
146 } // namespace content | 149 } // namespace content |
147 | 150 |
148 #endif // CONTENT_PUBLIC_COMMON_SERVICE_MANAGER_CONNECTION_H_ | 151 #endif // CONTENT_PUBLIC_COMMON_SERVICE_MANAGER_CONNECTION_H_ |
OLD | NEW |