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

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

Issue 2610853013: 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 // Returns the set of capabilities required from the target. 16 void SerializeIdentity(const Identity& identity, std::stringstream* stream) {
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
17 CapabilitySet GetRequestedCapabilities(const InterfaceProviderSpec& source_spec, 39 CapabilitySet GetRequestedCapabilities(const InterfaceProviderSpec& source_spec,
18 const Identity& target) { 40 const Identity& target) {
19 CapabilitySet capabilities; 41 CapabilitySet capabilities;
20 42
21 // Start by looking for specs specific to the supplied identity. 43 // Start by looking for specs specific to the supplied identity.
22 auto it = source_spec.requires.find(target.name()); 44 auto it = source_spec.requires.find(target.name());
23 if (it != source_spec.requires.end()) { 45 if (it != source_spec.requires.end()) {
24 std::copy(it->second.begin(), it->second.end(), 46 std::copy(it->second.begin(), it->second.end(),
25 std::inserter(capabilities, capabilities.begin())); 47 std::inserter(capabilities, capabilities.begin()));
26 } 48 }
27 49
28 // Apply wild card rules too. 50 // Apply wild card rules too.
29 it = source_spec.requires.find("*"); 51 it = source_spec.requires.find("*");
30 if (it != source_spec.requires.end()) { 52 if (it != source_spec.requires.end()) {
31 std::copy(it->second.begin(), it->second.end(), 53 std::copy(it->second.begin(), it->second.end(),
32 std::inserter(capabilities, capabilities.begin())); 54 std::inserter(capabilities, capabilities.begin()));
33 } 55 }
34 return capabilities; 56 return capabilities;
35 } 57 }
36 58
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.
39 InterfaceSet GetInterfacesToExpose( 59 InterfaceSet GetInterfacesToExpose(
40 const InterfaceProviderSpec& source_spec, 60 const InterfaceProviderSpec& source_spec,
41 const Identity& target, 61 const Identity& target,
42 const InterfaceProviderSpec& target_spec) { 62 const InterfaceProviderSpec& target_spec) {
43 InterfaceSet exposed_interfaces; 63 InterfaceSet exposed_interfaces;
44 // TODO(beng): remove this once we can assert that an InterfaceRegistry must 64 // TODO(beng): remove this once we can assert that an InterfaceRegistry must
45 // always be constructed with a valid identity. 65 // always be constructed with a valid identity.
46 if (!target.IsValid()) { 66 if (!target.IsValid()) {
47 exposed_interfaces.insert("*"); 67 exposed_interfaces.insert("*");
48 return exposed_interfaces; 68 return exposed_interfaces;
49 } 69 }
50 CapabilitySet capabilities = GetRequestedCapabilities(source_spec, target); 70 CapabilitySet capabilities = GetRequestedCapabilities(source_spec, target);
51 for (const auto& capability : capabilities) { 71 for (const auto& capability : capabilities) {
52 auto it = target_spec.provides.find(capability); 72 auto it = target_spec.provides.find(capability);
53 if (it != target_spec.provides.end()) { 73 if (it != target_spec.provides.end()) {
54 for (const auto& interface_name : it->second) 74 for (const auto& interface_name : it->second)
55 exposed_interfaces.insert(interface_name); 75 exposed_interfaces.insert(interface_name);
56 } 76 }
57 } 77 }
58 return exposed_interfaces; 78 return exposed_interfaces;
59 } 79 }
60 80
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
84 InterfaceRegistry::InterfaceRegistry(const std::string& name) 81 InterfaceRegistry::InterfaceRegistry(const std::string& name)
85 : binding_(this), 82 : binding_(this),
86 name_(name), 83 name_(name),
87 weak_factory_(this) {} 84 weak_factory_(this) {}
88 InterfaceRegistry::~InterfaceRegistry() {} 85 InterfaceRegistry::~InterfaceRegistry() {}
89 86
90 void InterfaceRegistry::Bind( 87 void InterfaceRegistry::Bind(
91 mojom::InterfaceProviderRequest local_interfaces_request, 88 mojom::InterfaceProviderRequest local_interfaces_request,
92 const Identity& local_identity, 89 const Identity& local_identity,
93 const InterfaceProviderSpec& local_interface_provider_spec, 90 const InterfaceProviderSpec& local_interface_provider_spec,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 exposed_interfaces_.size() == 1 && exposed_interfaces_.count("*") == 1; 247 exposed_interfaces_.size() == 1 && exposed_interfaces_.count("*") == 1;
251 } 248 }
252 249
253 void InterfaceRegistry::OnConnectionError() { 250 void InterfaceRegistry::OnConnectionError() {
254 std::list<base::Closure> closures = connection_lost_closures_; 251 std::list<base::Closure> closures = connection_lost_closures_;
255 for (const auto& closure : closures) 252 for (const auto& closure : closures)
256 closure.Run(); 253 closure.Run();
257 } 254 }
258 255
259 } // namespace service_manager 256 } // 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