Commit 335304f3 authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Support PendingReceiver in RenderProcessHostImpl::AddUIThreadInterface()

Add a new override for InterfaceGetter<> to handle a PendingReceiver<T>
and compatible callback, so that we don't need to implement wrappers
all around when migrating to the new Mojo types.

Additionally, clean up all the instances where such wrappers have been
used so far, now that we can use the PendingReceiver<T>-based methods.

TBR=mvanouwerkerk@chromium.org

Bug: 955171
Change-Id: I028faefc9c50b7d422d4713cdd7c8f87ccded220
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1769449
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarMugdha Lakhani <nator@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#691050}
parent c9624af0
......@@ -86,20 +86,6 @@ void BackgroundSyncContextImpl::Shutdown() {
base::BindOnce(&BackgroundSyncContextImpl::ShutdownOnCoreThread, this));
}
void BackgroundSyncContextImpl::CreateOneShotSyncServiceForRequest(
blink::mojom::OneShotBackgroundSyncServiceRequest request) {
// Implicit conversion from OneShotBackgroundSyncServiceRequest to
// mojo::PendingReceiver<blink::mojom::OneShotBackgroundSyncService>.
CreateOneShotSyncService(std::move(request));
}
void BackgroundSyncContextImpl::CreatePeriodicSyncServiceForRequest(
blink::mojom::PeriodicBackgroundSyncServiceRequest request) {
// Implicit conversion from PeriodicBackgroundSyncServiceRequest to
// mojo::PendingReceiver<blink::mojom::PeriodicBackgroundSyncService>.
CreatePeriodicSyncService(std::move(request));
}
void BackgroundSyncContextImpl::CreateOneShotSyncService(
mojo::PendingReceiver<blink::mojom::OneShotBackgroundSyncService>
receiver) {
......
......@@ -51,14 +51,6 @@ class CONTENT_EXPORT BackgroundSyncContextImpl
// Shutdown must be called before deleting this. Call on the UI thread.
void Shutdown();
// TODO(https://crbug.com/955171): Remove these methods and use
// CreateOneShotSyncService and CreatePeriodicSyncService directly once
// RenderProcessHostImpl uses service_manager::BinderMap.
void CreateOneShotSyncServiceForRequest(
blink::mojom::OneShotBackgroundSyncServiceRequest request);
void CreatePeriodicSyncServiceForRequest(
blink::mojom::PeriodicBackgroundSyncServiceRequest request);
// Create a OneShotBackgroundSyncServiceImpl that is owned by this. Call on
// the UI thread.
void CreateOneShotSyncService(
......
......@@ -286,12 +286,6 @@ void PushMessagingManager::AddPushMessagingReceiver(
receivers_.Add(this, std::move(receiver));
}
void PushMessagingManager::BindRequest(
blink::mojom::PushMessagingRequest request) {
// Implicit conversion to mojo::PendingReceiver<blink::mojom::PushMessaging>.
AddPushMessagingReceiver(std::move(request));
}
// Subscribe methods on both IO and UI threads, merged in order of use from
// PushMessagingManager and Core.
// -----------------------------------------------------------------------------
......
......@@ -44,10 +44,6 @@ class PushMessagingManager : public blink::mojom::PushMessaging {
void AddPushMessagingReceiver(
mojo::PendingReceiver<blink::mojom::PushMessaging> receiver);
// Temporary method while RenderProcessHostImpl does not migrate from using
// service_manager::BinderRegistry to using service_manager::BinderMap.
void BindRequest(blink::mojom::PushMessagingRequest request);
base::WeakPtr<PushMessagingManager> AsWeakPtr() {
return weak_factory_.GetWeakPtr();
}
......
......@@ -31,13 +31,6 @@ ClipboardHostImpl::ClipboardHostImpl(
clipboard_writer_(
new ui::ScopedClipboardWriter(ui::ClipboardBuffer::kCopyPaste)) {}
void ClipboardHostImpl::CreateForRequest(
blink::mojom::ClipboardHostRequest request) {
// Implicit conversion from ClipboardHostRequest to
// mojo::PendingReceiver<blink::mojom::ClipboardHost>.
Create(std::move(request));
}
void ClipboardHostImpl::Create(
mojo::PendingReceiver<blink::mojom::ClipboardHost> receiver) {
// Clipboard implementations do interesting things, like run nested message
......
......@@ -29,11 +29,6 @@ class CONTENT_EXPORT ClipboardHostImpl : public blink::mojom::ClipboardHost {
public:
~ClipboardHostImpl() override;
// TODO(https://crbug.com/955171): Remove this and use Create directly once
// RenderProcessHostImpl uses service_manager::BinderMap instead of
// service_manager::BinderRegistry.
static void CreateForRequest(blink::mojom::ClipboardHostRequest request);
static void Create(
mojo::PendingReceiver<blink::mojom::ClipboardHost> receiver);
......
......@@ -1967,11 +1967,7 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
AddUIThreadInterface(
registry.get(),
base::BindRepeating(
[](RenderProcessHostImpl* impl,
blink::mojom::EmbeddedFrameSinkProviderRequest request) {
// An implicit conversion to PendinReceiver<T> will be used below.
impl->CreateEmbeddedFrameSinkProvider(std::move(request));
},
&RenderProcessHostImpl::CreateEmbeddedFrameSinkProvider,
base::Unretained(this)));
AddUIThreadInterface(
......@@ -1987,33 +1983,27 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
AddUIThreadInterface(
registry.get(),
base::BindRepeating(
&BackgroundSyncContextImpl::CreateOneShotSyncServiceForRequest,
&BackgroundSyncContextImpl::CreateOneShotSyncService,
base::Unretained(
storage_partition_impl_->GetBackgroundSyncContext())));
AddUIThreadInterface(
registry.get(),
base::BindRepeating(
&BackgroundSyncContextImpl::CreatePeriodicSyncServiceForRequest,
&BackgroundSyncContextImpl::CreatePeriodicSyncService,
base::Unretained(
storage_partition_impl_->GetBackgroundSyncContext())));
AddUIThreadInterface(
registry.get(),
base::BindRepeating(
[](RenderProcessHostImpl* impl,
blink::mojom::StoragePartitionServiceRequest request) {
// An implicit conversion to PendinReceiver<T> will be used below.
impl->CreateStoragePartitionService(std::move(request));
},
base::Unretained(this)));
base::BindRepeating(&RenderProcessHostImpl::CreateStoragePartitionService,
base::Unretained(this)));
AddUIThreadInterface(
registry.get(),
base::BindRepeating(
&RenderProcessHostImpl::CreateBroadcastChannelProvider,
base::Unretained(this)));
AddUIThreadInterface(
registry.get(),
base::BindRepeating(&ClipboardHostImpl::CreateForRequest));
AddUIThreadInterface(registry.get(),
base::BindRepeating(&ClipboardHostImpl::Create));
AddUIThreadInterface(
registry.get(),
......@@ -2054,7 +2044,7 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
if (ServiceWorkerContext::IsServiceWorkerOnUIEnabled()) {
AddUIThreadInterface(
registry.get(),
base::BindRepeating(&PushMessagingManager::BindRequest,
base::BindRepeating(&PushMessagingManager::AddPushMessagingReceiver,
base::Unretained(push_messaging_manager_.get())));
} else {
registry->AddInterface(
......@@ -2254,17 +2244,14 @@ void RenderProcessHostImpl::CreateStoragePartitionService(
}
void RenderProcessHostImpl::CreateBroadcastChannelProvider(
blink::mojom::BroadcastChannelProviderRequest request) {
// |request| is converted into
// mojo::PendingReceiver<blink::mojom::BroadcastChannelProvider> while
// RenderProcessHostImpl uses service_manager::BinderRegistry.
mojo::PendingReceiver<blink::mojom::BroadcastChannelProvider> receiver) {
if (!GetBroadcastChannelProviderReceiverHandler().is_null()) {
GetBroadcastChannelProviderReceiverHandler().Run(this, std::move(request));
GetBroadcastChannelProviderReceiverHandler().Run(this, std::move(receiver));
return;
}
storage_partition_impl_->GetBroadcastChannelProvider()->Connect(
id_, std::move(request));
id_, std::move(receiver));
}
void RenderProcessHostImpl::BindVideoDecoderService(
......@@ -2275,13 +2262,13 @@ void RenderProcessHostImpl::BindVideoDecoderService(
}
void RenderProcessHostImpl::BindWebDatabaseHostImpl(
blink::mojom::WebDatabaseHostRequest request) {
mojo::PendingReceiver<blink::mojom::WebDatabaseHost> receiver) {
storage::DatabaseTracker* db_tracker =
storage_partition_impl_->GetDatabaseTracker();
db_tracker->task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&WebDatabaseHostImpl::Create, GetID(),
base::WrapRefCounted(db_tracker), std::move(request)));
base::WrapRefCounted(db_tracker), std::move(receiver)));
}
void RenderProcessHostImpl::CreateRendererHost(
......
......@@ -580,10 +580,11 @@ class CONTENT_EXPORT RenderProcessHostImpl
void CreateStoragePartitionService(
mojo::PendingReceiver<blink::mojom::StoragePartitionService> receiver);
void CreateBroadcastChannelProvider(
blink::mojom::BroadcastChannelProviderRequest request);
mojo::PendingReceiver<blink::mojom::BroadcastChannelProvider> receiver);
void CreateRendererHost(mojom::RendererHostAssociatedRequest request);
void BindVideoDecoderService(media::mojom::InterfaceFactoryRequest request);
void BindWebDatabaseHostImpl(blink::mojom::WebDatabaseHostRequest request);
void BindWebDatabaseHostImpl(
mojo::PendingReceiver<blink::mojom::WebDatabaseHost> receiver);
// Control message handlers.
void OnUserMetricsRecordAction(const std::string& action);
......@@ -659,6 +660,10 @@ class CONTENT_EXPORT RenderProcessHostImpl
using AddInterfaceCallback =
base::Callback<void(mojo::InterfaceRequest<InterfaceType>)>;
template <typename InterfaceType>
using AddReceiverCallback =
base::Callback<void(mojo::PendingReceiver<InterfaceType>)>;
template <typename CallbackType>
struct InterfaceGetter;
......@@ -674,6 +679,18 @@ class CONTENT_EXPORT RenderProcessHostImpl
}
};
template <typename InterfaceType>
struct InterfaceGetter<AddReceiverCallback<InterfaceType>> {
static void GetInterfaceOnUIThread(
base::WeakPtr<RenderProcessHostImpl> weak_host,
const AddReceiverCallback<InterfaceType>& callback,
mojo::PendingReceiver<InterfaceType> receiver) {
if (!weak_host)
return;
callback.Run(std::move(receiver));
}
};
// Helper to bind an interface callback whose lifetime is limited to that of
// the render process currently hosted by the RPHI. Callbacks added by this
// method will never run beyond the next invocation of Cleanup().
......
......@@ -4,7 +4,7 @@
#include "third_party/blink/renderer/modules/webdatabase/web_database_impl.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/blink/renderer/modules/webdatabase/database_tracker.h"
#include "third_party/blink/renderer/modules/webdatabase/quota_tracker.h"
......@@ -14,9 +14,10 @@ WebDatabaseImpl::WebDatabaseImpl() = default;
WebDatabaseImpl::~WebDatabaseImpl() = default;
void WebDatabaseImpl::Create(mojom::blink::WebDatabaseRequest request) {
mojo::MakeStrongBinding(std::make_unique<WebDatabaseImpl>(),
std::move(request));
void WebDatabaseImpl::Create(
mojo::PendingReceiver<mojom::blink::WebDatabase> receiver) {
mojo::MakeSelfOwnedReceiver(std::make_unique<WebDatabaseImpl>(),
std::move(receiver));
}
void WebDatabaseImpl::UpdateSize(
......
......@@ -7,6 +7,7 @@
#include <stdint.h>
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "third_party/blink/public/mojom/webdatabase/web_database.mojom-blink.h"
namespace blink {
......@@ -18,7 +19,7 @@ class WebDatabaseImpl : public mojom::blink::WebDatabase {
WebDatabaseImpl();
~WebDatabaseImpl() override;
static void Create(mojom::blink::WebDatabaseRequest);
static void Create(mojo::PendingReceiver<mojom::blink::WebDatabase>);
private:
// blink::mojom::blink::Database
......
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