Chromium Code Reviews| 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_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 5 #ifndef CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
| 6 #define CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 6 #define CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "base/supports_user_data.h" | |
| 14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 15 #include "mojo/public/cpp/bindings/interface_ptr.h" | 16 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 16 #include "mojo/public/cpp/bindings/interface_request.h" | 17 #include "mojo/public/cpp/bindings/interface_request.h" |
| 17 #include "mojo/public/cpp/system/core.h" | 18 #include "mojo/public/cpp/system/core.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 // A ServiceRegistry exposes local services that have been added using | 22 // A ServiceRegistry exposes local services that have been added using |
| 22 // AddService to a paired remote ServiceRegistry and provides local access to | 23 // AddService to a paired remote ServiceRegistry and provides local access to |
| 23 // services exposed by the remote ServiceRegistry through | 24 // services exposed by the remote ServiceRegistry through |
| 24 // ConnectToRemoteService. | 25 // ConnectToRemoteService. |
| 25 class CONTENT_EXPORT ServiceRegistry { | 26 class CONTENT_EXPORT ServiceRegistry : private base::SupportsUserData { |
|
ncarter (slow)
2016/04/05 18:22:40
For SupportsUserData, instead of private inheritan
| |
| 26 public: | 27 public: |
| 27 virtual ~ServiceRegistry() {} | 28 ~ServiceRegistry() override {} |
| 28 | 29 |
| 29 // Make the service created by |service_factory| available to the remote | 30 // Make the service created by |service_factory| available to the remote |
| 30 // ServiceProvider. In response to each request for a service, | 31 // ServiceProvider. In response to each request for a service, |
| 31 // |service_factory| will be run with an InterfaceRequest<Interface> | 32 // |service_factory| will be run with an InterfaceRequest<Interface> |
| 32 // representing that request. Adding a factory for an already registered | 33 // representing that request. Adding a factory for an already registered |
| 33 // service will override the factory. Existing connections to the service are | 34 // service will override the factory. Existing connections to the service are |
| 34 // unaffected. | 35 // unaffected. |
| 35 template <typename Interface> | 36 template <typename Interface> |
| 36 void AddService(const base::Callback<void(mojo::InterfaceRequest<Interface>)> | 37 void AddService(const base::Callback<void(mojo::InterfaceRequest<Interface>)> |
| 37 service_factory) { | 38 service_factory) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 66 virtual void AddServiceOverrideForTesting( | 67 virtual void AddServiceOverrideForTesting( |
| 67 const std::string& service_name, | 68 const std::string& service_name, |
| 68 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& | 69 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& |
| 69 service_factory) = 0; | 70 service_factory) = 0; |
| 70 | 71 |
| 71 // Removes all local service factories registered | 72 // Removes all local service factories registered |
| 72 // by AddServiceOverrideForTesting. Used only for testing. | 73 // by AddServiceOverrideForTesting. Used only for testing. |
| 73 virtual void ClearServiceOverridesForTesting() = 0; | 74 virtual void ClearServiceOverridesForTesting() = 0; |
| 74 | 75 |
| 75 private: | 76 private: |
| 77 friend class ServiceRegistryAndroid; | |
| 78 | |
| 76 template <typename Interface> | 79 template <typename Interface> |
| 77 static void ForwardToServiceFactory( | 80 static void ForwardToServiceFactory( |
| 78 const base::Callback<void(mojo::InterfaceRequest<Interface>)> | 81 const base::Callback<void(mojo::InterfaceRequest<Interface>)> |
| 79 service_factory, | 82 service_factory, |
| 80 mojo::ScopedMessagePipeHandle handle) { | 83 mojo::ScopedMessagePipeHandle handle) { |
| 81 service_factory.Run(mojo::MakeRequest<Interface>(std::move(handle))); | 84 service_factory.Run(mojo::MakeRequest<Interface>(std::move(handle))); |
| 82 } | 85 } |
| 83 }; | 86 }; |
| 84 | 87 |
| 85 } // namespace content | 88 } // namespace content |
| 86 | 89 |
| 87 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 90 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
| OLD | NEW |