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

Side by Side Diff: services/service_manager/public/cpp/lib/interface_registry.cc

Issue 2634493002: Revert of Perform InterfaceProviderSpec intersection in the ServiceManager (Closed)
Patch Set: Created 3 years, 11 months 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 #include "services/service_manager/public/cpp/interface_registry.h" 5 #include "services/service_manager/public/cpp/interface_registry.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "mojo/public/cpp/bindings/message.h" 10 #include "mojo/public/cpp/bindings/message.h"
11 #include "services/service_manager/public/cpp/connection.h" 11 #include "services/service_manager/public/cpp/connection.h"
12 12
13 namespace service_manager { 13 namespace service_manager {
14 namespace { 14 namespace {
15 15
16 void SerializeIdentity(const Identity& identity, std::stringstream* stream) { 16 // Returns the set of capabilities required from the target.
17 *stream << identity.name() << "@" << identity.instance() << " run as: "
18 << identity.user_id();
19 }
20
21 void SerializeSpec(const InterfaceProviderSpec& spec,
22 std::stringstream* stream) {
23 *stream << " Providing:\n";
24 for (const auto& entry : spec.provides) {
25 *stream << " capability: " << entry.first << " containing interfaces:\n";
26 for (const auto& interface_name : entry.second)
27 *stream << " " << interface_name << "\n";
28 }
29 *stream << "\n Requiring:\n";
30 for (const auto& entry : spec.requires) {
31 *stream << " From: " << entry.first << ":\n";
32 for (const auto& capability_name : entry.second)
33 *stream << " " << capability_name << "\n";
34 }
35 }
36
37 } // namespace
38
39 CapabilitySet GetRequestedCapabilities(const InterfaceProviderSpec& source_spec, 17 CapabilitySet GetRequestedCapabilities(const InterfaceProviderSpec& source_spec,
40 const Identity& target) { 18 const Identity& target) {
41 CapabilitySet capabilities; 19 CapabilitySet capabilities;
42 20
43 // Start by looking for specs specific to the supplied identity. 21 // Start by looking for specs specific to the supplied identity.
44 auto it = source_spec.requires.find(target.name()); 22 auto it = source_spec.requires.find(target.name());
45 if (it != source_spec.requires.end()) { 23 if (it != source_spec.requires.end()) {
46 std::copy(it->second.begin(), it->second.end(), 24 std::copy(it->second.begin(), it->second.end(),
47 std::inserter(capabilities, capabilities.begin())); 25 std::inserter(capabilities, capabilities.begin()));
48 } 26 }
49 27
50 // Apply wild card rules too. 28 // Apply wild card rules too.
51 it = source_spec.requires.find("*"); 29 it = source_spec.requires.find("*");
52 if (it != source_spec.requires.end()) { 30 if (it != source_spec.requires.end()) {
53 std::copy(it->second.begin(), it->second.end(), 31 std::copy(it->second.begin(), it->second.end(),
54 std::inserter(capabilities, capabilities.begin())); 32 std::inserter(capabilities, capabilities.begin()));
55 } 33 }
56 return capabilities; 34 return capabilities;
57 } 35 }
58 36
37 // Generates a single set of interfaces that is the union of all interfaces
38 // exposed by the target for the capabilities requested by the source.
59 InterfaceSet GetInterfacesToExpose( 39 InterfaceSet GetInterfacesToExpose(
60 const InterfaceProviderSpec& source_spec, 40 const InterfaceProviderSpec& source_spec,
61 const Identity& target, 41 const Identity& target,
62 const InterfaceProviderSpec& target_spec) { 42 const InterfaceProviderSpec& target_spec) {
63 InterfaceSet exposed_interfaces; 43 InterfaceSet exposed_interfaces;
64 // TODO(beng): remove this once we can assert that an InterfaceRegistry must 44 // TODO(beng): remove this once we can assert that an InterfaceRegistry must
65 // always be constructed with a valid identity. 45 // always be constructed with a valid identity.
66 if (!target.IsValid()) { 46 if (!target.IsValid()) {
67 exposed_interfaces.insert("*"); 47 exposed_interfaces.insert("*");
68 return exposed_interfaces; 48 return exposed_interfaces;
69 } 49 }
70 CapabilitySet capabilities = GetRequestedCapabilities(source_spec, target); 50 CapabilitySet capabilities = GetRequestedCapabilities(source_spec, target);
71 for (const auto& capability : capabilities) { 51 for (const auto& capability : capabilities) {
72 auto it = target_spec.provides.find(capability); 52 auto it = target_spec.provides.find(capability);
73 if (it != target_spec.provides.end()) { 53 if (it != target_spec.provides.end()) {
74 for (const auto& interface_name : it->second) 54 for (const auto& interface_name : it->second)
75 exposed_interfaces.insert(interface_name); 55 exposed_interfaces.insert(interface_name);
76 } 56 }
77 } 57 }
78 return exposed_interfaces; 58 return exposed_interfaces;
79 } 59 }
80 60
61 void SerializeIdentity(const Identity& identity, std::stringstream* stream) {
62 *stream << identity.name() << "@" << identity.instance() << " run as: "
63 << identity.user_id();
64 }
65
66 void SerializeSpec(const InterfaceProviderSpec& spec,
67 std::stringstream* stream) {
68 *stream << " Providing:\n";
69 for (const auto& entry : spec.provides) {
70 *stream << " capability: " << entry.first << " containing interfaces:\n";
71 for (const auto& interface_name : entry.second)
72 *stream << " " << interface_name << "\n";
73 }
74 *stream << "\n Requiring:\n";
75 for (const auto& entry : spec.requires) {
76 *stream << " From: " << entry.first << ":\n";
77 for (const auto& capability_name : entry.second)
78 *stream << " " << capability_name << "\n";
79 }
80 }
81
82 } // namespace
83
81 InterfaceRegistry::InterfaceRegistry(const std::string& name) 84 InterfaceRegistry::InterfaceRegistry(const std::string& name)
82 : binding_(this), 85 : binding_(this),
83 name_(name), 86 name_(name),
84 weak_factory_(this) {} 87 weak_factory_(this) {}
85 InterfaceRegistry::~InterfaceRegistry() {} 88 InterfaceRegistry::~InterfaceRegistry() {}
86 89
87 void InterfaceRegistry::Bind( 90 void InterfaceRegistry::Bind(
88 mojom::InterfaceProviderRequest local_interfaces_request, 91 mojom::InterfaceProviderRequest local_interfaces_request,
89 const Identity& local_identity, 92 const Identity& local_identity,
90 const InterfaceProviderSpec& local_interface_provider_spec, 93 const InterfaceProviderSpec& local_interface_provider_spec,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 exposed_interfaces_.size() == 1 && exposed_interfaces_.count("*") == 1; 250 exposed_interfaces_.size() == 1 && exposed_interfaces_.count("*") == 1;
248 } 251 }
249 252
250 void InterfaceRegistry::OnConnectionError() { 253 void InterfaceRegistry::OnConnectionError() {
251 std::list<base::Closure> closures = connection_lost_closures_; 254 std::list<base::Closure> closures = connection_lost_closures_;
252 for (const auto& closure : closures) 255 for (const auto& closure : closures)
253 closure.Run(); 256 closure.Run();
254 } 257 }
255 258
256 } // namespace service_manager 259 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/public/cpp/interface_registry.h ('k') | services/service_manager/public/cpp/lib/service_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698