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

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

Issue 2457493004: Cleanup InterfaceRegistry + adds Serialize() (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
« no previous file with comments | « no previous file | services/service_manager/public/cpp/lib/interface_registry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. This object will not bind requests 79 // Construct an unbound InterfaceRegistry. This object will not bind requests
80 // for interfaces until Bind() is called. 80 // for interfaces until Bind() is called. |name| is used for error reporting
81 // and should reflect the name of the InterfaceProviderSpec pair that controls
82 // which interfaces can be bound via this InterfaceRegistry.
81 explicit InterfaceRegistry(const std::string& name); 83 explicit InterfaceRegistry(const std::string& name);
82 ~InterfaceRegistry() override; 84 ~InterfaceRegistry() override;
83 85
84 // 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
85 // capability filters but have no registered handler in this registry. 87 // capability filters but have no registered handler in this registry.
86 void set_default_binder(const Binder& binder) { default_binder_ = binder; } 88 void set_default_binder(const Binder& binder) { default_binder_ = binder; }
87 89
88 // Binds a request for an InterfaceProvider from a remote source. 90 // Binds a request for an InterfaceProvider from a remote source.
89 // |remote_info| contains the the identity of the remote, and the remote's 91 // |remote_info| contains the the identity of the remote, and the remote's
90 // InterfaceProviderSpec, which will be intersected with the local's exports 92 // InterfaceProviderSpec, which will be intersected with the local's exports
91 // to determine what interfaces may be bound. 93 // to determine what interfaces may be bound.
92 void Bind(mojom::InterfaceProviderRequest request, 94 void Bind(mojom::InterfaceProviderRequest request,
93 const Identity& local_identity, 95 const Identity& local_identity,
94 const InterfaceProviderSpec& local_interface_provider_spec, 96 const InterfaceProviderSpec& local_interface_provider_spec,
95 const Identity& remote_identity, 97 const Identity& remote_identity,
96 const InterfaceProviderSpec& remote_interface_provider_spec); 98 const InterfaceProviderSpec& remote_interface_provider_spec);
97 99
100 // Serializes the contents of the registry (including the local and remote
101 // specs) to a stringstream.
102 void Serialize(std::stringstream* stream);
103
98 base::WeakPtr<InterfaceRegistry> GetWeakPtr(); 104 base::WeakPtr<InterfaceRegistry> GetWeakPtr();
99 105
100 // Allows |Interface| to be exposed via this registry. Requests to bind will 106 // 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 107 // be handled by |factory|. Returns true if the interface was exposed, false
102 // if Connection policy prevented exposure. 108 // if Connection policy prevented exposure.
103 template <typename Interface> 109 template <typename Interface>
104 bool AddInterface(InterfaceFactory<Interface>* factory) { 110 bool AddInterface(InterfaceFactory<Interface>* factory) {
105 return SetInterfaceBinderForName( 111 return SetInterfaceBinderForName(
106 base::MakeUnique<internal::InterfaceFactoryBinder<Interface>>(factory), 112 base::MakeUnique<internal::InterfaceFactoryBinder<Interface>>(factory),
107 Interface::Name_); 113 Interface::Name_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // Resumes incoming interface request binding. 146 // Resumes incoming interface request binding.
141 void ResumeBinding(); 147 void ResumeBinding();
142 148
143 // Populates a set with the interface names this registry can bind. 149 // Populates a set with the interface names this registry can bind.
144 void GetInterfaceNames(std::set<std::string>* interface_names); 150 void GetInterfaceNames(std::set<std::string>* interface_names);
145 151
146 // Sets a closure to be run when the InterfaceProvider pipe is closed. 152 // Sets a closure to be run when the InterfaceProvider pipe is closed.
147 void SetConnectionLostClosure(const base::Closure& connection_lost_closure); 153 void SetConnectionLostClosure(const base::Closure& connection_lost_closure);
148 154
149 private: 155 private:
150 using NameToInterfaceBinderMap = 156 using InterfaceNameToBinderMap =
151 std::map<std::string, std::unique_ptr<InterfaceBinder>>; 157 std::map<std::string, std::unique_ptr<InterfaceBinder>>;
152 158
153 // mojom::InterfaceProvider: 159 // mojom::InterfaceProvider:
154 void GetInterface(const std::string& interface_name, 160 void GetInterface(const std::string& interface_name,
155 mojo::ScopedMessagePipeHandle handle) override; 161 mojo::ScopedMessagePipeHandle handle) override;
156 162
157 // Returns true if the binder was set, false if it was not set (e.g. by 163 // Returns true if the binder was set, false if it was not set (e.g. by
158 // some filtering policy preventing this interface from being exposed). 164 // some filtering policy preventing this interface from being exposed).
159 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder, 165 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder,
160 const std::string& name); 166 const std::string& name);
161 167
162 // Returns true if |remote_identity_| is allowed to bind |interface_name|, 168 // Returns true if |remote_identity_| is allowed to bind |interface_name|,
163 // according to capability policy. 169 // according to capability policy.
164 bool CanBindRequestForInterface(const std::string& interface_name) const; 170 bool CanBindRequestForInterface(const std::string& interface_name) const;
165 171
172 // Called whenever |remote_interface_provider_spec_| changes to rebuild the
173 // contents of |exposed_interfaces_| and |expose_all_interfaces_|.
174 void RebuildExposedInterfaces();
175
166 mojom::InterfaceProviderRequest pending_request_; 176 mojom::InterfaceProviderRequest pending_request_;
167 177
168 mojo::Binding<mojom::InterfaceProvider> binding_; 178 mojo::Binding<mojom::InterfaceProvider> binding_;
169 Identity identity_; 179
170 InterfaceProviderSpec interface_provider_spec_;
171 std::string name_; 180 std::string name_;
172 181
173 // Metadata computed when Bind() is called: 182 // Initialized from static metadata in the host service's manifest.
183 Identity local_identity_;
184 InterfaceProviderSpec local_interface_provider_spec_;
185
186 // Initialized from static metadata in the remote service's manifest.
174 Identity remote_identity_; 187 Identity remote_identity_;
175 InterfaceSet allowed_interfaces_; 188 // Initialized from static metadata in the remote service's manifest. May be
176 bool allow_all_interfaces_ = false; 189 // mutated after the fact when a capability is dynamically granted via a call
190 // to GrantCapability().
191 InterfaceProviderSpec remote_interface_provider_spec_;
177 192
178 NameToInterfaceBinderMap name_to_binder_; 193 // Metadata computed whenever |remote_interface_provider_spec_| changes.
194 InterfaceSet exposed_interfaces_;
195 bool expose_all_interfaces_ = false;
196
197 // Contains every interface binder that has been registered with this
198 // InterfaceRegistry. Not all binders may be reachable depending on the
199 // capabilities requested by the remote. Only interfaces in
200 // exposed_interfaces_ may be bound. When |expose_all_interfaces_| is true,
201 // any interface may be bound.
202 InterfaceNameToBinderMap name_to_binder_;
179 Binder default_binder_; 203 Binder default_binder_;
180 204
181 bool is_paused_ = false; 205 bool is_paused_ = false;
182 206
183 // Pending interface requests which can accumulate if GetInterface() is called 207 // Pending interface requests which can accumulate if GetInterface() is called
184 // while binding is paused. 208 // while binding is paused.
185 std::queue<std::pair<std::string, mojo::ScopedMessagePipeHandle>> 209 std::queue<std::pair<std::string, mojo::ScopedMessagePipeHandle>>
186 pending_interface_requests_; 210 pending_interface_requests_;
187 211
188 base::WeakPtrFactory<InterfaceRegistry> weak_factory_; 212 base::WeakPtrFactory<InterfaceRegistry> weak_factory_;
189 213
190 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry); 214 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry);
191 }; 215 };
192 216
193 } // namespace service_manager 217 } // namespace service_manager
194 218
195 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_REGISTRY_H_ 219 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_INTERFACE_REGISTRY_H_
OLDNEW
« no previous file with comments | « no previous file | services/service_manager/public/cpp/lib/interface_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698