| 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 "services/shell/public/cpp/connection.h" | 7 #include "services/shell/public/cpp/connection.h" |
| 8 | 8 |
| 9 namespace shell { | 9 namespace shell { |
| 10 | 10 |
| 11 InterfaceRegistry::InterfaceRegistry(Connection* connection) | 11 InterfaceRegistry::InterfaceRegistry() |
| 12 : binding_(this), connection_(connection), weak_factory_(this) {} | 12 : binding_(this), allow_all_interfaces_(true), weak_factory_(this) {} |
| 13 |
| 14 InterfaceRegistry::InterfaceRegistry( |
| 15 const Identity& remote_identity, |
| 16 const CapabilityRequest& capability_request) |
| 17 : binding_(this), |
| 18 remote_identity_(remote_identity), |
| 19 capability_request_(capability_request), |
| 20 allow_all_interfaces_(capability_request.interfaces.size() == 1 && |
| 21 capability_request.interfaces.count("*") == 1), |
| 22 weak_factory_(this) {} |
| 23 |
| 13 InterfaceRegistry::~InterfaceRegistry() {} | 24 InterfaceRegistry::~InterfaceRegistry() {} |
| 14 | 25 |
| 15 void InterfaceRegistry::Bind( | 26 void InterfaceRegistry::Bind( |
| 16 mojom::InterfaceProviderRequest local_interfaces_request) { | 27 mojom::InterfaceProviderRequest local_interfaces_request) { |
| 17 DCHECK(!binding_.is_bound()); | 28 DCHECK(!binding_.is_bound()); |
| 18 binding_.Bind(std::move(local_interfaces_request)); | 29 binding_.Bind(std::move(local_interfaces_request)); |
| 19 } | 30 } |
| 20 | 31 |
| 21 base::WeakPtr<InterfaceRegistry> InterfaceRegistry::GetWeakPtr() { | 32 base::WeakPtr<InterfaceRegistry> InterfaceRegistry::GetWeakPtr() { |
| 22 return weak_factory_.GetWeakPtr(); | 33 return weak_factory_.GetWeakPtr(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // mojom::InterfaceProvider: | 80 // mojom::InterfaceProvider: |
| 70 void InterfaceRegistry::GetInterface(const mojo::String& interface_name, | 81 void InterfaceRegistry::GetInterface(const mojo::String& interface_name, |
| 71 mojo::ScopedMessagePipeHandle handle) { | 82 mojo::ScopedMessagePipeHandle handle) { |
| 72 if (is_paused_) { | 83 if (is_paused_) { |
| 73 pending_interface_requests_.emplace(interface_name, std::move(handle)); | 84 pending_interface_requests_.emplace(interface_name, std::move(handle)); |
| 74 return; | 85 return; |
| 75 } | 86 } |
| 76 | 87 |
| 77 auto iter = name_to_binder_.find(interface_name); | 88 auto iter = name_to_binder_.find(interface_name); |
| 78 if (iter != name_to_binder_.end()) { | 89 if (iter != name_to_binder_.end()) { |
| 79 Identity remote_identity = | 90 iter->second->BindInterface(remote_identity_, |
| 80 connection_ ? connection_->GetRemoteIdentity() : Identity(); | |
| 81 iter->second->BindInterface(remote_identity, | |
| 82 interface_name, | 91 interface_name, |
| 83 std::move(handle)); | 92 std::move(handle)); |
| 84 } else if (connection_ && !connection_->AllowsInterface(interface_name)) { | 93 } else if (!CanBindRequestForInterface(interface_name)) { |
| 85 LOG(ERROR) << "Capability spec prevented service: " | 94 LOG(ERROR) << "Capability spec prevented service: " |
| 86 << connection_->GetRemoteIdentity().name() | 95 << remote_identity_.name() |
| 87 << " from binding interface: " << interface_name; | 96 << " from binding interface: " << interface_name; |
| 88 } else if (!default_binder_.is_null()) { | 97 } else if (!default_binder_.is_null()) { |
| 89 default_binder_.Run(interface_name, std::move(handle)); | 98 default_binder_.Run(interface_name, std::move(handle)); |
| 90 } else { | 99 } else { |
| 91 LOG(ERROR) << "Failed to locate a binder for interface: " << interface_name; | 100 LOG(ERROR) << "Failed to locate a binder for interface: " << interface_name; |
| 92 } | 101 } |
| 93 } | 102 } |
| 94 | 103 |
| 95 bool InterfaceRegistry::SetInterfaceBinderForName( | 104 bool InterfaceRegistry::SetInterfaceBinderForName( |
| 96 std::unique_ptr<InterfaceBinder> binder, | 105 std::unique_ptr<InterfaceBinder> binder, |
| 97 const std::string& interface_name) { | 106 const std::string& interface_name) { |
| 98 if (!connection_ || | 107 if (CanBindRequestForInterface(interface_name)) { |
| 99 (connection_ && connection_->AllowsInterface(interface_name))) { | |
| 100 RemoveInterface(interface_name); | 108 RemoveInterface(interface_name); |
| 101 name_to_binder_[interface_name] = std::move(binder); | 109 name_to_binder_[interface_name] = std::move(binder); |
| 102 return true; | 110 return true; |
| 103 } | 111 } |
| 104 return false; | 112 return false; |
| 105 } | 113 } |
| 106 | 114 |
| 115 bool InterfaceRegistry::CanBindRequestForInterface( |
| 116 const std::string& interface_name) const { |
| 117 return allow_all_interfaces_ || |
| 118 capability_request_.interfaces.count(interface_name); |
| 119 } |
| 120 |
| 107 } // namespace shell | 121 } // namespace shell |
| OLD | NEW |