Commit b0c5e585 authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Add methods to blink::InterfaceRegistry for Pending{Associated}Receiver<T>

Similarly to what has been done already for blink::InterfaceProvider[1] and
service_manager::InterfaceProvider[2], in order to help with the transition
to the new Mojo types, let's add three more templated methods to the class
blink::InterfaceRegistry that enable calling the AddInterface() and the
AddAssociatedInterface methods passing a Pending{Associated}Receiver<T> as
parameter.

This will be useful in cases relying on the InterfaceRegistry's API to add
interface factories using the new Mojo types, as it's the case for instance
for the FindInPage class (see [3]).

[1]https://cs.chromium.org/chromium/src/third_party/blink/public/platform/interface_provider.h?l=28
[2]https://cs.chromium.org/chromium/src/services/service_manager/public/cpp/interface_provider.h?l=98
[3]https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/frame/find_in_page.cc?l=55

Bug: 980151
Change-Id: I994d0d28c884f5500ac4f82a5592f16c824f8bff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1697486
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#677118}
parent e049fdf5
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_INTERFACE_REGISTRY_H_ #ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_INTERFACE_REGISTRY_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_INTERFACE_REGISTRY_H_ #define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_INTERFACE_REGISTRY_H_
#include <utility>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
...@@ -14,6 +16,8 @@ ...@@ -14,6 +16,8 @@
#if INSIDE_BLINK #if INSIDE_BLINK
#include "mojo/public/cpp/bindings/associated_interface_request.h" #include "mojo/public/cpp/bindings/associated_interface_request.h"
#include "mojo/public/cpp/bindings/interface_request.h" #include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h" // nogncheck #include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h" // nogncheck
#include "third_party/blink/renderer/platform/wtf/functional.h" // nogncheck #include "third_party/blink/renderer/platform/wtf/functional.h" // nogncheck
#endif #endif
...@@ -47,22 +51,45 @@ class BLINK_PLATFORM_EXPORT InterfaceRegistry { ...@@ -47,22 +51,45 @@ class BLINK_PLATFORM_EXPORT InterfaceRegistry {
void AddInterface( void AddInterface(
base::RepeatingCallback<void(mojo::InterfaceRequest<Interface>)> base::RepeatingCallback<void(mojo::InterfaceRequest<Interface>)>
factory) { factory) {
AddInterface(Interface::Name_, AddInterface(
WTF::BindRepeating( Interface::Name_,
&InterfaceRegistry::ForwardToInterfaceFactory<Interface>, WTF::BindRepeating(&InterfaceRegistry::ForwardToInterfaceFactory<
std::move(factory))); mojo::InterfaceRequest<Interface>>,
std::move(factory)));
}
template <typename Interface>
void AddInterface(
base::RepeatingCallback<void(mojo::PendingReceiver<Interface>)> factory) {
AddInterface(
Interface::Name_,
WTF::BindRepeating(&InterfaceRegistry::ForwardToInterfaceFactory<
mojo::PendingReceiver<Interface>>,
std::move(factory)));
} }
template <typename Interface> template <typename Interface>
void AddInterface(WTF::CrossThreadRepeatingFunction< void AddInterface(WTF::CrossThreadRepeatingFunction<
void(mojo::InterfaceRequest<Interface>)> factory, void(mojo::InterfaceRequest<Interface>)> factory,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
AddInterface( AddInterface(Interface::Name_,
Interface::Name_, ConvertToBaseCallback(CrossThreadBind(
ConvertToBaseCallback(CrossThreadBind( &InterfaceRegistry::ForwardToCrossThreadInterfaceFactory<
&InterfaceRegistry::ForwardToCrossThreadInterfaceFactory<Interface>, mojo::InterfaceRequest<Interface>>,
std::move(factory))), std::move(factory))),
std::move(task_runner)); std::move(task_runner));
}
template <typename Interface>
void AddInterface(WTF::CrossThreadRepeatingFunction<
void(mojo::PendingReceiver<Interface>)> factory,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
AddInterface(Interface::Name_,
ConvertToBaseCallback(CrossThreadBind(
&InterfaceRegistry::ForwardToCrossThreadInterfaceFactory<
mojo::PendingReceiver<Interface>>,
std::move(factory))),
std::move(task_runner));
} }
template <typename Interface> template <typename Interface>
...@@ -72,36 +99,48 @@ class BLINK_PLATFORM_EXPORT InterfaceRegistry { ...@@ -72,36 +99,48 @@ class BLINK_PLATFORM_EXPORT InterfaceRegistry {
AddAssociatedInterface( AddAssociatedInterface(
Interface::Name_, Interface::Name_,
WTF::BindRepeating( WTF::BindRepeating(
&InterfaceRegistry::ForwardToAssociatedInterfaceFactory<Interface>, &InterfaceRegistry::ForwardToAssociatedInterfaceFactory<
mojo::AssociatedInterfaceRequest<Interface>>,
std::move(factory))); std::move(factory)));
} }
private:
template <typename Interface> template <typename Interface>
void AddAssociatedInterface(
base::RepeatingCallback<void(mojo::PendingAssociatedReceiver<Interface>)>
factory) {
AddAssociatedInterface(
Interface::Name_,
WTF::BindRepeating(
&InterfaceRegistry::ForwardToAssociatedInterfaceFactory<
mojo::PendingAssociatedReceiver<Interface>>,
std::move(factory)));
}
private:
template <typename MojoType>
static void ForwardToInterfaceFactory( static void ForwardToInterfaceFactory(
base::RepeatingCallback<void(mojo::InterfaceRequest<Interface>)> factory, base::RepeatingCallback<void(MojoType)> factory,
mojo::ScopedMessagePipeHandle handle) { mojo::ScopedMessagePipeHandle handle) {
factory.Run(mojo::InterfaceRequest<Interface>(std::move(handle))); factory.Run(MojoType(std::move(handle)));
} }
template <typename Interface> template <typename MojoType>
static void ForwardToCrossThreadInterfaceFactory( static void ForwardToCrossThreadInterfaceFactory(
const WTF::CrossThreadRepeatingFunction< const WTF::CrossThreadRepeatingFunction<void(MojoType)>& factory,
void(mojo::InterfaceRequest<Interface>)>& factory,
mojo::ScopedMessagePipeHandle handle) { mojo::ScopedMessagePipeHandle handle) {
factory.Run(mojo::InterfaceRequest<Interface>(std::move(handle))); factory.Run(MojoType(std::move(handle)));
} }
template <typename Interface> template <typename MojoType>
static void ForwardToAssociatedInterfaceFactory( static void ForwardToAssociatedInterfaceFactory(
base::RepeatingCallback<void(mojo::AssociatedInterfaceRequest<Interface>)> base::RepeatingCallback<void(MojoType)> factory,
factory,
mojo::ScopedInterfaceEndpointHandle handle) { mojo::ScopedInterfaceEndpointHandle handle) {
factory.Run(mojo::AssociatedInterfaceRequest<Interface>(std::move(handle))); factory.Run(MojoType(std::move(handle)));
} }
#endif // INSIDE_BLINK #endif // INSIDE_BLINK
}; };
} // namespace blink } // namespace blink
#endif #endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_INTERFACE_REGISTRY_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment