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() : binding_(this), weak_factory_(this) {} |
64 const Identity& identity, | |
65 const InterfaceProviderSpec& interface_provider_spec) | |
66 : binding_(this), | |
67 identity_(identity), | |
68 interface_provider_spec_(interface_provider_spec), | |
69 weak_factory_(this) {} | |
70 | |
71 InterfaceRegistry::~InterfaceRegistry() {} | 64 InterfaceRegistry::~InterfaceRegistry() {} |
72 | 65 |
73 void InterfaceRegistry::Bind( | 66 void InterfaceRegistry::Bind( |
74 mojom::InterfaceProviderRequest local_interfaces_request, | 67 mojom::InterfaceProviderRequest local_interfaces_request, |
| 68 const Identity& local_identity, |
| 69 const InterfaceProviderSpec& local_interface_provider_spec, |
75 const Identity& remote_identity, | 70 const Identity& remote_identity, |
76 const InterfaceProviderSpec& remote_interface_provider_spec) { | 71 const InterfaceProviderSpec& remote_interface_provider_spec) { |
77 DCHECK(!binding_.is_bound()); | 72 DCHECK(!binding_.is_bound()); |
| 73 identity_ = local_identity; |
| 74 interface_provider_spec_ = local_interface_provider_spec; |
78 remote_identity_ = remote_identity; | 75 remote_identity_ = remote_identity; |
79 allowed_interfaces_ = GetAllowedInterfaces(remote_interface_provider_spec, | 76 allowed_interfaces_ = GetAllowedInterfaces(remote_interface_provider_spec, |
80 identity_, | 77 identity_, |
81 interface_provider_spec_); | 78 interface_provider_spec_); |
82 allow_all_interfaces_ = | 79 allow_all_interfaces_ = |
83 allowed_interfaces_.size() == 1 && allowed_interfaces_.count("*") == 1; | 80 allowed_interfaces_.size() == 1 && allowed_interfaces_.count("*") == 1; |
84 if (!allow_all_interfaces_) { | 81 if (!allow_all_interfaces_) { |
85 for (auto it = name_to_binder_.begin(); it != name_to_binder_.end(); ++it) { | 82 for (auto it = name_to_binder_.begin(); it != name_to_binder_.end();) { |
86 if (allowed_interfaces_.count(it->first) == 0) | 83 if (allowed_interfaces_.count(it->first) == 0) |
87 name_to_binder_.erase(it); | 84 it = name_to_binder_.erase(it); |
| 85 else |
| 86 ++it; |
88 } | 87 } |
89 } | 88 } |
90 binding_.Bind(std::move(local_interfaces_request)); | 89 binding_.Bind(std::move(local_interfaces_request)); |
91 } | 90 } |
92 | 91 |
93 base::WeakPtr<InterfaceRegistry> InterfaceRegistry::GetWeakPtr() { | 92 base::WeakPtr<InterfaceRegistry> InterfaceRegistry::GetWeakPtr() { |
94 return weak_factory_.GetWeakPtr(); | 93 return weak_factory_.GetWeakPtr(); |
95 } | 94 } |
96 | 95 |
97 bool InterfaceRegistry::AddInterface( | 96 bool InterfaceRegistry::AddInterface( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 const std::string& interface_name) const { | 180 const std::string& interface_name) const { |
182 // Any interface may be registered before the registry is bound to a pipe. At | 181 // 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 | 182 // bind time, the interfaces exposed will be intersected with the requirements |
184 // of the source. | 183 // of the source. |
185 if (!binding_.is_bound()) | 184 if (!binding_.is_bound()) |
186 return true; | 185 return true; |
187 return allow_all_interfaces_ || allowed_interfaces_.count(interface_name); | 186 return allow_all_interfaces_ || allowed_interfaces_.count(interface_name); |
188 } | 187 } |
189 | 188 |
190 } // namespace service_manager | 189 } // namespace service_manager |
OLD | NEW |