| 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/interface_impl.h" | 17 #include "mojo/public/cpp/bindings/interface_impl.h" |
| 18 #include "mojo/public/cpp/system/core.h" | 18 #include "mojo/public/cpp/system/core.h" |
| 19 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 19 #include "mojo/public/interfaces/application/service_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::InterfaceImpl<mojo::ServiceProvider>) { | 25 public NON_EXPORTED_BASE(mojo::InterfaceImpl<mojo::ServiceProvider>) { |
| 26 public: | 26 public: |
| 27 ServiceRegistryImpl(); | 27 ServiceRegistryImpl(); |
| 28 explicit ServiceRegistryImpl(mojo::ScopedMessagePipeHandle handle); | 28 explicit ServiceRegistryImpl(mojo::ScopedMessagePipeHandle handle); |
| 29 virtual ~ServiceRegistryImpl(); | 29 ~ServiceRegistryImpl() override; |
| 30 | 30 |
| 31 // Binds to a remote ServiceProvider. This will expose added services to the | 31 // Binds to a remote ServiceProvider. This will expose added services to the |
| 32 // remote ServiceProvider with the corresponding handle and enable | 32 // remote ServiceProvider with the corresponding handle and enable |
| 33 // ConnectToRemoteService to provide access to services exposed by the remote | 33 // ConnectToRemoteService to provide access to services exposed by the remote |
| 34 // ServiceProvider. | 34 // ServiceProvider. |
| 35 void BindRemoteServiceProvider(mojo::ScopedMessagePipeHandle handle); | 35 void BindRemoteServiceProvider(mojo::ScopedMessagePipeHandle handle); |
| 36 | 36 |
| 37 // ServiceRegistry overrides. | 37 // ServiceRegistry overrides. |
| 38 virtual void AddService( | 38 void AddService(const std::string& service_name, |
| 39 const std::string& service_name, | 39 const base::Callback<void(mojo::ScopedMessagePipeHandle)> |
| 40 const base::Callback<void(mojo::ScopedMessagePipeHandle)> service_factory) | 40 service_factory) override; |
| 41 override; | 41 void RemoveService(const std::string& service_name) override; |
| 42 virtual void RemoveService(const std::string& service_name) override; | 42 void ConnectToRemoteService(const base::StringPiece& service_name, |
| 43 virtual void ConnectToRemoteService( | 43 mojo::ScopedMessagePipeHandle handle) override; |
| 44 const base::StringPiece& service_name, | |
| 45 mojo::ScopedMessagePipeHandle handle) override; | |
| 46 | 44 |
| 47 base::WeakPtr<ServiceRegistry> GetWeakPtr(); | 45 base::WeakPtr<ServiceRegistry> GetWeakPtr(); |
| 48 | 46 |
| 49 private: | 47 private: |
| 50 // mojo::InterfaceImpl<mojo::ServiceProvider> overrides. | 48 // mojo::InterfaceImpl<mojo::ServiceProvider> overrides. |
| 51 virtual void ConnectToService( | 49 void ConnectToService(const mojo::String& name, |
| 52 const mojo::String& name, | 50 mojo::ScopedMessagePipeHandle client_handle) override; |
| 53 mojo::ScopedMessagePipeHandle client_handle) override; | 51 void OnConnectionError() override; |
| 54 virtual void OnConnectionError() override; | |
| 55 | 52 |
| 56 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> > | 53 std::map<std::string, base::Callback<void(mojo::ScopedMessagePipeHandle)> > |
| 57 service_factories_; | 54 service_factories_; |
| 58 std::queue<std::pair<std::string, mojo::MessagePipeHandle> > | 55 std::queue<std::pair<std::string, mojo::MessagePipeHandle> > |
| 59 pending_connects_; | 56 pending_connects_; |
| 60 bool bound_; | 57 bool bound_; |
| 61 | 58 |
| 62 base::WeakPtrFactory<ServiceRegistry> weak_factory_; | 59 base::WeakPtrFactory<ServiceRegistry> weak_factory_; |
| 63 }; | 60 }; |
| 64 | 61 |
| 65 } // namespace content | 62 } // namespace content |
| 66 | 63 |
| 67 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ | 64 #endif // CONTENT_COMMON_MOJO_SERVICE_REGISTRY_IMPL_H_ |
| OLD | NEW |