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