| 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(Connection* connection) |
| 12 : InterfaceRegistry(nullptr, nullptr, connection) {} | 12 : InterfaceRegistry(nullptr, connection) {} |
| 13 | 13 |
| 14 InterfaceRegistry::InterfaceRegistry( | 14 InterfaceRegistry::InterfaceRegistry( |
| 15 mojom::InterfaceProviderPtr remote_interfaces, | |
| 16 mojom::InterfaceProviderRequest local_interfaces_request, | 15 mojom::InterfaceProviderRequest local_interfaces_request, |
| 17 Connection* connection) | 16 Connection* connection) |
| 18 : binding_(this), | 17 : binding_(this), |
| 19 connection_(connection), | 18 connection_(connection) { |
| 20 remote_interfaces_(std::move(remote_interfaces)) { | |
| 21 if (!local_interfaces_request.is_pending()) | 19 if (!local_interfaces_request.is_pending()) |
| 22 local_interfaces_request = GetProxy(&client_handle_); | 20 local_interfaces_request = GetProxy(&client_handle_); |
| 23 binding_.Bind(std::move(local_interfaces_request)); | 21 binding_.Bind(std::move(local_interfaces_request)); |
| 24 } | 22 } |
| 25 | 23 |
| 26 InterfaceRegistry::~InterfaceRegistry() {} | 24 InterfaceRegistry::~InterfaceRegistry() {} |
| 27 | 25 |
| 28 mojom::InterfaceProviderPtr InterfaceRegistry::TakeClientHandle() { | 26 mojom::InterfaceProviderPtr InterfaceRegistry::TakeClientHandle() { |
| 29 return std::move(client_handle_); | 27 return std::move(client_handle_); |
| 30 } | 28 } |
| 31 | 29 |
| 32 mojom::InterfaceProvider* InterfaceRegistry::GetRemoteInterfaces() { | 30 void InterfaceRegistry::Bind( |
| 33 return remote_interfaces_.get(); | 31 mojom::InterfaceProviderRequest local_interfaces_request) { |
| 32 binding_.Bind(std::move(local_interfaces_request)); |
| 34 } | 33 } |
| 35 | 34 |
| 36 void InterfaceRegistry::SetRemoteInterfacesConnectionLostClosure( | 35 void InterfaceRegistry::RemoveInterface(const std::string& name) { |
| 37 const base::Closure& connection_lost_closure) { | 36 auto it = name_to_binder_.find(name); |
| 38 remote_interfaces_.set_connection_error_handler(connection_lost_closure); | 37 if (it != name_to_binder_.end()) |
| 38 name_to_binder_.erase(it); |
| 39 } | 39 } |
| 40 | 40 |
| 41 // mojom::InterfaceProvider: | 41 // mojom::InterfaceProvider: |
| 42 void InterfaceRegistry::GetInterface(const mojo::String& interface_name, | 42 void InterfaceRegistry::GetInterface(const mojo::String& interface_name, |
| 43 mojo::ScopedMessagePipeHandle handle) { | 43 mojo::ScopedMessagePipeHandle handle) { |
| 44 auto iter = name_to_binder_.find(interface_name); | 44 auto iter = name_to_binder_.find(interface_name); |
| 45 if (iter != name_to_binder_.end()) { | 45 if (iter != name_to_binder_.end()) { |
| 46 iter->second->BindInterface(connection_, interface_name, std::move(handle)); | 46 iter->second->BindInterface(connection_, interface_name, std::move(handle)); |
| 47 } else if (connection_ && connection_->AllowsInterface(interface_name)) { | 47 } else if (connection_ && connection_->AllowsInterface(interface_name)) { |
| 48 LOG(ERROR) << "Connection CapabilityFilter prevented binding to " | 48 LOG(ERROR) << "Connection CapabilityFilter prevented binding to " |
| 49 << "interface: " << interface_name << " connection_name:" | 49 << "interface: " << interface_name << " connection_name:" |
| 50 << connection_->GetConnectionName() << " remote_name:" | 50 << connection_->GetConnectionName() << " remote_name:" |
| 51 << connection_->GetRemoteIdentity().name(); | 51 << connection_->GetRemoteIdentity().name(); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool InterfaceRegistry::SetInterfaceBinderForName( | 55 bool InterfaceRegistry::SetInterfaceBinderForName( |
| 56 std::unique_ptr<InterfaceBinder> binder, | 56 std::unique_ptr<InterfaceBinder> binder, |
| 57 const std::string& interface_name) { | 57 const std::string& interface_name) { |
| 58 if (!connection_ || | 58 if (!connection_ || |
| 59 (connection_ && connection_->AllowsInterface(interface_name))) { | 59 (connection_ && connection_->AllowsInterface(interface_name))) { |
| 60 RemoveInterfaceBinderForName(interface_name); | 60 RemoveInterface(interface_name); |
| 61 name_to_binder_[interface_name] = std::move(binder); | 61 name_to_binder_[interface_name] = std::move(binder); |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 return false; | 64 return false; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void InterfaceRegistry::RemoveInterfaceBinderForName( | |
| 68 const std::string& interface_name) { | |
| 69 NameToInterfaceBinderMap::iterator it = name_to_binder_.find(interface_name); | |
| 70 if (it == name_to_binder_.end()) | |
| 71 return; | |
| 72 name_to_binder_.erase(it); | |
| 73 } | |
| 74 | |
| 75 } // namespace shell | 67 } // namespace shell |
| OLD | NEW |