| 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 mojo { | 9 namespace shell { |
| 10 | 10 |
| 11 InterfaceRegistry::InterfaceRegistry(Connection* connection) | 11 InterfaceRegistry::InterfaceRegistry(Connection* connection) |
| 12 : InterfaceRegistry(nullptr, connection) {} | 12 : InterfaceRegistry(nullptr, connection) {} |
| 13 | 13 |
| 14 InterfaceRegistry::InterfaceRegistry( | 14 InterfaceRegistry::InterfaceRegistry(mojom::InterfaceProviderRequest request, |
| 15 shell::mojom::InterfaceProviderRequest request, | 15 Connection* connection) |
| 16 Connection* connection) | 16 : binding_(this), connection_(connection), default_binder_(nullptr) { |
| 17 : binding_(this), | |
| 18 connection_(connection), | |
| 19 default_binder_(nullptr) { | |
| 20 if (!request.is_pending()) | 17 if (!request.is_pending()) |
| 21 request = GetProxy(&client_handle_); | 18 request = GetProxy(&client_handle_); |
| 22 binding_.Bind(std::move(request)); | 19 binding_.Bind(std::move(request)); |
| 23 } | 20 } |
| 24 | 21 |
| 25 InterfaceRegistry::~InterfaceRegistry() { | 22 InterfaceRegistry::~InterfaceRegistry() { |
| 26 for (auto& i : name_to_binder_) | 23 for (auto& i : name_to_binder_) |
| 27 delete i.second; | 24 delete i.second; |
| 28 name_to_binder_.clear(); | 25 name_to_binder_.clear(); |
| 29 } | 26 } |
| 30 | 27 |
| 31 shell::mojom::InterfaceProviderPtr InterfaceRegistry::TakeClientHandle() { | 28 mojom::InterfaceProviderPtr InterfaceRegistry::TakeClientHandle() { |
| 32 return std::move(client_handle_); | 29 return std::move(client_handle_); |
| 33 } | 30 } |
| 34 | 31 |
| 35 // shell::mojom::InterfaceProvider: | 32 // mojom::InterfaceProvider: |
| 36 void InterfaceRegistry::GetInterface(const String& interface_name, | 33 void InterfaceRegistry::GetInterface(const mojo::String& interface_name, |
| 37 ScopedMessagePipeHandle handle) { | 34 mojo::ScopedMessagePipeHandle handle) { |
| 38 auto iter = name_to_binder_.find(interface_name); | 35 auto iter = name_to_binder_.find(interface_name); |
| 39 InterfaceBinder* binder = iter != name_to_binder_.end() ? iter->second : | 36 InterfaceBinder* binder = iter != name_to_binder_.end() ? iter->second : |
| 40 default_binder_; | 37 default_binder_; |
| 41 if (binder) | 38 if (binder) |
| 42 binder->BindInterface(connection_, interface_name, std::move(handle)); | 39 binder->BindInterface(connection_, interface_name, std::move(handle)); |
| 43 } | 40 } |
| 44 | 41 |
| 45 bool InterfaceRegistry::SetInterfaceBinderForName( | 42 bool InterfaceRegistry::SetInterfaceBinderForName( |
| 46 InterfaceBinder* binder, | 43 InterfaceBinder* binder, |
| 47 const std::string& interface_name) { | 44 const std::string& interface_name) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 | 57 |
| 61 void InterfaceRegistry::RemoveInterfaceBinderForName( | 58 void InterfaceRegistry::RemoveInterfaceBinderForName( |
| 62 const std::string& interface_name) { | 59 const std::string& interface_name) { |
| 63 NameToInterfaceBinderMap::iterator it = name_to_binder_.find(interface_name); | 60 NameToInterfaceBinderMap::iterator it = name_to_binder_.find(interface_name); |
| 64 if (it == name_to_binder_.end()) | 61 if (it == name_to_binder_.end()) |
| 65 return; | 62 return; |
| 66 delete it->second; | 63 delete it->second; |
| 67 name_to_binder_.erase(it); | 64 name_to_binder_.erase(it); |
| 68 } | 65 } |
| 69 | 66 |
| 70 } // namespace mojo | 67 } // namespace shell |
| OLD | NEW |