[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / content / common / mojo / service_registry_impl.h
blobc2346766286a456642d046ae8f6b87eadff6b5ec
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/bindings/error_handler.h"
20 #include "third_party/mojo/src/mojo/public/cpp/system/core.h"
22 namespace content {
24 class CONTENT_EXPORT ServiceRegistryImpl
25 : public ServiceRegistry,
26 public NON_EXPORTED_BASE(mojo::ServiceProvider),
27 public NON_EXPORTED_BASE(mojo::ErrorHandler) {
28 public:
29 ServiceRegistryImpl();
30 ~ServiceRegistryImpl() override;
32 // Binds this ServiceProvider implementation to a message pipe endpoint.
33 void Bind(mojo::InterfaceRequest<mojo::ServiceProvider> request);
35 // Binds to a remote ServiceProvider. This will expose added services to the
36 // remote ServiceProvider with the corresponding handle and enable
37 // ConnectToRemoteService to provide access to services exposed by the remote
38 // ServiceProvider.
39 void BindRemoteServiceProvider(mojo::ServiceProviderPtr service_provider);
41 // ServiceRegistry overrides.
42 void AddService(const std::string& service_name,
43 const base::Callback<void(mojo::ScopedMessagePipeHandle)>
44 service_factory) override;
45 void RemoveService(const std::string& service_name) override;
46 void ConnectToRemoteService(const base::StringPiece& service_name,
47 mojo::ScopedMessagePipeHandle handle) override;
49 bool IsBound() const;
51 base::WeakPtr<ServiceRegistry> GetWeakPtr();
53 private:
54 // mojo::ServiceProvider overrides.
55 void ConnectToService(const mojo::String& name,
56 mojo::ScopedMessagePipeHandle client_handle) override;
58 // mojo::ErrorHandler overrides.
59 void OnConnectionError() override;
61 mojo::Binding<mojo::ServiceProvider> binding_;
62 mojo::ServiceProviderPtr remote_provider_;
64 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> >
65 service_factories_;
66 std::queue<std::pair<std::string, mojo::MessagePipeHandle> >
67 pending_connects_;
69 base::WeakPtrFactory<ServiceRegistry> weak_factory_;
72 } // namespace content
74 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_