| 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/shell/public/cpp/interface_registry.h" | 5 #include "services/shell/public/cpp/interface_registry.h" |
| 6 | 6 |
| 7 #include <sstream> |
| 8 |
| 9 #include "mojo/public/cpp/bindings/message.h" |
| 7 #include "services/shell/public/cpp/connection.h" | 10 #include "services/shell/public/cpp/connection.h" |
| 8 | 11 |
| 9 namespace shell { | 12 namespace shell { |
| 10 | 13 |
| 11 InterfaceRegistry::InterfaceRegistry() | 14 InterfaceRegistry::InterfaceRegistry() |
| 12 : binding_(this), allow_all_interfaces_(true), weak_factory_(this) {} | 15 : binding_(this), allow_all_interfaces_(true), weak_factory_(this) {} |
| 13 | 16 |
| 14 InterfaceRegistry::InterfaceRegistry( | 17 InterfaceRegistry::InterfaceRegistry( |
| 15 const Identity& remote_identity, | 18 const Identity& remote_identity, |
| 16 const CapabilityRequest& capability_request) | 19 const CapabilityRequest& capability_request) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 pending_interface_requests_.emplace(interface_name, std::move(handle)); | 86 pending_interface_requests_.emplace(interface_name, std::move(handle)); |
| 84 return; | 87 return; |
| 85 } | 88 } |
| 86 | 89 |
| 87 auto iter = name_to_binder_.find(interface_name); | 90 auto iter = name_to_binder_.find(interface_name); |
| 88 if (iter != name_to_binder_.end()) { | 91 if (iter != name_to_binder_.end()) { |
| 89 iter->second->BindInterface(remote_identity_, | 92 iter->second->BindInterface(remote_identity_, |
| 90 interface_name, | 93 interface_name, |
| 91 std::move(handle)); | 94 std::move(handle)); |
| 92 } else if (!CanBindRequestForInterface(interface_name)) { | 95 } else if (!CanBindRequestForInterface(interface_name)) { |
| 93 LOG(ERROR) << "Capability spec prevented service: " | 96 std::stringstream ss; |
| 94 << remote_identity_.name() | 97 ss << "Capability spec prevented service " << remote_identity_.name() |
| 95 << " from binding interface: " << interface_name; | 98 << " from binding interface: " << interface_name; |
| 99 LOG(ERROR) << ss.str(); |
| 100 mojo::ReportBadMessage(ss.str()); |
| 96 } else if (!default_binder_.is_null()) { | 101 } else if (!default_binder_.is_null()) { |
| 97 default_binder_.Run(interface_name, std::move(handle)); | 102 default_binder_.Run(interface_name, std::move(handle)); |
| 98 } else { | 103 } else { |
| 99 LOG(ERROR) << "Failed to locate a binder for interface: " << interface_name; | 104 LOG(ERROR) << "Failed to locate a binder for interface: " << interface_name; |
| 100 } | 105 } |
| 101 } | 106 } |
| 102 | 107 |
| 103 bool InterfaceRegistry::SetInterfaceBinderForName( | 108 bool InterfaceRegistry::SetInterfaceBinderForName( |
| 104 std::unique_ptr<InterfaceBinder> binder, | 109 std::unique_ptr<InterfaceBinder> binder, |
| 105 const std::string& interface_name) { | 110 const std::string& interface_name) { |
| 106 if (CanBindRequestForInterface(interface_name)) { | 111 if (CanBindRequestForInterface(interface_name)) { |
| 107 RemoveInterface(interface_name); | 112 RemoveInterface(interface_name); |
| 108 name_to_binder_[interface_name] = std::move(binder); | 113 name_to_binder_[interface_name] = std::move(binder); |
| 109 return true; | 114 return true; |
| 110 } | 115 } |
| 111 return false; | 116 return false; |
| 112 } | 117 } |
| 113 | 118 |
| 114 bool InterfaceRegistry::CanBindRequestForInterface( | 119 bool InterfaceRegistry::CanBindRequestForInterface( |
| 115 const std::string& interface_name) const { | 120 const std::string& interface_name) const { |
| 116 return allow_all_interfaces_ || | 121 return allow_all_interfaces_ || |
| 117 capability_request_.interfaces.count(interface_name); | 122 capability_request_.interfaces.count(interface_name); |
| 118 } | 123 } |
| 119 | 124 |
| 120 } // namespace shell | 125 } // namespace shell |
| OLD | NEW |