| 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_APPLICATION_PUBLIC_CPP_SERVICE_PROVIDER_IMPL_H_ | |
| 6 #define MOJO_APPLICATION_PUBLIC_CPP_SERVICE_PROVIDER_IMPL_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "mojo/application/public/cpp/lib/interface_factory_connector.h" | |
| 11 #include "mojo/application/public/cpp/lib/service_connector_registry.h" | |
| 12 #include "mojo/application/public/interfaces/service_provider.mojom.h" | |
| 13 #include "mojo/public/cpp/bindings/strong_binding.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 | |
| 26 template <typename Interface> | |
| 27 void AddService(InterfaceFactory<Interface>* factory) { | |
| 28 SetServiceConnectorForName( | |
| 29 new internal::InterfaceFactoryConnector<Interface>(factory), | |
| 30 Interface::Name_); | |
| 31 } | |
| 32 | |
| 33 private: | |
| 34 // Overridden from ServiceProvider: | |
| 35 void ConnectToService(const String& service_name, | |
| 36 ScopedMessagePipeHandle client_handle) override; | |
| 37 | |
| 38 void SetServiceConnectorForName(ServiceConnector* service_connector, | |
| 39 const std::string& interface_name); | |
| 40 | |
| 41 StrongBinding<ServiceProvider> binding_; | |
| 42 | |
| 43 internal::ServiceConnectorRegistry service_connector_registry_; | |
| 44 | |
| 45 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceProviderImpl); | |
| 46 }; | |
| 47 | |
| 48 } // namespace mojo | |
| 49 | |
| 50 #endif // MOJO_APPLICATION_PUBLIC_CPP_SERVICE_PROVIDER_IMPL_H_ | |
| OLD | NEW |