Commit bb73807c authored by Shimi Zhang's avatar Shimi Zhang Committed by Commit Bot

{Add,Get}Interface() for PendingAssociatedReceiver/AssociatedRemote

This comes from the discussion of crrev/c/1306240. We want to migrate
- AssociatedInterfaceRequest to PendingAssociatedReceiver.
- AssociatedInterfacePtr to AssociatedRemote

However AssociatedInterfaceRegistry and AssociatedInterfaceProvider
don't have such support yet.

Bug: 955171
Change-Id: I350dba2dac66b37cfc59f08daa06b000352b0c1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1685837Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Shimi Zhang <ctzsm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#675743}
parent 797c514c
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "content/public/common/previews_state.h" #include "content/public/common/previews_state.h"
#include "content/public/common/transferrable_url_loader.mojom.h" #include "content/public/common/transferrable_url_loader.mojom.h"
#include "media/mojo/interfaces/interface_factory.mojom.h" #include "media/mojo/interfaces/interface_factory.mojom.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/data_pipe.h"
...@@ -1952,7 +1953,7 @@ class CONTENT_EXPORT RenderFrameHostImpl ...@@ -1952,7 +1953,7 @@ class CONTENT_EXPORT RenderFrameHostImpl
mojo::AssociatedBinding<mojom::FrameHost> frame_host_associated_binding_; mojo::AssociatedBinding<mojom::FrameHost> frame_host_associated_binding_;
mojom::FramePtr frame_; mojom::FramePtr frame_;
mojom::FrameBindingsControlAssociatedPtr frame_bindings_control_; mojom::FrameBindingsControlAssociatedPtr frame_bindings_control_;
mojom::FrameNavigationControlAssociatedPtr navigation_control_; mojo::AssociatedRemote<mojom::FrameNavigationControl> navigation_control_;
// If this is true then this object was created in response to a renderer // If this is true then this object was created in response to a renderer
// initiated request. Init() will be called, and until then navigation // initiated request. Init() will be called, and until then navigation
......
...@@ -1841,7 +1841,7 @@ RenderFrameImpl::RenderFrameImpl(CreateParams params) ...@@ -1841,7 +1841,7 @@ RenderFrameImpl::RenderFrameImpl(CreateParams params)
frame_binding_(this), frame_binding_(this),
host_zoom_binding_(this), host_zoom_binding_(this),
frame_bindings_control_binding_(this), frame_bindings_control_binding_(this),
frame_navigation_control_binding_(this), frame_navigation_control_receiver_(this),
fullscreen_binding_(this), fullscreen_binding_(this),
mhtml_file_writer_binding_(this), mhtml_file_writer_binding_(this),
navigation_client_impl_(nullptr), navigation_client_impl_(nullptr),
...@@ -2347,9 +2347,9 @@ void RenderFrameImpl::BindFrameBindingsControl( ...@@ -2347,9 +2347,9 @@ void RenderFrameImpl::BindFrameBindingsControl(
} }
void RenderFrameImpl::BindFrameNavigationControl( void RenderFrameImpl::BindFrameNavigationControl(
mojom::FrameNavigationControlAssociatedRequest request) { mojo::PendingAssociatedReceiver<mojom::FrameNavigationControl> receiver) {
frame_navigation_control_binding_.Bind( frame_navigation_control_receiver_.Bind(
std::move(request), GetTaskRunner(blink::TaskType::kInternalIPC)); std::move(receiver), GetTaskRunner(blink::TaskType::kInternalIPC));
} }
void RenderFrameImpl::BindNavigationClient( void RenderFrameImpl::BindNavigationClient(
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
#include "ipc/ipc_platform_file.h" #include "ipc/ipc_platform_file.h"
#include "media/base/routing_token_callback.h" #include "media/base/routing_token_callback.h"
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/data_pipe.h"
...@@ -904,7 +905,7 @@ class CONTENT_EXPORT RenderFrameImpl ...@@ -904,7 +905,7 @@ class CONTENT_EXPORT RenderFrameImpl
void BindFrameBindingsControl( void BindFrameBindingsControl(
mojom::FrameBindingsControlAssociatedRequest request); mojom::FrameBindingsControlAssociatedRequest request);
void BindFrameNavigationControl( void BindFrameNavigationControl(
mojom::FrameNavigationControlAssociatedRequest request); mojo::PendingAssociatedReceiver<mojom::FrameNavigationControl> receiver);
// Only used when PerNavigationMojoInterface is enabled. // Only used when PerNavigationMojoInterface is enabled.
void BindNavigationClient(mojom::NavigationClientAssociatedRequest request); void BindNavigationClient(mojom::NavigationClientAssociatedRequest request);
...@@ -1669,8 +1670,8 @@ class CONTENT_EXPORT RenderFrameImpl ...@@ -1669,8 +1670,8 @@ class CONTENT_EXPORT RenderFrameImpl
mojo::AssociatedBinding<mojom::HostZoom> host_zoom_binding_; mojo::AssociatedBinding<mojom::HostZoom> host_zoom_binding_;
mojo::AssociatedBinding<mojom::FrameBindingsControl> mojo::AssociatedBinding<mojom::FrameBindingsControl>
frame_bindings_control_binding_; frame_bindings_control_binding_;
mojo::AssociatedBinding<mojom::FrameNavigationControl> mojo::AssociatedReceiver<mojom::FrameNavigationControl>
frame_navigation_control_binding_; frame_navigation_control_receiver_;
mojo::AssociatedBinding<mojom::FullscreenVideoElementHandler> mojo::AssociatedBinding<mojom::FullscreenVideoElementHandler>
fullscreen_binding_; fullscreen_binding_;
mojo::AssociatedBinding<mojom::MhtmlFileWriter> mhtml_file_writer_binding_; mojo::AssociatedBinding<mojom::MhtmlFileWriter> mhtml_file_writer_binding_;
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "mojo/public/cpp/bindings/associated_interface_ptr.h" #include "mojo/public/cpp/bindings/associated_interface_ptr.h"
#include "mojo/public/cpp/bindings/associated_interface_request.h" #include "mojo/public/cpp/bindings/associated_interface_request.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
#include "third_party/blink/public/common/common_export.h" #include "third_party/blink/public/common/common_export.h"
#include "third_party/blink/public/mojom/associated_interfaces/associated_interfaces.mojom.h" #include "third_party/blink/public/mojom/associated_interfaces/associated_interfaces.mojom.h"
...@@ -58,17 +60,31 @@ class BLINK_COMMON_EXPORT AssociatedInterfaceProvider { ...@@ -58,17 +60,31 @@ class BLINK_COMMON_EXPORT AssociatedInterfaceProvider {
void GetInterface(const std::string& name, void GetInterface(const std::string& name,
mojo::ScopedInterfaceEndpointHandle handle); mojo::ScopedInterfaceEndpointHandle handle);
// Remove this after done with migration from AssociatedInterfaceRequest to
// PendingAssociatedReceiver.
// Templated helpers for GetInterface(). // Templated helpers for GetInterface().
template <typename Interface> template <typename Interface>
void GetInterface(mojo::AssociatedInterfaceRequest<Interface> request) { void GetInterface(mojo::AssociatedInterfaceRequest<Interface> request) {
GetInterface(Interface::Name_, request.PassHandle()); GetInterface(Interface::Name_, request.PassHandle());
} }
// Remove this after done with migration from AssociatedInterfacePtr to
// AssociatedRemote.
template <typename Interface> template <typename Interface>
void GetInterface(mojo::AssociatedInterfacePtr<Interface>* proxy) { void GetInterface(mojo::AssociatedInterfacePtr<Interface>* proxy) {
GetInterface(mojo::MakeRequest(proxy, task_runner_)); GetInterface(mojo::MakeRequest(proxy, task_runner_));
} }
template <typename Interface>
void GetInterface(mojo::PendingAssociatedReceiver<Interface> receiver) {
GetInterface(Interface::Name_, receiver.PassHandle());
}
template <typename Interface>
void GetInterface(mojo::AssociatedRemote<Interface>* remote) {
GetInterface(remote->BindNewEndpointAndPassReceiver());
}
void OverrideBinderForTesting( void OverrideBinderForTesting(
const std::string& name, const std::string& name,
const base::RepeatingCallback<void(mojo::ScopedInterfaceEndpointHandle)>& const base::RepeatingCallback<void(mojo::ScopedInterfaceEndpointHandle)>&
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/associated_interface_request.h" #include "mojo/public/cpp/bindings/associated_interface_request.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
#include "third_party/blink/public/common/common_export.h" #include "third_party/blink/public/common/common_export.h"
...@@ -51,10 +52,14 @@ class BLINK_COMMON_EXPORT AssociatedInterfaceRegistry { ...@@ -51,10 +52,14 @@ class BLINK_COMMON_EXPORT AssociatedInterfaceRegistry {
bool TryBindInterface(const std::string& name, bool TryBindInterface(const std::string& name,
mojo::ScopedInterfaceEndpointHandle* handle); mojo::ScopedInterfaceEndpointHandle* handle);
// Remove this after done with migration from AssociatedInterfaceRequest to
// PendingAssociatedReceiver.
template <typename Interface> template <typename Interface>
using InterfaceBinder = base::RepeatingCallback<void( using InterfaceBinder = base::RepeatingCallback<void(
mojo::AssociatedInterfaceRequest<Interface>)>; mojo::AssociatedInterfaceRequest<Interface>)>;
// Remove this after done with migration from AssociatedInterfaceRequest to
// PendingAssociatedReceiver.
// Templated helper for AddInterface() above. // Templated helper for AddInterface() above.
template <typename Interface> template <typename Interface>
void AddInterface(const InterfaceBinder<Interface>& binder) { void AddInterface(const InterfaceBinder<Interface>& binder) {
...@@ -62,15 +67,35 @@ class BLINK_COMMON_EXPORT AssociatedInterfaceRegistry { ...@@ -62,15 +67,35 @@ class BLINK_COMMON_EXPORT AssociatedInterfaceRegistry {
base::BindRepeating(&BindInterface<Interface>, binder)); base::BindRepeating(&BindInterface<Interface>, binder));
} }
template <typename Interface>
using ReceiverBinder =
base::RepeatingCallback<void(mojo::PendingAssociatedReceiver<Interface>)>;
template <typename Interface>
void AddInterface(const ReceiverBinder<Interface>& binder) {
AddInterface(
Interface::Name_,
base::BindRepeating(&BindInterfaceReceiver<Interface>, binder));
}
base::WeakPtr<AssociatedInterfaceRegistry> GetWeakPtr(); base::WeakPtr<AssociatedInterfaceRegistry> GetWeakPtr();
private: private:
// Remove this after done with migration from AssociatedInterfaceRequest to
// PendingAssociatedReceiver.
template <typename Interface> template <typename Interface>
static void BindInterface(const InterfaceBinder<Interface>& binder, static void BindInterface(const InterfaceBinder<Interface>& binder,
mojo::ScopedInterfaceEndpointHandle handle) { mojo::ScopedInterfaceEndpointHandle handle) {
binder.Run(mojo::AssociatedInterfaceRequest<Interface>(std::move(handle))); binder.Run(mojo::AssociatedInterfaceRequest<Interface>(std::move(handle)));
} }
template <typename Interface>
static void BindInterfaceReceiver(
const ReceiverBinder<Interface>& binder,
mojo::ScopedInterfaceEndpointHandle handle) {
binder.Run(mojo::PendingAssociatedReceiver<Interface>(std::move(handle)));
}
std::map<std::string, Binder> interfaces_; std::map<std::string, Binder> interfaces_;
base::WeakPtrFactory<AssociatedInterfaceRegistry> weak_ptr_factory_{this}; base::WeakPtrFactory<AssociatedInterfaceRegistry> weak_ptr_factory_{this};
......
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