| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ | |
| 6 #define MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "mojo/public/cpp/application/lib/interface_factory_connector.h" | |
| 11 #include "mojo/public/cpp/application/lib/service_connector_registry.h" | |
| 12 #include "mojo/public/cpp/bindings/binding.h" | |
| 13 #include "mojo/public/interfaces/application/service_provider.mojom.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 | |
| 17 // Implements a registry that can be used to expose services to another app. | |
| 18 class ServiceProviderImpl : public ServiceProvider { | |
| 19 public: | |
| 20 ServiceProviderImpl(); | |
| 21 explicit ServiceProviderImpl(InterfaceRequest<ServiceProvider> request); | |
| 22 ~ServiceProviderImpl() override; | |
| 23 | |
| 24 void Bind(InterfaceRequest<ServiceProvider> request); | |
| 25 // Disconnect this service provider and put it in a state where it can be | |
| 26 // rebound to a new request. | |
| 27 void Close(); | |
| 28 | |
| 29 template <typename Interface> | |
| 30 void AddService(InterfaceFactory<Interface>* factory) { | |
| 31 SetServiceConnectorForName( | |
| 32 new internal::InterfaceFactoryConnector<Interface>(factory), | |
| 33 Interface::Name_); | |
| 34 } | |
| 35 | |
| 36 private: | |
| 37 // Overridden from ServiceProvider: | |
| 38 void ConnectToService(const String& service_name, | |
| 39 ScopedMessagePipeHandle client_handle) override; | |
| 40 | |
| 41 void SetServiceConnectorForName(ServiceConnector* service_connector, | |
| 42 const std::string& interface_name); | |
| 43 | |
| 44 Binding<ServiceProvider> binding_; | |
| 45 | |
| 46 internal::ServiceConnectorRegistry service_connector_registry_; | |
| 47 | |
| 48 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceProviderImpl); | |
| 49 }; | |
| 50 | |
| 51 } // namespace mojo | |
| 52 | |
| 53 #endif // MOJO_PUBLIC_APPLICATION_SERVICE_PROVIDER_IMPL_H_ | |
| OLD | NEW |