OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_REGISTRY_H_ |
| 6 #define CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_REGISTRY_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/callback.h" |
| 12 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| 13 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 // An AssociatedInterfaceRegistry is a collection of associated interface- |
| 18 // binding callbacks mapped by interface name. |
| 19 // |
| 20 // This is used to register binding callbacks for interfaces which must be |
| 21 // associated with some IPC::ChannelProxy, meaning that messages on the |
| 22 // interface retain FIFO with respect to legacy Chrome IPC messages sent or |
| 23 // dispatched on the channel. |
| 24 // |
| 25 // The channel with which a registered interface is associated depends on the |
| 26 // configuration of the specific AssociatedInterfaceRegistry instance. For |
| 27 // example, RenderFrame exposes an instance of this class for which all |
| 28 // interfaces are associated with the IPC::SyncChannel to the browser. |
| 29 class AssociatedInterfaceRegistry { |
| 30 public: |
| 31 using Binder = base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>; |
| 32 |
| 33 virtual ~AssociatedInterfaceRegistry() {} |
| 34 |
| 35 // Adds an interface binder to the registry. |
| 36 virtual void AddInterface(const std::string& name, const Binder& binder) = 0; |
| 37 |
| 38 // Removes an interface binder from the registry. |
| 39 virtual void RemoveInterface(const std::string& name) = 0; |
| 40 |
| 41 template <typename Interface> |
| 42 using InterfaceBinder = |
| 43 base::Callback<void(mojo::AssociatedInterfaceRequest<Interface>)>; |
| 44 |
| 45 // Templated helper for AddInterface() above. |
| 46 template <typename Interface> |
| 47 void AddInterface(const InterfaceBinder<Interface>& binder) { |
| 48 AddInterface(Interface::Name_, |
| 49 base::Bind(&BindInterface<Interface>, binder)); |
| 50 } |
| 51 |
| 52 private: |
| 53 template <typename Interface> |
| 54 static void BindInterface(const InterfaceBinder<Interface>& binder, |
| 55 mojo::ScopedInterfaceEndpointHandle handle) { |
| 56 mojo::AssociatedInterfaceRequest<Interface> request; |
| 57 request.Bind(std::move(handle)); |
| 58 binder.Run(std::move(request)); |
| 59 } |
| 60 }; |
| 61 |
| 62 } // namespace content |
| 63 |
| 64 #endif // CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_REGISTRY_H_ |
OLD | NEW |