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