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 26 matching lines...) Expand all Loading... |
37 // ServiceProvider. | 37 // ServiceProvider. |
38 virtual void BindRemoteServiceProvider( | 38 virtual void BindRemoteServiceProvider( |
39 shell::mojom::InterfaceProviderPtr service_provider) = 0; | 39 shell::mojom::InterfaceProviderPtr service_provider) = 0; |
40 | 40 |
41 // Make the service created by |service_factory| available to the remote | 41 // Make the service created by |service_factory| available to the remote |
42 // ServiceProvider. In response to each request for a service, | 42 // ServiceProvider. In response to each request for a service, |
43 // |service_factory| will be run with an InterfaceRequest<Interface> | 43 // |service_factory| will be run with an InterfaceRequest<Interface> |
44 // representing that request. Adding a factory for an already registered | 44 // representing that request. Adding a factory for an already registered |
45 // service will override the factory. Existing connections to the service are | 45 // service will override the factory. Existing connections to the service are |
46 // unaffected. | 46 // unaffected. |
| 47 // |
| 48 // If a non-null |task_runner| is passed, the factory will be invoked on that |
| 49 // TaskRunner. |
47 template <typename Interface> | 50 template <typename Interface> |
48 void AddService(const base::Callback<void(mojo::InterfaceRequest<Interface>)>& | 51 void AddService(const base::Callback<void(mojo::InterfaceRequest<Interface>)>& |
49 service_factory) { | 52 service_factory, |
| 53 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 54 task_runner = nullptr) { |
50 AddService(Interface::Name_, | 55 AddService(Interface::Name_, |
51 base::Bind(&ServiceRegistry::ForwardToServiceFactory<Interface>, | 56 base::Bind(&ServiceRegistry::ForwardToServiceFactory<Interface>, |
52 service_factory)); | 57 service_factory), |
| 58 task_runner); |
53 } | 59 } |
54 virtual void AddService( | 60 virtual void AddService( |
55 const std::string& service_name, | 61 const std::string& service_name, |
56 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& | 62 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& |
57 service_factory) = 0; | 63 service_factory, |
| 64 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) = 0; |
58 | 65 |
59 // Remove future access to the service implementing Interface. Existing | 66 // Remove future access to the service implementing Interface. Existing |
60 // connections to the service are unaffected. | 67 // connections to the service are unaffected. |
61 template <typename Interface> | 68 template <typename Interface> |
62 void RemoveService() { | 69 void RemoveService() { |
63 RemoveService(Interface::Name_); | 70 RemoveService(Interface::Name_); |
64 } | 71 } |
65 virtual void RemoveService(const std::string& service_name) = 0; | 72 virtual void RemoveService(const std::string& service_name) = 0; |
66 | 73 |
67 // Connect to an interface provided by the remote service provider. | 74 // Connect to an interface provided by the remote service provider. |
(...skipping 22 matching lines...) Expand all Loading... |
90 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& | 97 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& |
91 service_factory, | 98 service_factory, |
92 mojo::ScopedMessagePipeHandle handle) { | 99 mojo::ScopedMessagePipeHandle handle) { |
93 service_factory.Run(mojo::MakeRequest<Interface>(std::move(handle))); | 100 service_factory.Run(mojo::MakeRequest<Interface>(std::move(handle))); |
94 } | 101 } |
95 }; | 102 }; |
96 | 103 |
97 } // namespace content | 104 } // namespace content |
98 | 105 |
99 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ | 106 #endif // CONTENT_PUBLIC_COMMON_SERVICE_REGISTRY_H_ |
OLD | NEW |