OLD | NEW |
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 "mojo/public/cpp/bindings/message.h" | 9 #include "mojo/public/cpp/bindings/message.h" |
10 #include "services/service_manager/public/cpp/connection.h" | 10 #include "services/service_manager/public/cpp/connection.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 for (const auto& interface_name : it->second) | 53 for (const auto& interface_name : it->second) |
54 allowed_interfaces.insert(interface_name); | 54 allowed_interfaces.insert(interface_name); |
55 } | 55 } |
56 } | 56 } |
57 return allowed_interfaces; | 57 return allowed_interfaces; |
58 } | 58 } |
59 | 59 |
60 | 60 |
61 } // namespace | 61 } // namespace |
62 | 62 |
63 InterfaceRegistry::InterfaceRegistry( | 63 InterfaceRegistry::InterfaceRegistry(const std::string& name) |
64 const Identity& identity, | |
65 const InterfaceProviderSpec& interface_provider_spec) | |
66 : binding_(this), | 64 : binding_(this), |
67 identity_(identity), | 65 name_(name), |
68 interface_provider_spec_(interface_provider_spec), | |
69 weak_factory_(this) {} | 66 weak_factory_(this) {} |
70 | |
71 InterfaceRegistry::~InterfaceRegistry() {} | 67 InterfaceRegistry::~InterfaceRegistry() {} |
72 | 68 |
73 void InterfaceRegistry::Bind( | 69 void InterfaceRegistry::Bind( |
74 mojom::InterfaceProviderRequest local_interfaces_request, | 70 mojom::InterfaceProviderRequest local_interfaces_request, |
| 71 const Identity& local_identity, |
| 72 const InterfaceProviderSpec& local_interface_provider_spec, |
75 const Identity& remote_identity, | 73 const Identity& remote_identity, |
76 const InterfaceProviderSpec& remote_interface_provider_spec) { | 74 const InterfaceProviderSpec& remote_interface_provider_spec) { |
77 DCHECK(!binding_.is_bound()); | 75 DCHECK(!binding_.is_bound()); |
| 76 identity_ = local_identity; |
| 77 interface_provider_spec_ = local_interface_provider_spec; |
78 remote_identity_ = remote_identity; | 78 remote_identity_ = remote_identity; |
79 allowed_interfaces_ = GetAllowedInterfaces(remote_interface_provider_spec, | 79 allowed_interfaces_ = GetAllowedInterfaces(remote_interface_provider_spec, |
80 identity_, | 80 identity_, |
81 interface_provider_spec_); | 81 interface_provider_spec_); |
82 allow_all_interfaces_ = | 82 allow_all_interfaces_ = |
83 allowed_interfaces_.size() == 1 && allowed_interfaces_.count("*") == 1; | 83 allowed_interfaces_.size() == 1 && allowed_interfaces_.count("*") == 1; |
84 if (!allow_all_interfaces_) { | 84 if (!allow_all_interfaces_) { |
85 for (auto it = name_to_binder_.begin(); it != name_to_binder_.end(); ++it) { | 85 for (auto it = name_to_binder_.begin(); it != name_to_binder_.end();) { |
86 if (allowed_interfaces_.count(it->first) == 0) | 86 if (allowed_interfaces_.count(it->first) == 0) |
87 name_to_binder_.erase(it); | 87 it = name_to_binder_.erase(it); |
| 88 else |
| 89 ++it; |
88 } | 90 } |
89 } | 91 } |
90 binding_.Bind(std::move(local_interfaces_request)); | 92 binding_.Bind(std::move(local_interfaces_request)); |
91 } | 93 } |
92 | 94 |
93 base::WeakPtr<InterfaceRegistry> InterfaceRegistry::GetWeakPtr() { | 95 base::WeakPtr<InterfaceRegistry> InterfaceRegistry::GetWeakPtr() { |
94 return weak_factory_.GetWeakPtr(); | 96 return weak_factory_.GetWeakPtr(); |
95 } | 97 } |
96 | 98 |
97 bool InterfaceRegistry::AddInterface( | 99 bool InterfaceRegistry::AddInterface( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 return; | 147 return; |
146 } | 148 } |
147 | 149 |
148 auto iter = name_to_binder_.find(interface_name); | 150 auto iter = name_to_binder_.find(interface_name); |
149 if (iter != name_to_binder_.end()) { | 151 if (iter != name_to_binder_.end()) { |
150 iter->second->BindInterface(remote_identity_, | 152 iter->second->BindInterface(remote_identity_, |
151 interface_name, | 153 interface_name, |
152 std::move(handle)); | 154 std::move(handle)); |
153 } else if (!CanBindRequestForInterface(interface_name)) { | 155 } else if (!CanBindRequestForInterface(interface_name)) { |
154 std::stringstream ss; | 156 std::stringstream ss; |
155 ss << "Capability spec prevented service " << remote_identity_.name() | 157 ss << "InterfaceProviderSpec \"" << name_ << "\" prevented service: " |
156 << " from binding interface: " << interface_name | 158 << remote_identity_.name() << " from binding interface: " |
157 << " exposed by: " << identity_.name(); | 159 << interface_name << " exposed by: " << identity_.name(); |
158 LOG(ERROR) << ss.str(); | 160 LOG(ERROR) << ss.str(); |
159 mojo::ReportBadMessage(ss.str()); | 161 mojo::ReportBadMessage(ss.str()); |
160 } else if (!default_binder_.is_null()) { | 162 } else if (!default_binder_.is_null()) { |
161 default_binder_.Run(interface_name, std::move(handle)); | 163 default_binder_.Run(interface_name, std::move(handle)); |
162 } else { | 164 } else { |
163 LOG(ERROR) << "Failed to locate a binder for interface: " << interface_name | 165 LOG(ERROR) << "Failed to locate a binder for interface: " << interface_name |
164 << " requested by: " << remote_identity_.name() | 166 << " requested by: " << remote_identity_.name() |
165 << " exposed by: " << identity_.name(); | 167 << " exposed by: " << identity_.name(); |
166 } | 168 } |
167 } | 169 } |
(...skipping 13 matching lines...) Expand all Loading... |
181 const std::string& interface_name) const { | 183 const std::string& interface_name) const { |
182 // Any interface may be registered before the registry is bound to a pipe. At | 184 // Any interface may be registered before the registry is bound to a pipe. At |
183 // bind time, the interfaces exposed will be intersected with the requirements | 185 // bind time, the interfaces exposed will be intersected with the requirements |
184 // of the source. | 186 // of the source. |
185 if (!binding_.is_bound()) | 187 if (!binding_.is_bound()) |
186 return true; | 188 return true; |
187 return allow_all_interfaces_ || allowed_interfaces_.count(interface_name); | 189 return allow_all_interfaces_ || allowed_interfaces_.count(interface_name); |
188 } | 190 } |
189 | 191 |
190 } // namespace service_manager | 192 } // namespace service_manager |
OLD | NEW |