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 #ifndef MOJO_APPLICATION_PUBLIC_CPP_LIB_SERVICE_REGISTRY_H_
6 #define MOJO_APPLICATION_PUBLIC_CPP_LIB_SERVICE_REGISTRY_H_
11 #include "mojo/application/public/cpp/application_connection.h"
12 #include "mojo/application/public/cpp/lib/service_connector_registry.h"
13 #include "mojo/application/public/interfaces/service_provider.mojom.h"
14 #include "mojo/public/cpp/bindings/binding.h"
19 // A ServiceRegistry represents each half of a connection between two
20 // applications, allowing customization of which services are published to the
22 class ServiceRegistry
: public ServiceProvider
, public ApplicationConnection
{
25 // |allowed_interfaces| are the set of interfaces that the shell has allowed
26 // an application to expose to another application. If this set contains only
27 // the string value "*" all interfaces may be exposed.
28 ServiceRegistry(const std::string
& connection_url
,
29 const std::string
& remote_url
,
30 ServiceProviderPtr remote_services
,
31 InterfaceRequest
<ServiceProvider
> local_services
,
32 const std::set
<std::string
>& allowed_interfaces
);
33 ~ServiceRegistry() override
;
35 // ApplicationConnection overrides.
36 void SetServiceConnector(ServiceConnector
* service_connector
) override
;
37 bool SetServiceConnectorForName(ServiceConnector
* service_connector
,
38 const std::string
& interface_name
) override
;
39 const std::string
& GetConnectionURL() override
;
40 const std::string
& GetRemoteApplicationURL() override
;
41 ServiceProvider
* GetServiceProvider() override
;
42 ServiceProvider
* GetLocalServiceProvider() override
;
43 void SetRemoteServiceProviderConnectionErrorHandler(
44 const Closure
& handler
) override
;
45 base::WeakPtr
<ApplicationConnection
> GetWeakPtr() override
;
47 void RemoveServiceConnectorForName(const std::string
& interface_name
);
50 // ServiceProvider method.
51 void ConnectToService(const mojo::String
& service_name
,
52 ScopedMessagePipeHandle client_handle
) override
;
54 const std::string connection_url_
;
55 const std::string remote_url_
;
56 Binding
<ServiceProvider
> local_binding_
;
57 ServiceProviderPtr remote_service_provider_
;
58 ServiceConnectorRegistry service_connector_registry_
;
59 const std::set
<std::string
> allowed_interfaces_
;
60 const bool allow_all_interfaces_
;
61 base::WeakPtrFactory
<ApplicationConnection
> weak_factory_
;
63 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceRegistry
);
66 } // namespace internal
69 #endif // MOJO_APPLICATION_PUBLIC_CPP_LIB_SERVICE_REGISTRY_H_