Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: services/service_manager/public/cpp/interface_registry.h

Issue 2446313003: Revise InterfaceRegistry API to support filtering interfaces @ Bind() time. (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 InterfaceRegistry with no filtering rules applied. 79 // Construct an unbound InterfaceRegistry for the service |identity| that
80 InterfaceRegistry(); 80 // exposes interfaces in accordance to |interface_provider_spec|. This object
81 81 // will not bind requests for interfaces until Bind() is called.
82 // Construct an InterfaceRegistry in |local_identity| that exposes only 82 InterfaceRegistry(const Identity& identity,
83 // |allowed_interfaces| to |remote_identity|. 83 const InterfaceProviderSpec& interface_provider_spec);
84 InterfaceRegistry(const Identity& local_identity,
85 const Identity& remote_identity,
86 const InterfaceSet& allowed_interfaces);
87 ~InterfaceRegistry() override; 84 ~InterfaceRegistry() override;
88 85
89 // Sets a default handler for incoming interface requests which are allowed by 86 // Sets a default handler for incoming interface requests which are allowed by
90 // capability filters but have no registered handler in this registry. 87 // capability filters but have no registered handler in this registry.
91 void set_default_binder(const Binder& binder) { default_binder_ = binder; } 88 void set_default_binder(const Binder& binder) { default_binder_ = binder; }
92 89
93 void Bind(mojom::InterfaceProviderRequest local_interfaces_request); 90 // Binds a request for an InterfaceProvider from a remote source.
91 // |remote_info| contains the the identity of the remote, and the remote's
92 // InterfaceProviderSpec, which will be intersected with the local's exports
93 // to determine what interfaces may be bound.
94 void Bind(mojom::InterfaceProviderRequest request,
95 const Identity& remote_identity,
96 const InterfaceProviderSpec& remote_interface_provider_spec);
94 97
95 base::WeakPtr<InterfaceRegistry> GetWeakPtr(); 98 base::WeakPtr<InterfaceRegistry> GetWeakPtr();
96 99
97 // 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
98 // 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
99 // if Connection policy prevented exposure. 102 // if Connection policy prevented exposure.
100 template <typename Interface> 103 template <typename Interface>
101 bool AddInterface(InterfaceFactory<Interface>* factory) { 104 bool AddInterface(InterfaceFactory<Interface>* factory) {
102 return SetInterfaceBinderForName( 105 return SetInterfaceBinderForName(
103 base::MakeUnique<internal::InterfaceFactoryBinder<Interface>>(factory), 106 base::MakeUnique<internal::InterfaceFactoryBinder<Interface>>(factory),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder, 159 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder,
157 const std::string& name); 160 const std::string& name);
158 161
159 // Returns true if |remote_identity_| is allowed to bind |interface_name|, 162 // Returns true if |remote_identity_| is allowed to bind |interface_name|,
160 // according to capability policy. 163 // according to capability policy.
161 bool CanBindRequestForInterface(const std::string& interface_name) const; 164 bool CanBindRequestForInterface(const std::string& interface_name) const;
162 165
163 mojom::InterfaceProviderRequest pending_request_; 166 mojom::InterfaceProviderRequest pending_request_;
164 167
165 mojo::Binding<mojom::InterfaceProvider> binding_; 168 mojo::Binding<mojom::InterfaceProvider> binding_;
166 const Identity local_identity_; 169 const Identity identity_;
167 const Identity remote_identity_; 170 const InterfaceProviderSpec interface_provider_spec_;
168 const InterfaceSet allowed_interfaces_; 171
169 const bool allow_all_interfaces_; 172 // Metadata computed when Bind() is called:
173 Identity remote_identity_;
174 InterfaceSet allowed_interfaces_;
175 bool allow_all_interfaces_ = false;
170 176
171 NameToInterfaceBinderMap name_to_binder_; 177 NameToInterfaceBinderMap name_to_binder_;
172 Binder default_binder_; 178 Binder default_binder_;
173 179
174 bool is_paused_ = false; 180 bool is_paused_ = false;
175 181
176 // Pending interface requests which can accumulate if GetInterface() is called 182 // Pending interface requests which can accumulate if GetInterface() is called
177 // while binding is paused. 183 // while binding is paused.
178 std::queue<std::pair<std::string, mojo::ScopedMessagePipeHandle>> 184 std::queue<std::pair<std::string, mojo::ScopedMessagePipeHandle>>
179 pending_interface_requests_; 185 pending_interface_requests_;
180 186
181 base::WeakPtrFactory<InterfaceRegistry> weak_factory_; 187 base::WeakPtrFactory<InterfaceRegistry> weak_factory_;
182 188
183 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry); 189 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry);
184 }; 190 };
185 191
186 } // namespace service_manager 192 } // namespace service_manager
187 193
188 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_REGISTRY_H_ 194 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_REGISTRY_H_
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/identity.h ('k') | services/service_manager/public/cpp/lib/identity.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698