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/application/public/interfaces/service_provider.mojom.h" | 17 #include "mojo/application/public/interfaces/service_provider.mojom.h" |
18 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.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" |
19 #include "third_party/mojo/src/mojo/public/cpp/system/core.h" | 20 #include "third_party/mojo/src/mojo/public/cpp/system/core.h" |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 class CONTENT_EXPORT ServiceRegistryImpl | 24 class CONTENT_EXPORT ServiceRegistryImpl |
24 : public ServiceRegistry, | 25 : public ServiceRegistry, |
25 public NON_EXPORTED_BASE(mojo::ServiceProvider) { | 26 public NON_EXPORTED_BASE(mojo::ServiceProvider), |
| 27 public NON_EXPORTED_BASE(mojo::ErrorHandler) { |
26 public: | 28 public: |
27 ServiceRegistryImpl(); | 29 ServiceRegistryImpl(); |
28 ~ServiceRegistryImpl() override; | 30 ~ServiceRegistryImpl() override; |
29 | 31 |
30 // Binds this ServiceProvider implementation to a message pipe endpoint. | 32 // Binds this ServiceProvider implementation to a message pipe endpoint. |
31 void Bind(mojo::InterfaceRequest<mojo::ServiceProvider> request); | 33 void Bind(mojo::InterfaceRequest<mojo::ServiceProvider> request); |
32 | 34 |
33 // 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 |
34 // remote ServiceProvider with the corresponding handle and enable | 36 // remote ServiceProvider with the corresponding handle and enable |
35 // ConnectToRemoteService to provide access to services exposed by the remote | 37 // ConnectToRemoteService to provide access to services exposed by the remote |
36 // ServiceProvider. | 38 // ServiceProvider. |
37 void BindRemoteServiceProvider(mojo::ServiceProviderPtr service_provider); | 39 void BindRemoteServiceProvider(mojo::ServiceProviderPtr service_provider); |
38 | 40 |
39 // ServiceRegistry overrides. | 41 // ServiceRegistry overrides. |
40 void AddService(const std::string& service_name, | 42 void AddService(const std::string& service_name, |
41 const base::Callback<void(mojo::ScopedMessagePipeHandle)> | 43 const base::Callback<void(mojo::ScopedMessagePipeHandle)> |
42 service_factory) override; | 44 service_factory) override; |
43 void RemoveService(const std::string& service_name) override; | 45 void RemoveService(const std::string& service_name) override; |
44 void ConnectToRemoteService(const base::StringPiece& service_name, | 46 void ConnectToRemoteService(const base::StringPiece& service_name, |
45 mojo::ScopedMessagePipeHandle handle) override; | 47 mojo::ScopedMessagePipeHandle handle) override; |
46 | 48 |
| 49 bool IsBound() const; |
| 50 |
47 base::WeakPtr<ServiceRegistry> GetWeakPtr(); | 51 base::WeakPtr<ServiceRegistry> GetWeakPtr(); |
48 | 52 |
49 private: | 53 private: |
50 // mojo::ServiceProvider overrides. | 54 // mojo::ServiceProvider overrides. |
51 void ConnectToService(const mojo::String& name, | 55 void ConnectToService(const mojo::String& name, |
52 mojo::ScopedMessagePipeHandle client_handle) override; | 56 mojo::ScopedMessagePipeHandle client_handle) override; |
53 | 57 |
| 58 // mojo::ErrorHandler overrides. |
| 59 void OnConnectionError() override; |
| 60 |
54 mojo::Binding<mojo::ServiceProvider> binding_; | 61 mojo::Binding<mojo::ServiceProvider> binding_; |
55 mojo::ServiceProviderPtr remote_provider_; | 62 mojo::ServiceProviderPtr remote_provider_; |
56 | 63 |
57 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> > | 64 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> > |
58 service_factories_; | 65 service_factories_; |
59 std::queue<std::pair<std::string, mojo::MessagePipeHandle> > | 66 std::queue<std::pair<std::string, mojo::MessagePipeHandle> > |
60 pending_connects_; | 67 pending_connects_; |
61 | 68 |
62 base::WeakPtrFactory<ServiceRegistry> weak_factory_; | 69 base::WeakPtrFactory<ServiceRegistry> weak_factory_; |
63 }; | 70 }; |
64 | 71 |
65 } // namespace content | 72 } // namespace content |
66 | 73 |
67 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ | 74 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ |
OLD | NEW |