Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / common / mojo / service_registry_impl.h
blobfe78364bb223cea3241f09a55be4019d161d0b87
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.
5 #ifndef CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_
6 #define CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_
8 #include <map>
9 #include <queue>
10 #include <string>
11 #include <utility>
13 #include "base/callback.h"
14 #include "base/memory/weak_ptr.h"
15 #include "content/public/common/service_registry.h"
16 #include "mojo/public/cpp/bindings/interface_impl.h"
17 #include "mojo/public/cpp/system/core.h"
18 #include "mojo/public/interfaces/application/service_provider.mojom.h"
20 namespace content {
22 class ServiceRegistryImpl : public ServiceRegistry,
23 public mojo::InterfaceImpl<mojo::ServiceProvider> {
24 public:
25 ServiceRegistryImpl();
26 explicit ServiceRegistryImpl(mojo::ScopedMessagePipeHandle handle);
27 virtual ~ServiceRegistryImpl();
29 // Binds to a remote ServiceProvider. This will expose added services to the
30 // remote ServiceProvider with the corresponding handle and enable
31 // ConnectToRemoteService to provide access to services exposed by the remote
32 // ServiceProvider.
33 void BindRemoteServiceProvider(mojo::ScopedMessagePipeHandle handle);
35 // ServiceRegistry overrides.
36 virtual void AddService(
37 const std::string& service_name,
38 const base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory)
39 OVERRIDE;
40 virtual void RemoveService(const std::string& service_name) OVERRIDE;
41 virtual void ConnectToRemoteService(
42 const base::StringPiece& service_name,
43 mojo::ScopedMessagePipeHandle handle) OVERRIDE;
45 base::WeakPtr<ServiceRegistry> GetWeakPtr();
47 private:
48 // mojo::InterfaceImpl<mojo::ServiceProvider> overrides.
49 virtual void ConnectToService(
50 const mojo::String& name,
51 mojo::ScopedMessagePipeHandle client_handle) OVERRIDE;
52 virtual void OnConnectionError() OVERRIDE;
54 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> >
55 service_factories_;
56 std::queue<std::pair<std::string, mojo::MessagePipeHandle> >
57 pending_connects_;
58 bool bound_;
60 base::WeakPtrFactory<ServiceRegistry> weak_factory_;
63 } // namespace content
65 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_