OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_ASSOCIATED_INTERFACE_PROVIDER_H_ | 5 #ifndef CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_PROVIDER_H_ |
6 #define CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_PROVIDER_H_ | 6 #define CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_PROVIDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" | 10 #include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
11 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 11 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
12 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 12 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
13 | 13 |
14 namespace mojo { | |
15 class AssociatedGroup; | |
16 } | |
17 | |
18 namespace content { | 14 namespace content { |
19 | 15 |
20 // A helper interface for connecting to remote Channel-associated interfaces. | 16 // A helper interface for connecting to remote Channel-associated interfaces. |
21 // | 17 // |
22 // This is analogous to service_manager::InterfaceProvider in that it provides a | 18 // This is analogous to service_manager::InterfaceProvider in that it provides a |
23 // means of | 19 // means of |
24 // binding proxies to remote interfaces, but this is specifically for interfaces | 20 // binding proxies to remote interfaces, but this is specifically for interfaces |
25 // which must be assocaited with an IPC::Channel, i.e. retain FIFO message | 21 // which must be assocaited with an IPC::Channel, i.e. retain FIFO message |
26 // ordering with respect to legacy IPC messages. | 22 // ordering with respect to legacy IPC messages. |
27 // | 23 // |
28 // The Channel with which the remote interfaces are associated depends on | 24 // The Channel with which the remote interfaces are associated depends on |
29 // the configuration of the specific AssociatedInterfaceProvider instance. For | 25 // the configuration of the specific AssociatedInterfaceProvider instance. For |
30 // example, RenderFrameHost exposes an instance of this class for which all | 26 // example, RenderFrameHost exposes an instance of this class for which all |
31 // interfaces are associted with the IPC::ChannelProxy to the render process | 27 // interfaces are associted with the IPC::ChannelProxy to the render process |
32 // which hosts its corresponding RenderFrame. | 28 // which hosts its corresponding RenderFrame. |
33 class AssociatedInterfaceProvider { | 29 class AssociatedInterfaceProvider { |
34 public: | 30 public: |
35 virtual ~AssociatedInterfaceProvider() {} | 31 virtual ~AssociatedInterfaceProvider() {} |
36 | 32 |
37 // Passes an associated endpoint handle to the remote end to be bound to a | 33 // Passes an associated endpoint handle to the remote end to be bound to a |
38 // Channel-associated interface named |name|. | 34 // Channel-associated interface named |name|. |
39 virtual void GetInterface(const std::string& name, | 35 virtual void GetInterface(const std::string& name, |
40 mojo::ScopedInterfaceEndpointHandle handle) = 0; | 36 mojo::ScopedInterfaceEndpointHandle handle) = 0; |
41 | 37 |
42 // Returns an AssociatedGroup for the provider. This may be used to create | |
43 // new associated endpoints for use with Channel-associated interfaces. | |
44 virtual mojo::AssociatedGroup* GetAssociatedGroup() = 0; | |
45 | |
46 // Templated helper for GetInterface(). | 38 // Templated helper for GetInterface(). |
47 template <typename Interface> | 39 template <typename Interface> |
48 void GetInterface(mojo::AssociatedInterfacePtr<Interface>* proxy) { | 40 void GetInterface(mojo::AssociatedInterfacePtr<Interface>* proxy) { |
49 mojo::AssociatedInterfaceRequest<Interface> request = | 41 auto request = mojo::MakeRequest(proxy); |
50 mojo::MakeRequest(proxy, GetAssociatedGroup()); | |
51 GetInterface(Interface::Name_, request.PassHandle()); | 42 GetInterface(Interface::Name_, request.PassHandle()); |
52 } | 43 } |
53 | 44 |
54 virtual void OverrideBinderForTesting( | 45 virtual void OverrideBinderForTesting( |
55 const std::string& name, | 46 const std::string& name, |
56 const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& | 47 const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& |
57 binder) = 0; | 48 binder) = 0; |
58 }; | 49 }; |
59 | 50 |
60 } // namespace content | 51 } // namespace content |
61 | 52 |
62 #endif // CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_PROVIDER_H_ | 53 #endif // CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_PROVIDER_H_ |
OLD | NEW |