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

Side by Side Diff: services/service_manager/service_manager.cc

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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "services/service_manager/service_manager.h" 5 #include "services/service_manager/service_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 21 matching lines...) Expand all
32 namespace service_manager { 32 namespace service_manager {
33 33
34 namespace { 34 namespace {
35 35
36 const char kCatalogName[] = "service:catalog"; 36 const char kCatalogName[] = "service:catalog";
37 const char kServiceManagerName[] = "service:service_manager"; 37 const char kServiceManagerName[] = "service:service_manager";
38 const char kCapability_UserID[] = "service_manager:user_id"; 38 const char kCapability_UserID[] = "service_manager:user_id";
39 const char kCapability_ClientProcess[] = "service_manager:client_process"; 39 const char kCapability_ClientProcess[] = "service_manager:client_process";
40 const char kCapability_InstanceName[] = "service_manager:instance_name"; 40 const char kCapability_InstanceName[] = "service_manager:instance_name";
41 const char kCapability_AllUsers[] = "service_manager:all_users"; 41 const char kCapability_AllUsers[] = "service_manager:all_users";
42 const char kCapability_ExplicitClass[] = "service_manager:explicit_class";
43 const char kCapability_ServiceManager[] = "service_manager:service_manager"; 42 const char kCapability_ServiceManager[] = "service_manager:service_manager";
44 43
45 } // namespace 44 } // namespace
46 45
47 Identity CreateServiceManagerIdentity() { 46 Identity CreateServiceManagerIdentity() {
48 return Identity(kServiceManagerName, mojom::kRootUserID); 47 return Identity(kServiceManagerName, mojom::kRootUserID);
49 } 48 }
50 49
51 Identity CreateCatalogIdentity() { 50 Identity CreateCatalogIdentity() {
52 return Identity(kCatalogName, mojom::kRootUserID); 51 return Identity(kCatalogName, mojom::kRootUserID);
53 } 52 }
54 53
55 InterfaceProviderSpec GetPermissiveInterfaceProviderSpec() { 54 InterfaceProviderSpec GetPermissiveInterfaceProviderSpec() {
56 InterfaceProviderSpec spec; 55 InterfaceProviderSpec spec;
57 InterfaceSet interfaces; 56 InterfaceSet interfaces;
58 interfaces.insert("*"); 57 interfaces.insert("*");
59 spec.requires["*"] = interfaces; 58 spec.requires["*"] = interfaces;
60 return spec; 59 return spec;
61 } 60 }
62 61
63 CapabilitySet GetRequestedCapabilities(const InterfaceProviderSpec& source_spec,
64 const Identity& target) {
65 CapabilitySet capabilities;
66
67 // Start by looking for specs specific to the supplied identity.
68 auto it = source_spec.requires.find(target.name());
69 if (it != source_spec.requires.end()) {
70 std::copy(it->second.begin(), it->second.end(),
71 std::inserter(capabilities, capabilities.begin()));
72 }
73
74 // Apply wild card rules too.
75 it = source_spec.requires.find("*");
76 if (it != source_spec.requires.end()) {
77 std::copy(it->second.begin(), it->second.end(),
78 std::inserter(capabilities, capabilities.begin()));
79 }
80 return capabilities;
81 }
82
83 void GetCapabilitiesAndInterfacesForConnection(
84 const InterfaceProviderSpec& source_spec,
85 const Identity& target,
86 const InterfaceProviderSpec& target_spec,
87 CapabilitySet* capabilities,
88 InterfaceSet* interfaces) {
89 DCHECK(capabilities && interfaces);
90 *capabilities = GetRequestedCapabilities(source_spec, target);
91 // Flatten all interfaces from capabilities requested by the source into the
92 // allowed interface set in the request.
93 for (const auto& capability : *capabilities) {
94 auto it = target_spec.provides.find(capability);
95 if (it != target_spec.provides.end()) {
96 for (const auto& interface_name : it->second)
97 interfaces->insert(interface_name);
98 }
99 }
100 }
101
102 bool HasCapability(const InterfaceProviderSpec& spec, 62 bool HasCapability(const InterfaceProviderSpec& spec,
103 const std::string& capability) { 63 const std::string& capability) {
104 auto it = spec.requires.find(kServiceManagerName); 64 auto it = spec.requires.find(kServiceManagerName);
105 if (it == spec.requires.end()) 65 if (it == spec.requires.end())
106 return false; 66 return false;
107 return it->second.find(capability) != it->second.end(); 67 return it->second.find(capability) != it->second.end();
108 } 68 }
109 69
110 // Encapsulates a connection to an instance of a service, tracked by the 70 // Encapsulates a connection to an instance of a service, tracked by the
111 // Service Manager. 71 // Service Manager.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 bool ConnectToService(std::unique_ptr<ConnectParams>* connect_params) { 130 bool ConnectToService(std::unique_ptr<ConnectParams>* connect_params) {
171 if (!service_.is_bound()) 131 if (!service_.is_bound())
172 return false; 132 return false;
173 133
174 std::unique_ptr<ConnectParams> params(std::move(*connect_params)); 134 std::unique_ptr<ConnectParams> params(std::move(*connect_params));
175 if (!params->connect_callback().is_null()) { 135 if (!params->connect_callback().is_null()) {
176 params->connect_callback().Run(mojom::ConnectResult::SUCCEEDED, 136 params->connect_callback().Run(mojom::ConnectResult::SUCCEEDED,
177 identity_.user_id()); 137 identity_.user_id());
178 } 138 }
179 139
180 InterfaceProviderSpec connection_spec = GetConnectionSpec(); 140 InterfaceProviderSpecMap specs;
181 CapabilitySet capabilities;
182 InterfaceSet interfaces;
183 Instance* source = service_manager_->GetExistingInstance(params->source()); 141 Instance* source = service_manager_->GetExistingInstance(params->source());
184 if (source) {
185 GetCapabilitiesAndInterfacesForConnection(source->GetConnectionSpec(),
186 identity_, connection_spec,
187 &capabilities, &interfaces);
188 } else {
189 interfaces.insert("*");
190 }
191
192 // The target has specified that sources must request one of its provided
193 // classes instead of specifying a wild-card for interfaces.
194 if (HasCapability(connection_spec, kCapability_ExplicitClass) &&
195 (interfaces.count("*") != 0)) {
196 interfaces.erase("*");
197 }
198
199 InterfaceProviderSpecMap specs;
200 if (source) 142 if (source)
201 specs = source->interface_provider_specs_; 143 specs = source->interface_provider_specs_;
202 service_->OnConnect(ServiceInfo(params->source(), specs), 144 service_->OnConnect(ServiceInfo(params->source(), specs),
203 params->TakeRemoteInterfaces(), interfaces, 145 params->TakeRemoteInterfaces());
204 capabilities);
205 return true; 146 return true;
206 } 147 }
207 148
208 void StartWithService(mojom::ServicePtr service) { 149 void StartWithService(mojom::ServicePtr service) {
209 CHECK(!service_); 150 CHECK(!service_);
210 service_ = std::move(service); 151 service_ = std::move(service);
211 service_.set_connection_error_handler( 152 service_.set_connection_error_handler(
212 base::Bind(&Instance::OnServiceLost, base::Unretained(this), 153 base::Bind(&Instance::OnServiceLost, base::Unretained(this),
213 service_manager_->GetWeakPtr())); 154 service_manager_->GetWeakPtr()));
214 service_->OnStart(ServiceInfo(identity_, interface_provider_specs_), 155 service_->OnStart(ServiceInfo(identity_, interface_provider_specs_),
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 // Now that the instance has a Service, we can connect to it. 850 // Now that the instance has a Service, we can connect to it.
910 bool connected = instance->ConnectToService(&params); 851 bool connected = instance->ConnectToService(&params);
911 DCHECK(connected); 852 DCHECK(connected);
912 } 853 }
913 854
914 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { 855 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() {
915 return weak_ptr_factory_.GetWeakPtr(); 856 return weak_ptr_factory_.GetWeakPtr();
916 } 857 }
917 858
918 } // namespace service_manager 859 } // namespace service_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698