| 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_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ | 5 #ifndef MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ |
| 6 #define MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ | 6 #define MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ |
| 7 | 7 |
| 8 #include "mojo/public/cpp/application/lib/service_connector.h" | 8 #include "mojo/public/cpp/application/lib/service_connector.h" |
| 9 #include "mojo/public/cpp/bindings/binding.h" |
| 9 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 10 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
| 10 | 11 |
| 11 namespace mojo { | 12 namespace mojo { |
| 12 namespace internal { | 13 namespace internal { |
| 13 class WeakServiceProvider; | |
| 14 class ServiceConnectorBase; | 14 class ServiceConnectorBase; |
| 15 } | 15 } |
| 16 | 16 |
| 17 // Implements a registry that can be used to expose services to another app. | 17 // Implements a registry that can be used to expose services to another app. |
| 18 class ServiceProviderImpl : public InterfaceImpl<ServiceProvider> { | 18 class ServiceProviderImpl : public ServiceProvider { |
| 19 public: | 19 public: |
| 20 ServiceProviderImpl(); | 20 ServiceProviderImpl(); |
| 21 explicit ServiceProviderImpl(InterfaceRequest<ServiceProvider> request); |
| 21 ~ServiceProviderImpl() override; | 22 ~ServiceProviderImpl() override; |
| 22 | 23 |
| 24 void Bind(InterfaceRequest<ServiceProvider> request); |
| 25 |
| 23 template <typename Interface> | 26 template <typename Interface> |
| 24 void AddService(InterfaceFactory<Interface>* factory) { | 27 void AddService(InterfaceFactory<Interface>* factory) { |
| 25 AddServiceConnector( | 28 AddServiceConnector( |
| 26 new internal::InterfaceFactoryConnector<Interface>(factory)); | 29 new internal::InterfaceFactoryConnector<Interface>(factory)); |
| 27 } | 30 } |
| 28 | 31 |
| 29 // Returns an instance of a ServiceProvider that weakly wraps this impl's | |
| 30 // connection to some other app. Whereas the lifetime of an instance of | |
| 31 // ServiceProviderImpl is bound to the lifetime of the pipe it | |
| 32 // encapsulates, the lifetime of the ServiceProvider instance returned by this | |
| 33 // method is assumed by the caller. After the pipe is closed | |
| 34 // ConnectToService() calls on this object will be silently dropped. | |
| 35 // This method must only be called once per ServiceProviderImpl. | |
| 36 ServiceProvider* CreateRemoteServiceProvider(); | |
| 37 | |
| 38 private: | 32 private: |
| 39 typedef std::map<std::string, internal::ServiceConnectorBase*> | 33 typedef std::map<std::string, internal::ServiceConnectorBase*> |
| 40 NameToServiceConnectorMap; | 34 NameToServiceConnectorMap; |
| 41 | 35 |
| 42 friend class internal::WeakServiceProvider; | |
| 43 | |
| 44 // Overridden from ServiceProvider: | 36 // Overridden from ServiceProvider: |
| 45 void ConnectToService(const String& service_name, | 37 void ConnectToService(const String& service_name, |
| 46 ScopedMessagePipeHandle client_handle) override; | 38 ScopedMessagePipeHandle client_handle) override; |
| 47 | 39 |
| 48 // Overridden from InterfaceImpl: | |
| 49 void OnConnectionError() override; | |
| 50 | |
| 51 void AddServiceConnector(internal::ServiceConnectorBase* service_connector); | 40 void AddServiceConnector(internal::ServiceConnectorBase* service_connector); |
| 52 void RemoveServiceConnector( | 41 void RemoveServiceConnector( |
| 53 internal::ServiceConnectorBase* service_connector); | 42 internal::ServiceConnectorBase* service_connector); |
| 54 | 43 |
| 55 void ClearRemote(); | |
| 56 | |
| 57 NameToServiceConnectorMap service_connectors_; | 44 NameToServiceConnectorMap service_connectors_; |
| 58 | 45 |
| 59 internal::WeakServiceProvider* remote_; | 46 Binding<ServiceProvider> binding_; |
| 60 | 47 |
| 61 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceProviderImpl); | 48 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceProviderImpl); |
| 62 }; | 49 }; |
| 63 | 50 |
| 64 } // namespace mojo | 51 } // namespace mojo |
| 65 | 52 |
| 66 #endif // MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ | 53 #endif // MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ |
| OLD | NEW |