Commit 08c26569 authored by Dominic Farolino's avatar Dominic Farolino Committed by Commit Bot

MBI: AgentSchedulingGroup implements RouteProvider & AssociatedInterfaceProvider

This CL makes AgentSchedulingGroup and its host, implement the
mojom::RouteProvider and blink::mojom::AssociatedInterface interfaces.
This will make it possible in the future to register ASG-specific routes
instead of process-global routes, as well as ASG-specific associated
interfaces, as opposed to interfaces that are associated with the
process-global IPC channel.

Currently the implementations of these interfaces are not operational.
Later CLs will flesh out this implementation so we can begin migrating
interfaces over to the ASG scope.

Bug: 1111231
Change-Id: I3da0a31d31018b18ab616e02f351d3d0876c7694
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2415949
Commit-Queue: Dominic Farolino <dom@chromium.org>
Reviewed-by: default avatarTal Pressman <talp@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810101}
parent 47a04dee
......@@ -190,4 +190,26 @@ void AgentSchedulingGroupHost::DestroyView(int32_t routing_id) {
process_.GetRendererInterface()->DestroyView(routing_id);
}
void AgentSchedulingGroupHost::GetRoute(
int32_t routing_id,
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterfaceProvider>
receiver) {
// TODO(crbug.com/1111231): Make AgentSchedulingGroupHost a fully-fledged
// RouteProvider, so we can register routes directly with an
// AgentSchedulingGroupHost rather than RenderProcessHostImpl.
static_cast<RenderProcessHostImpl&>(process_).GetRoute(routing_id,
std::move(receiver));
}
void AgentSchedulingGroupHost::GetAssociatedInterface(
const std::string& name,
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterface>
receiver) {
// TODO(crbug.com/1111231): Make AgentSchedulingGroupHost a fully-fledged
// AssociatedInterfaceProvider, so we can start associating interfaces
// directly with the AgentSchedulingGroupHost interface.
static_cast<RenderProcessHostImpl&>(process_).GetAssociatedInterface(
name, std::move(receiver));
}
} // namespace content
......@@ -8,7 +8,7 @@
#include <stdint.h>
#include "content/common/agent_scheduling_group.mojom.h"
#include "content/common/associated_interfaces.mojom-forward.h"
#include "content/common/associated_interfaces.mojom.h"
#include "content/common/content_export.h"
#include "content/common/renderer.mojom-forward.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
......@@ -16,6 +16,7 @@
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/mojom/associated_interfaces/associated_interfaces.mojom.h"
namespace IPC {
class ChannelProxy;
......@@ -37,7 +38,9 @@ class SiteInstance;
// An AgentSchedulingGroupHost is stored as (and owned by) UserData on the
// RenderProcessHost.
class CONTENT_EXPORT AgentSchedulingGroupHost
: public mojom::AgentSchedulingGroupHost {
: public mojom::AgentSchedulingGroupHost,
public mojom::RouteProvider,
public blink::mojom::AssociatedInterfaceProvider {
public:
// Get the appropriate AgentSchedulingGroupHost for the given |instance| and
// |process|. For now, each RenderProcessHost has a single
......@@ -122,6 +125,18 @@ class CONTENT_EXPORT AgentSchedulingGroupHost
// `AgentSchedulingGroup`.
AgentSchedulingGroupHost(RenderProcessHost& process, bool should_associate);
// mojom::RouteProvider
void GetRoute(
int32_t routing_id,
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterfaceProvider>
receiver) override;
// blink::mojom::AssociatedInterfaceProvider
void GetAssociatedInterface(
const std::string& name,
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterface>
receiver) override;
// The RenderProcessHost this AgentSchedulingGroup is assigned to.
RenderProcessHost& process_;
......
......@@ -721,6 +721,12 @@ class CONTENT_EXPORT RenderProcessHostImpl
friend class VisitRelayingRenderProcessHost;
friend class StoragePartitonInterceptor;
friend class RenderProcessHostTest;
// TODO(crbug.com/1111231): This class is a friend so that it can call our
// private mojo implementation methods, acting as a pass-through. This is only
// necessary during the associated interface migration, after which,
// AgentSchedulingGroupHost will not act as a pass-through to the private
// methods here. At that point we'll remove this friend class.
friend class AgentSchedulingGroupHost;
// Use CreateRenderProcessHost() instead of calling this constructor
// directly.
......
......@@ -167,6 +167,13 @@ class CONTENT_EXPORT ChildThreadImpl
bool IsInBrowserProcess() const;
private:
// TODO(crbug.com/1111231): This class is a friend so that it can call our
// private mojo implementation methods, acting as a pass-through. This is only
// necessary during the associated interface migration, after which,
// AgentSchedulingGroup will not act as a pass-through to the private methods
// here. At that point we'll remove this friend class.
friend class AgentSchedulingGroup;
class IOThreadState;
class ChildThreadMessageRouter : public IPC::MessageRouter {
......
......@@ -63,13 +63,15 @@ AgentSchedulingGroup::MaybeAssociatedRemote::~MaybeAssociatedRemote() = default;
// AgentSchedulingGroup:
AgentSchedulingGroup::AgentSchedulingGroup(
RenderThreadImpl* render_thread,
PendingRemote<mojom::AgentSchedulingGroupHost> host_remote,
PendingReceiver<mojom::AgentSchedulingGroup> receiver,
base::OnceCallback<void(const AgentSchedulingGroup*)>
mojo_disconnect_handler)
// TODO(crbug.com/1111231): Mojo interfaces should be associated with
// per-ASG task runners instead of default.
: receiver_(*this,
: render_thread_(*render_thread),
receiver_(*this,
std::move(receiver),
base::BindOnce(std::move(mojo_disconnect_handler), this)),
host_remote_(std::move(host_remote)) {
......@@ -78,13 +80,15 @@ AgentSchedulingGroup::AgentSchedulingGroup(
}
AgentSchedulingGroup::AgentSchedulingGroup(
RenderThreadImpl* render_thread,
PendingAssociatedRemote<mojom::AgentSchedulingGroupHost> host_remote,
PendingAssociatedReceiver<mojom::AgentSchedulingGroup> receiver,
base::OnceCallback<void(const AgentSchedulingGroup*)>
mojo_disconnect_handler)
// TODO(crbug.com/1111231): Mojo interfaces should be associated with
// per-ASG task runners instead of default.
: receiver_(*this,
: render_thread_(*render_thread),
receiver_(*this,
std::move(receiver),
base::BindOnce(std::move(mojo_disconnect_handler), this)),
host_remote_(std::move(host_remote)) {
......@@ -94,4 +98,24 @@ AgentSchedulingGroup::AgentSchedulingGroup(
AgentSchedulingGroup::~AgentSchedulingGroup() = default;
void AgentSchedulingGroup::GetRoute(
int32_t routing_id,
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterfaceProvider>
receiver) {
// TODO(crbug.com/1111231): Make AgentSchedulingGroup a fully-fledged
// RouteProvider, so we can start registering routes directly with an
// AgentSchedulingGroup rather than ChildThreadImpl.
render_thread_.GetRoute(routing_id, std::move(receiver));
}
void AgentSchedulingGroup::GetAssociatedInterface(
const std::string& name,
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterface>
receiver) {
// TODO(crbug.com/1111231): Make AgentSchedulingGroup a fully-fledged
// AssociatedInterfaceProvider, so we can start associating interfaces
// directly with the AgentSchedulingGroup interface.
render_thread_.GetAssociatedInterface(name, std::move(receiver));
}
} // namespace content
......@@ -7,12 +7,15 @@
#include "base/callback.h"
#include "content/common/agent_scheduling_group.mojom.h"
#include "content/common/associated_interfaces.mojom.h"
#include "content/common/content_export.h"
#include "content/renderer/render_thread_impl.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/mojom/associated_interfaces/associated_interfaces.mojom.h"
namespace content {
......@@ -21,16 +24,21 @@ namespace content {
// Blink's unit of scheduling and performance isolation, which is the only way
// to obtain ordering guarantees between different Mojo (associated) interfaces
// and legacy IPC messages.
class CONTENT_EXPORT AgentSchedulingGroup : public mojom::AgentSchedulingGroup {
class CONTENT_EXPORT AgentSchedulingGroup
: public mojom::AgentSchedulingGroup,
public mojom::RouteProvider,
public blink::mojom::AssociatedInterfaceProvider {
public:
// |mojo_disconnect_handler| will be called with |this| when |receiver| is
// disconnected.
AgentSchedulingGroup(
RenderThreadImpl* render_thread,
mojo::PendingRemote<mojom::AgentSchedulingGroupHost> host_remote,
mojo::PendingReceiver<mojom::AgentSchedulingGroup> receiver,
base::OnceCallback<void(const AgentSchedulingGroup*)>
mojo_disconnect_handler);
AgentSchedulingGroup(
RenderThreadImpl* render_thread,
mojo::PendingAssociatedRemote<mojom::AgentSchedulingGroupHost>
host_remote,
mojo::PendingAssociatedReceiver<mojom::AgentSchedulingGroup> receiver,
......@@ -86,6 +94,20 @@ class CONTENT_EXPORT AgentSchedulingGroup : public mojom::AgentSchedulingGroup {
remote_;
};
// mojom::RouteProvider
void GetRoute(
int32_t routing_id,
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterfaceProvider>
receiver) override;
// blink::mojom::AssociatedInterfaceProvider
void GetAssociatedInterface(
const std::string& name,
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterface>
receiver) override;
RenderThreadImpl& render_thread_;
// Implementation of `mojom::AgentSchedulingGroup`, used for responding to
// calls from the (browser-side) `AgentSchedulingGroupHost`.
MaybeAssociatedReceiver receiver_;
......
......@@ -1860,7 +1860,8 @@ void RenderThreadImpl::CreateAgentSchedulingGroup(
agent_scheduling_group_host,
mojo::PendingReceiver<mojom::AgentSchedulingGroup> agent_scheduling_group) {
agent_scheduling_groups_.emplace(std::make_unique<AgentSchedulingGroup>(
std::move(agent_scheduling_group_host), std::move(agent_scheduling_group),
this, std::move(agent_scheduling_group_host),
std::move(agent_scheduling_group),
remove_agent_scheduling_group_callback_));
}
......@@ -1870,7 +1871,8 @@ void RenderThreadImpl::CreateAssociatedAgentSchedulingGroup(
mojo::PendingAssociatedReceiver<mojom::AgentSchedulingGroup>
agent_scheduling_group) {
agent_scheduling_groups_.emplace(std::make_unique<AgentSchedulingGroup>(
std::move(agent_scheduling_group_host), std::move(agent_scheduling_group),
this, std::move(agent_scheduling_group_host),
std::move(agent_scheduling_group),
remove_agent_scheduling_group_callback_));
}
......
......@@ -414,6 +414,7 @@ class CONTENT_EXPORT RenderThreadImpl
private:
friend class RenderThreadImplBrowserTest;
friend class AgentSchedulingGroup;
void OnProcessFinalRelease() override;
// IPC::Listener
......
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