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/application/public/interfaces/shell.mojom.h"
15 #include "mojo/public/cpp/bindings/binding.h"
20 // A ServiceRegistry represents each half of a connection between two
21 // applications, allowing customization of which services are published to the
23 class ServiceRegistry
: public ServiceProvider
, public ApplicationConnection
{
26 // |allowed_interfaces| are the set of interfaces that the shell has allowed
27 // an application to expose to another application. If this set contains only
28 // the string value "*" all interfaces may be exposed.
29 ServiceRegistry(const std::string
& connection_url
,
30 const std::string
& remote_url
,
31 ServiceProviderPtr remote_services
,
32 InterfaceRequest
<ServiceProvider
> local_services
,
33 const std::set
<std::string
>& allowed_interfaces
);
34 ~ServiceRegistry() override
;
36 Shell::ConnectToApplicationCallback
GetConnectToApplicationCallback();
38 // ApplicationConnection overrides.
39 void SetServiceConnector(ServiceConnector
* service_connector
) override
;
40 bool SetServiceConnectorForName(ServiceConnector
* service_connector
,
41 const std::string
& interface_name
) override
;
42 const std::string
& GetConnectionURL() override
;
43 const std::string
& GetRemoteApplicationURL() override
;
44 ServiceProvider
* GetServiceProvider() override
;
45 ServiceProvider
* GetLocalServiceProvider() override
;
46 void SetRemoteServiceProviderConnectionErrorHandler(
47 const Closure
& handler
) override
;
48 bool GetContentHandlerID(uint32_t* target_id
) override
;
49 void AddContentHandlerIDCallback(const Closure
& callback
) override
;
50 base::WeakPtr
<ApplicationConnection
> GetWeakPtr() override
;
52 void RemoveServiceConnectorForName(const std::string
& interface_name
);
55 void OnGotContentHandlerID(uint32_t content_handler_id
);
57 // ServiceProvider method.
58 void ConnectToService(const mojo::String
& service_name
,
59 ScopedMessagePipeHandle client_handle
) override
;
61 const std::string connection_url_
;
62 const std::string remote_url_
;
63 Binding
<ServiceProvider
> local_binding_
;
64 ServiceProviderPtr remote_service_provider_
;
65 ServiceConnectorRegistry service_connector_registry_
;
66 const std::set
<std::string
> allowed_interfaces_
;
67 const bool allow_all_interfaces_
;
68 // The id of the content_handler is only available once the callback from
69 // establishing the connection is made.
70 uint32_t content_handler_id_
;
71 bool is_content_handler_id_valid_
;
72 std::vector
<Closure
> content_handler_id_callbacks_
;
73 base::WeakPtrFactory
<ServiceRegistry
> weak_factory_
;
75 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceRegistry
);
78 } // namespace internal
81 #endif // MOJO_APPLICATION_PUBLIC_CPP_LIB_SERVICE_REGISTRY_H_