| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/application/public/cpp/lib/service_registry.h" | 5 #include "mojo/application/public/cpp/lib/service_registry.h" |
| 6 | 6 |
| 7 #include "mojo/application/public/cpp/application_connection.h" | 7 #include "mojo/application/public/cpp/application_connection.h" |
| 8 #include "mojo/application/public/cpp/application_impl.h" | 8 #include "mojo/application/public/cpp/application_impl.h" |
| 9 #include "mojo/application/public/cpp/service_connector.h" | 9 #include "mojo/application/public/cpp/service_connector.h" |
| 10 | 10 |
| 11 namespace mojo { | 11 namespace mojo { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 ServiceRegistry::ServiceRegistry( | 14 ServiceRegistry::ServiceRegistry( |
| 15 ApplicationImpl* application_impl, | 15 ApplicationImpl* application_impl, |
| 16 const std::string& connection_url, | 16 const std::string& connection_url, |
| 17 const std::string& remote_url, | 17 const std::string& remote_url, |
| 18 ServiceProviderPtr remote_services, | 18 ServiceProviderPtr remote_services, |
| 19 InterfaceRequest<ServiceProvider> local_services) | 19 InterfaceRequest<ServiceProvider> local_services, |
| 20 const std::set<std::string>& allowed_interfaces) |
| 20 : application_impl_(application_impl), | 21 : application_impl_(application_impl), |
| 21 connection_url_(connection_url), | 22 connection_url_(connection_url), |
| 22 remote_url_(remote_url), | 23 remote_url_(remote_url), |
| 23 local_binding_(this), | 24 local_binding_(this), |
| 24 remote_service_provider_(remote_services.Pass()) { | 25 remote_service_provider_(remote_services.Pass()), |
| 26 allowed_interfaces_(allowed_interfaces), |
| 27 allow_all_interfaces_(allowed_interfaces_.size() == 1 && |
| 28 allowed_interfaces_.count("*") == 1) { |
| 25 if (local_services.is_pending()) | 29 if (local_services.is_pending()) |
| 26 local_binding_.Bind(local_services.Pass()); | 30 local_binding_.Bind(local_services.Pass()); |
| 27 } | 31 } |
| 28 | 32 |
| 29 ServiceRegistry::ServiceRegistry() | 33 ServiceRegistry::ServiceRegistry() |
| 30 : application_impl_(nullptr), local_binding_(this) { | 34 : application_impl_(nullptr), |
| 35 local_binding_(this), |
| 36 allow_all_interfaces_(true) { |
| 31 } | 37 } |
| 32 | 38 |
| 33 void ServiceRegistry::SetServiceConnector(ServiceConnector* connector) { | 39 void ServiceRegistry::SetServiceConnector(ServiceConnector* connector) { |
| 34 service_connector_registry_.set_service_connector(connector); | 40 service_connector_registry_.set_service_connector(connector); |
| 35 } | 41 } |
| 36 | 42 |
| 37 void ServiceRegistry::SetServiceConnectorForName( | 43 bool ServiceRegistry::SetServiceConnectorForName( |
| 38 ServiceConnector* service_connector, | 44 ServiceConnector* service_connector, |
| 39 const std::string& interface_name) { | 45 const std::string& interface_name) { |
| 40 service_connector_registry_.SetServiceConnectorForName(service_connector, | 46 if (allow_all_interfaces_ || |
| 41 interface_name); | 47 allowed_interfaces_.count(interface_name)) { |
| 48 service_connector_registry_.SetServiceConnectorForName(service_connector, |
| 49 interface_name); |
| 50 return true; |
| 51 } |
| 52 DVLOG(2) << "CapabilityFilter prevented connection to interface: " << |
| 53 interface_name; |
| 54 return false; |
| 42 } | 55 } |
| 43 | 56 |
| 44 ServiceProvider* ServiceRegistry::GetLocalServiceProvider() { | 57 ServiceProvider* ServiceRegistry::GetLocalServiceProvider() { |
| 45 return this; | 58 return this; |
| 46 } | 59 } |
| 47 | 60 |
| 61 void ServiceRegistry::SetRemoteServiceProviderConnectionErrorHandler( |
| 62 const Closure& handler) { |
| 63 remote_service_provider_.set_connection_error_handler(handler); |
| 64 } |
| 65 |
| 48 void ServiceRegistry::RemoveServiceConnectorForName( | 66 void ServiceRegistry::RemoveServiceConnectorForName( |
| 49 const std::string& interface_name) { | 67 const std::string& interface_name) { |
| 50 service_connector_registry_.RemoveServiceConnectorForName(interface_name); | 68 service_connector_registry_.RemoveServiceConnectorForName(interface_name); |
| 51 if (service_connector_registry_.empty()) | 69 if (service_connector_registry_.empty()) |
| 52 remote_service_provider_.reset(); | 70 remote_service_provider_.reset(); |
| 53 } | 71 } |
| 54 | 72 |
| 55 const std::string& ServiceRegistry::GetConnectionURL() { | 73 const std::string& ServiceRegistry::GetConnectionURL() { |
| 56 return connection_url_; | 74 return connection_url_; |
| 57 } | 75 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 73 } | 91 } |
| 74 | 92 |
| 75 void ServiceRegistry::ConnectToService(const mojo::String& service_name, | 93 void ServiceRegistry::ConnectToService(const mojo::String& service_name, |
| 76 ScopedMessagePipeHandle client_handle) { | 94 ScopedMessagePipeHandle client_handle) { |
| 77 service_connector_registry_.ConnectToService(this, service_name, | 95 service_connector_registry_.ConnectToService(this, service_name, |
| 78 client_handle.Pass()); | 96 client_handle.Pass()); |
| 79 } | 97 } |
| 80 | 98 |
| 81 } // namespace internal | 99 } // namespace internal |
| 82 } // namespace mojo | 100 } // namespace mojo |
| OLD | NEW |