GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / content / common / mojo / service_registry_impl.h
blob13aba813f6bb19033f065b3a02ca532c0965bab9
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 "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
18 #include "third_party/mojo/src/mojo/public/cpp/system/core.h"
19 #include "third_party/mojo/src/mojo/public/interfaces/application/service_provider.mojom.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 base::WeakPtr<ServiceRegistry> GetWeakPtr();
49 private:
50 // mojo::ServiceProvider overrides.
51 void ConnectToService(const mojo::String& name,
52 mojo::ScopedMessagePipeHandle client_handle) override;
54 mojo::Binding<mojo::ServiceProvider> binding_;
55 mojo::ServiceProviderPtr remote_provider_;
57 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> >
58 service_factories_;
59 std::queue<std::pair<std::string, mojo::MessagePipeHandle> >
60 pending_connects_;
62 base::WeakPtrFactory<ServiceRegistry> weak_factory_;
65 } // namespace content
67 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_