| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mojo/public/cpp/application/lib/service_connector_registry.h" | 5 #include "mojo/public/cpp/application/lib/service_connector_registry.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "mojo/public/cpp/application/application_connection.h" |
| 10 #include "mojo/public/cpp/application/connection_context.h" |
| 9 #include "mojo/public/cpp/application/service_connector.h" | 11 #include "mojo/public/cpp/application/service_connector.h" |
| 10 | 12 |
| 11 namespace mojo { | 13 namespace mojo { |
| 12 namespace internal { | 14 namespace internal { |
| 13 | 15 |
| 14 ServiceConnectorRegistry::ServiceConnectorRegistry() {} | 16 ServiceConnectorRegistry::ServiceConnectorRegistry() {} |
| 15 | 17 |
| 16 ServiceConnectorRegistry::~ServiceConnectorRegistry() {} | 18 ServiceConnectorRegistry::~ServiceConnectorRegistry() {} |
| 17 | 19 |
| 18 void ServiceConnectorRegistry::SetServiceConnectorForName( | 20 void ServiceConnectorRegistry::SetServiceConnectorForName( |
| 19 std::unique_ptr<ServiceConnector> service_connector, | 21 std::unique_ptr<ServiceConnector> service_connector, |
| 20 const std::string& interface_name) { | 22 const std::string& interface_name) { |
| 21 name_to_service_connector_[interface_name] = std::move(service_connector); | 23 name_to_service_connector_[interface_name] = std::move(service_connector); |
| 22 } | 24 } |
| 23 | 25 |
| 24 void ServiceConnectorRegistry::RemoveServiceConnectorForName( | 26 void ServiceConnectorRegistry::RemoveServiceConnectorForName( |
| 25 const std::string& interface_name) { | 27 const std::string& interface_name) { |
| 26 NameToServiceConnectorMap::iterator it = | 28 NameToServiceConnectorMap::iterator it = |
| 27 name_to_service_connector_.find(interface_name); | 29 name_to_service_connector_.find(interface_name); |
| 28 if (it == name_to_service_connector_.end()) | 30 if (it == name_to_service_connector_.end()) |
| 29 return; | 31 return; |
| 30 name_to_service_connector_.erase(it); | 32 name_to_service_connector_.erase(it); |
| 31 } | 33 } |
| 32 | 34 |
| 33 bool ServiceConnectorRegistry::ConnectToService( | 35 bool ServiceConnectorRegistry::ConnectToService( |
| 34 ApplicationConnection* application_connection, | 36 const ConnectionContext& connection_context, |
| 35 const std::string& interface_name, | 37 const std::string& interface_name, |
| 36 ScopedMessagePipeHandle* client_handle) { | 38 ScopedMessagePipeHandle* client_handle) { |
| 37 auto iter = name_to_service_connector_.find(interface_name); | 39 auto iter = name_to_service_connector_.find(interface_name); |
| 38 if (iter != name_to_service_connector_.end()) { | 40 if (iter != name_to_service_connector_.end()) { |
| 39 iter->second->ConnectToService(application_connection, interface_name, | 41 iter->second->ConnectToService(connection_context, interface_name, |
| 40 client_handle->Pass()); | 42 client_handle->Pass()); |
| 41 return true; | 43 return true; |
| 42 } | 44 } |
| 43 return false; | 45 return false; |
| 44 } | 46 } |
| 45 | 47 |
| 46 } // namespace internal | 48 } // namespace internal |
| 47 } // namespace mojo | 49 } // namespace mojo |
| OLD | NEW |