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
3 // found in the LICENSE file.
5 #include "mojo/application/public/cpp/lib/service_registry.h"
7 #include "mojo/application/public/cpp/application_connection.h"
8 #include "mojo/application/public/cpp/application_impl.h"
9 #include "mojo/application/public/cpp/service_connector.h"
14 ServiceRegistry::ServiceRegistry(
15 ApplicationImpl
* application_impl
,
16 const std::string
& connection_url
,
17 const std::string
& remote_url
,
18 ServiceProviderPtr remote_services
,
19 InterfaceRequest
<ServiceProvider
> local_services
,
20 const std::set
<std::string
>& allowed_interfaces
)
21 : application_impl_(application_impl
),
22 connection_url_(connection_url
),
23 remote_url_(remote_url
),
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) {
29 if (local_services
.is_pending())
30 local_binding_
.Bind(local_services
.Pass());
33 ServiceRegistry::ServiceRegistry()
34 : application_impl_(nullptr),
36 allow_all_interfaces_(true) {
39 void ServiceRegistry::SetServiceConnector(ServiceConnector
* connector
) {
40 service_connector_registry_
.set_service_connector(connector
);
43 bool ServiceRegistry::SetServiceConnectorForName(
44 ServiceConnector
* service_connector
,
45 const std::string
& interface_name
) {
46 if (allow_all_interfaces_
||
47 allowed_interfaces_
.count(interface_name
)) {
48 service_connector_registry_
.SetServiceConnectorForName(service_connector
,
52 DVLOG(2) << "CapabilityFilter prevented connection to interface: " <<
57 ServiceProvider
* ServiceRegistry::GetLocalServiceProvider() {
61 void ServiceRegistry::SetRemoteServiceProviderConnectionErrorHandler(
62 const Closure
& handler
) {
63 remote_service_provider_
.set_connection_error_handler(handler
);
66 void ServiceRegistry::RemoveServiceConnectorForName(
67 const std::string
& interface_name
) {
68 service_connector_registry_
.RemoveServiceConnectorForName(interface_name
);
69 if (service_connector_registry_
.empty())
70 remote_service_provider_
.reset();
73 const std::string
& ServiceRegistry::GetConnectionURL() {
74 return connection_url_
;
77 const std::string
& ServiceRegistry::GetRemoteApplicationURL() {
81 ServiceProvider
* ServiceRegistry::GetServiceProvider() {
82 return remote_service_provider_
.get();
85 ServiceRegistry::~ServiceRegistry() {
88 void ServiceRegistry::OnCloseConnection() {
89 if (application_impl_
)
90 application_impl_
->CloseConnection(this);
93 void ServiceRegistry::ConnectToService(const mojo::String
& service_name
,
94 ScopedMessagePipeHandle client_handle
) {
95 service_connector_registry_
.ConnectToService(this, service_name
,
96 client_handle
.Pass());
99 } // namespace internal