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 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 virtual void RemoveService(const std::string& service_name) = 0; | 53 virtual void RemoveService(const std::string& service_name) = 0; |
54 | 54 |
55 // Connect to an interface provided by the remote service provider. | 55 // Connect to an interface provided by the remote service provider. |
56 template <typename Interface> | 56 template <typename Interface> |
57 void ConnectToRemoteService(mojo::InterfaceRequest<Interface> ptr) { | 57 void ConnectToRemoteService(mojo::InterfaceRequest<Interface> ptr) { |
58 ConnectToRemoteService(Interface::Name_, ptr.PassMessagePipe()); | 58 ConnectToRemoteService(Interface::Name_, ptr.PassMessagePipe()); |
59 } | 59 } |
60 virtual void ConnectToRemoteService(const base::StringPiece& name, | 60 virtual void ConnectToRemoteService(const base::StringPiece& name, |
61 mojo::ScopedMessagePipeHandle handle) = 0; | 61 mojo::ScopedMessagePipeHandle handle) = 0; |
62 | 62 |
| 63 // Registers a local service factory to intercept ConnectToRemoteService |
| 64 // requests instead of actually connecting to the remote registry. Used only |
| 65 // for testing. |
| 66 virtual void AddServiceOverrideForTesting( |
| 67 const std::string& service_name, |
| 68 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& |
| 69 service_factory) = 0; |
| 70 |
| 71 // Removes all local service factories registered |
| 72 // by AddServiceOverrideForTesting. Used only for testing. |
| 73 virtual void ClearServiceOverridesForTesting() = 0; |
| 74 |
63 private: | 75 private: |
64 template <typename Interface> | 76 template <typename Interface> |
65 static void ForwardToServiceFactory( | 77 static void ForwardToServiceFactory( |
66 const base::Callback<void(mojo::InterfaceRequest<Interface>)> | 78 const base::Callback<void(mojo::InterfaceRequest<Interface>)> |
67 service_factory, | 79 service_factory, |
68 mojo::ScopedMessagePipeHandle handle) { | 80 mojo::ScopedMessagePipeHandle handle) { |
69 service_factory.Run(mojo::MakeRequest<Interface>(std::move(handle))); | 81 service_factory.Run(mojo::MakeRequest<Interface>(std::move(handle))); |
70 } | 82 } |
71 }; | 83 }; |
72 | 84 |
73 } // namespace content | 85 } // namespace content |
74 | 86 |
75 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 87 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
OLD | NEW |