service_registry.h revision 116680a4aac90f2aa7413d9095a592090648e557
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_CPP_APPLICATION_LIB_SERVICE_REGISTRY_H_
6#define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_REGISTRY_H_
7
8#include "mojo/public/cpp/application/application_connection.h"
9#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
10
11namespace mojo {
12
13class ApplicationImpl;
14
15namespace internal {
16
17class ServiceConnectorBase;
18
19// A ServiceRegistry represents each half of a connection between two
20// applications, allowing customization of which services are published to the
21// other.
22class ServiceRegistry : public ServiceProvider, public ApplicationConnection {
23 public:
24  ServiceRegistry();
25  ServiceRegistry(ApplicationImpl* application_impl,
26                  const std::string& url,
27                  ServiceProviderPtr service_provider);
28  virtual ~ServiceRegistry();
29
30  // ApplicationConnection overrides.
31  virtual void AddServiceConnector(ServiceConnectorBase* service_connector)
32      MOJO_OVERRIDE;
33  virtual const std::string& GetRemoteApplicationURL() MOJO_OVERRIDE;
34  virtual ApplicationConnection* ConnectToApplication(
35      const std::string& url) MOJO_OVERRIDE;
36  virtual ServiceProvider* GetServiceProvider() MOJO_OVERRIDE;
37
38  virtual void RemoveServiceConnector(ServiceConnectorBase* service_connector);
39
40 private:
41  // ServiceProvider method.
42  virtual void ConnectToService(const mojo::String& service_name,
43                                ScopedMessagePipeHandle client_handle)
44      MOJO_OVERRIDE;
45
46  ApplicationImpl* application_impl_;
47  const std::string url_;
48
49 private:
50  bool RemoveServiceConnectorInternal(
51      ServiceConnectorBase* service_connector);
52
53  Application* application_;
54  typedef std::map<std::string, ServiceConnectorBase*>
55      NameToServiceConnectorMap;
56  NameToServiceConnectorMap name_to_service_connector_;
57  ServiceProviderPtr remote_service_provider_;
58
59  MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceRegistry);
60};
61
62}  // namespace internal
63}  // namespace mojo
64
65#endif  // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_REGISTRY_H_
66