| Index: mojo/public/cpp/application/exported_service_registry.h
|
| diff --git a/mojo/public/cpp/application/exported_service_registry.h b/mojo/public/cpp/application/exported_service_registry.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b5026304574403a969b58706170485671b50d85d
|
| --- /dev/null
|
| +++ b/mojo/public/cpp/application/exported_service_registry.h
|
| @@ -0,0 +1,82 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef MOJO_PUBLIC_APPLICATION_EXPORTED_SERVICE_REGISTRY_H_
|
| +#define MOJO_PUBLIC_APPLICATION_EXPORTED_SERVICE_REGISTRY_H_
|
| +
|
| +#include "mojo/public/cpp/application/lib/service_connector.h"
|
| +#include "mojo/public/interfaces/application/service_provider.mojom.h"
|
| +
|
| +namespace mojo {
|
| +namespace internal {
|
| +class ServiceConnectorBase;
|
| +}
|
| +
|
| +class RemoteServiceProvider : public ServiceProvider {
|
| + public:
|
| + explicit RemoteServiceProvider(ServiceProvider* service_provider)
|
| + : service_provider_(service_provider) {}
|
| + virtual ~RemoteServiceProvider() {}
|
| +
|
| + void Clear() {
|
| + service_provider_ = NULL;
|
| + }
|
| +
|
| + virtual void ConnectToService(
|
| + const String& service_name,
|
| + ScopedMessagePipeHandle client_handle) MOJO_OVERRIDE {
|
| + if (service_provider_)
|
| + service_provider_->ConnectToService(service_name, client_handle.Pass());
|
| + }
|
| +
|
| + private:
|
| + ServiceProvider* service_provider_;
|
| +
|
| + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteServiceProvider);
|
| +};
|
| +
|
| +class ExportedServiceRegistry : public InterfaceImpl<ServiceProvider> {
|
| + public:
|
| + ExportedServiceRegistry();
|
| + virtual ~ExportedServiceRegistry();
|
| +
|
| + template <typename Interface>
|
| + void AddService(InterfaceFactory<Interface>* factory) {
|
| + AddServiceConnector(
|
| + new internal::InterfaceFactoryConnector<Interface>(factory));
|
| + }
|
| +
|
| + void set_remote(RemoteServiceProvider* remote) { remote_ = remote; }
|
| +
|
| + private:
|
| + typedef std::map<std::string, internal::ServiceConnectorBase*>
|
| + NameToServiceConnectorMap;
|
| +
|
| + // Overridden from ServiceProvider:
|
| + virtual void ConnectToService(
|
| + const String& service_name,
|
| + ScopedMessagePipeHandle client_handle) MOJO_OVERRIDE;
|
| +
|
| + // Overridden from InterfaceImpl:
|
| + virtual void OnConnectionError() MOJO_OVERRIDE {
|
| + if (remote_)
|
| + remote_->Clear();
|
| + remote_ = NULL;
|
| + }
|
| +
|
| + void AddServiceConnector(
|
| + internal::ServiceConnectorBase* service_connector);
|
| + void RemoveServiceConnector(
|
| + internal::ServiceConnectorBase* service_connector);
|
| +
|
| + NameToServiceConnectorMap service_connectors_;
|
| +
|
| + RemoteServiceProvider* remote_;
|
| +
|
| + MOJO_DISALLOW_COPY_AND_ASSIGN(ExportedServiceRegistry);
|
| +};
|
| +
|
| +} // namespace mojo
|
| +
|
| +#endif // MOJO_PUBLIC_APPLICATION_EXPORTED_SERVICE_REGISTRY_H_
|
|
|