Update V8 to version 4.6.72.
[chromium-blink-merge.git] / content / common / mojo / service_registry_impl.h
blobb25ade991907b4ff55e2d2522820b7fae3755591
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/compiler_specific.h"
15 #include "base/memory/weak_ptr.h"
16 #include "content/public/common/service_registry.h"
17 #include "mojo/application/public/interfaces/service_provider.mojom.h"
18 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
19 #include "third_party/mojo/src/mojo/public/cpp/system/core.h"
21 namespace content {
23 class CONTENT_EXPORT ServiceRegistryImpl
24 : public ServiceRegistry,
25 public NON_EXPORTED_BASE(mojo::ServiceProvider) {
26 public:
27 ServiceRegistryImpl();
28 ~ServiceRegistryImpl() override;
30 // Binds this ServiceProvider implementation to a message pipe endpoint.
31 void Bind(mojo::InterfaceRequest<mojo::ServiceProvider> request);
33 // Binds to a remote ServiceProvider. This will expose added services to the
34 // remote ServiceProvider with the corresponding handle and enable
35 // ConnectToRemoteService to provide access to services exposed by the remote
36 // ServiceProvider.
37 void BindRemoteServiceProvider(mojo::ServiceProviderPtr service_provider);
39 // ServiceRegistry overrides.
40 void AddService(const std::string& service_name,
41 const base::Callback<void(mojo::ScopedMessagePipeHandle)>
42 service_factory) override;
43 void RemoveService(const std::string& service_name) override;
44 void ConnectToRemoteService(const base::StringPiece& service_name,
45 mojo::ScopedMessagePipeHandle handle) override;
47 bool IsBound() const;
49 base::WeakPtr<ServiceRegistry> GetWeakPtr();
51 private:
52 // mojo::ServiceProvider overrides.
53 void ConnectToService(const mojo::String& name,
54 mojo::ScopedMessagePipeHandle client_handle) override;
56 void OnConnectionError();
58 mojo::Binding<mojo::ServiceProvider> binding_;
59 mojo::ServiceProviderPtr remote_provider_;
61 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> >
62 service_factories_;
63 std::queue<std::pair<std::string, mojo::MessagePipeHandle> >
64 pending_connects_;
66 base::WeakPtrFactory<ServiceRegistry> weak_factory_;
69 } // namespace content
71 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_