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