OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ | 5 #ifndef CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ |
6 #define CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ | 6 #define CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "content/public/common/service_registry.h" | 16 #include "content/public/common/service_registry.h" |
17 #include "mojo/public/cpp/bindings/binding.h" | 17 #include "mojo/public/cpp/bindings/binding.h" |
18 #include "mojo/public/cpp/system/core.h" | 18 #include "mojo/public/cpp/system/core.h" |
19 #include "services/shell/public/interfaces/interface_provider.mojom.h" | 19 #include "services/shell/public/interfaces/interface_provider.mojom.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 class CONTENT_EXPORT ServiceRegistryImpl | 23 class CONTENT_EXPORT ServiceRegistryImpl |
24 : public ServiceRegistry, | 24 : public ServiceRegistry, |
25 public NON_EXPORTED_BASE(mojo::shell::mojom::InterfaceProvider) { | 25 public NON_EXPORTED_BASE(shell::mojom::InterfaceProvider) { |
26 public: | 26 public: |
27 using ServiceFactory = base::Callback<void(mojo::ScopedMessagePipeHandle)>; | 27 using ServiceFactory = base::Callback<void(mojo::ScopedMessagePipeHandle)>; |
28 | 28 |
29 ServiceRegistryImpl(); | 29 ServiceRegistryImpl(); |
30 ~ServiceRegistryImpl() override; | 30 ~ServiceRegistryImpl() override; |
31 | 31 |
32 // Binds this ServiceProvider implementation to a message pipe endpoint. | 32 // Binds this ServiceProvider implementation to a message pipe endpoint. |
33 void Bind(mojo::shell::mojom::InterfaceProviderRequest request); | 33 void Bind(shell::mojom::InterfaceProviderRequest request); |
34 | 34 |
35 // Binds to a remote ServiceProvider. This will expose added services to the | 35 // Binds to a remote ServiceProvider. This will expose added services to the |
36 // remote ServiceProvider with the corresponding handle and enable | 36 // remote ServiceProvider with the corresponding handle and enable |
37 // ConnectToRemoteService to provide access to services exposed by the remote | 37 // ConnectToRemoteService to provide access to services exposed by the remote |
38 // ServiceProvider. | 38 // ServiceProvider. |
39 void BindRemoteServiceProvider( | 39 void BindRemoteServiceProvider( |
40 mojo::shell::mojom::InterfaceProviderPtr service_provider); | 40 shell::mojom::InterfaceProviderPtr service_provider); |
41 | 41 |
42 // ServiceRegistry overrides. | 42 // ServiceRegistry overrides. |
43 void AddService(const std::string& service_name, | 43 void AddService(const std::string& service_name, |
44 const ServiceFactory service_factory) override; | 44 const ServiceFactory service_factory) override; |
45 void RemoveService(const std::string& service_name) override; | 45 void RemoveService(const std::string& service_name) override; |
46 void ConnectToRemoteService(const base::StringPiece& service_name, | 46 void ConnectToRemoteService(const base::StringPiece& service_name, |
47 mojo::ScopedMessagePipeHandle handle) override; | 47 mojo::ScopedMessagePipeHandle handle) override; |
48 void AddServiceOverrideForTesting( | 48 void AddServiceOverrideForTesting( |
49 const std::string& service_name, | 49 const std::string& service_name, |
50 const ServiceFactory& service_factory) override; | 50 const ServiceFactory& service_factory) override; |
51 void ClearServiceOverridesForTesting() override; | 51 void ClearServiceOverridesForTesting() override; |
52 | 52 |
53 bool IsBound() const; | 53 bool IsBound() const; |
54 | 54 |
55 base::WeakPtr<ServiceRegistry> GetWeakPtr(); | 55 base::WeakPtr<ServiceRegistry> GetWeakPtr(); |
56 | 56 |
57 private: | 57 private: |
58 // mojo::InterfaceProvider overrides. | 58 // mojo::InterfaceProvider overrides. |
59 void GetInterface(const mojo::String& name, | 59 void GetInterface(const mojo::String& name, |
60 mojo::ScopedMessagePipeHandle client_handle) override; | 60 mojo::ScopedMessagePipeHandle client_handle) override; |
61 | 61 |
62 void OnConnectionError(); | 62 void OnConnectionError(); |
63 | 63 |
64 mojo::Binding<mojo::shell::mojom::InterfaceProvider> binding_; | 64 mojo::Binding<shell::mojom::InterfaceProvider> binding_; |
65 mojo::shell::mojom::InterfaceProviderPtr remote_provider_; | 65 shell::mojom::InterfaceProviderPtr remote_provider_; |
66 | 66 |
67 std::map<std::string, ServiceFactory> service_factories_; | 67 std::map<std::string, ServiceFactory> service_factories_; |
68 std::queue<std::pair<std::string, mojo::MessagePipeHandle> > | 68 std::queue<std::pair<std::string, mojo::MessagePipeHandle> > |
69 pending_connects_; | 69 pending_connects_; |
70 | 70 |
71 std::map<std::string, ServiceFactory> service_overrides_; | 71 std::map<std::string, ServiceFactory> service_overrides_; |
72 | 72 |
73 base::WeakPtrFactory<ServiceRegistry> weak_factory_; | 73 base::WeakPtrFactory<ServiceRegistry> weak_factory_; |
74 }; | 74 }; |
75 | 75 |
76 } // namespace content | 76 } // namespace content |
77 | 77 |
78 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ | 78 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ |
OLD | NEW |