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 SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_REGISTRY_H_ | 5 #ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_REGISTRY_H_ |
6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_REGISTRY_H_ | 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_REGISTRY_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <set> | 10 #include <set> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 void GetLocalInterface(const std::string& name, | 69 void GetLocalInterface(const std::string& name, |
70 mojo::ScopedMessagePipeHandle handle) { | 70 mojo::ScopedMessagePipeHandle handle) { |
71 registry_->GetInterface(name, std::move(handle)); | 71 registry_->GetInterface(name, std::move(handle)); |
72 } | 72 } |
73 | 73 |
74 private: | 74 private: |
75 InterfaceRegistry* registry_; | 75 InterfaceRegistry* registry_; |
76 DISALLOW_COPY_AND_ASSIGN(TestApi); | 76 DISALLOW_COPY_AND_ASSIGN(TestApi); |
77 }; | 77 }; |
78 | 78 |
79 // Construct an unbound InterfaceRegistry for the service |identity| that | 79 // Construct an unbound InterfaceRegistry. This object will not bind requests |
80 // exposes interfaces in accordance to |interface_provider_spec|. This object | 80 // for interfaces until Bind() is called. |
81 // will not bind requests for interfaces until Bind() is called. | 81 explicit InterfaceRegistry(const std::string& name); |
82 InterfaceRegistry(const Identity& identity, | |
83 const InterfaceProviderSpec& interface_provider_spec); | |
84 ~InterfaceRegistry() override; | 82 ~InterfaceRegistry() override; |
85 | 83 |
86 // Sets a default handler for incoming interface requests which are allowed by | 84 // Sets a default handler for incoming interface requests which are allowed by |
87 // capability filters but have no registered handler in this registry. | 85 // capability filters but have no registered handler in this registry. |
88 void set_default_binder(const Binder& binder) { default_binder_ = binder; } | 86 void set_default_binder(const Binder& binder) { default_binder_ = binder; } |
89 | 87 |
90 // Binds a request for an InterfaceProvider from a remote source. | 88 // Binds a request for an InterfaceProvider from a remote source. |
91 // |remote_info| contains the the identity of the remote, and the remote's | 89 // |remote_info| contains the the identity of the remote, and the remote's |
92 // InterfaceProviderSpec, which will be intersected with the local's exports | 90 // InterfaceProviderSpec, which will be intersected with the local's exports |
93 // to determine what interfaces may be bound. | 91 // to determine what interfaces may be bound. |
94 void Bind(mojom::InterfaceProviderRequest request, | 92 void Bind(mojom::InterfaceProviderRequest request, |
| 93 const Identity& local_identity, |
| 94 const InterfaceProviderSpec& local_interface_provider_spec, |
95 const Identity& remote_identity, | 95 const Identity& remote_identity, |
96 const InterfaceProviderSpec& remote_interface_provider_spec); | 96 const InterfaceProviderSpec& remote_interface_provider_spec); |
97 | 97 |
98 base::WeakPtr<InterfaceRegistry> GetWeakPtr(); | 98 base::WeakPtr<InterfaceRegistry> GetWeakPtr(); |
99 | 99 |
100 // Allows |Interface| to be exposed via this registry. Requests to bind will | 100 // Allows |Interface| to be exposed via this registry. Requests to bind will |
101 // be handled by |factory|. Returns true if the interface was exposed, false | 101 // be handled by |factory|. Returns true if the interface was exposed, false |
102 // if Connection policy prevented exposure. | 102 // if Connection policy prevented exposure. |
103 template <typename Interface> | 103 template <typename Interface> |
104 bool AddInterface(InterfaceFactory<Interface>* factory) { | 104 bool AddInterface(InterfaceFactory<Interface>* factory) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder, | 159 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder, |
160 const std::string& name); | 160 const std::string& name); |
161 | 161 |
162 // Returns true if |remote_identity_| is allowed to bind |interface_name|, | 162 // Returns true if |remote_identity_| is allowed to bind |interface_name|, |
163 // according to capability policy. | 163 // according to capability policy. |
164 bool CanBindRequestForInterface(const std::string& interface_name) const; | 164 bool CanBindRequestForInterface(const std::string& interface_name) const; |
165 | 165 |
166 mojom::InterfaceProviderRequest pending_request_; | 166 mojom::InterfaceProviderRequest pending_request_; |
167 | 167 |
168 mojo::Binding<mojom::InterfaceProvider> binding_; | 168 mojo::Binding<mojom::InterfaceProvider> binding_; |
169 const Identity identity_; | 169 Identity identity_; |
170 const InterfaceProviderSpec interface_provider_spec_; | 170 InterfaceProviderSpec interface_provider_spec_; |
| 171 std::string name_; |
171 | 172 |
172 // Metadata computed when Bind() is called: | 173 // Metadata computed when Bind() is called: |
173 Identity remote_identity_; | 174 Identity remote_identity_; |
174 InterfaceSet allowed_interfaces_; | 175 InterfaceSet allowed_interfaces_; |
175 bool allow_all_interfaces_ = false; | 176 bool allow_all_interfaces_ = false; |
176 | 177 |
177 NameToInterfaceBinderMap name_to_binder_; | 178 NameToInterfaceBinderMap name_to_binder_; |
178 Binder default_binder_; | 179 Binder default_binder_; |
179 | 180 |
180 bool is_paused_ = false; | 181 bool is_paused_ = false; |
181 | 182 |
182 // Pending interface requests which can accumulate if GetInterface() is called | 183 // Pending interface requests which can accumulate if GetInterface() is called |
183 // while binding is paused. | 184 // while binding is paused. |
184 std::queue<std::pair<std::string, mojo::ScopedMessagePipeHandle>> | 185 std::queue<std::pair<std::string, mojo::ScopedMessagePipeHandle>> |
185 pending_interface_requests_; | 186 pending_interface_requests_; |
186 | 187 |
187 base::WeakPtrFactory<InterfaceRegistry> weak_factory_; | 188 base::WeakPtrFactory<InterfaceRegistry> weak_factory_; |
188 | 189 |
189 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry); | 190 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry); |
190 }; | 191 }; |
191 | 192 |
192 } // namespace service_manager | 193 } // namespace service_manager |
193 | 194 |
194 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_REGISTRY_H_ | 195 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_REGISTRY_H_ |
OLD | NEW |