Skip to content

Commit 08c2656

Browse files
domfarolinoCommit Bot
authored andcommitted
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 <[email protected]> Reviewed-by: Tal Pressman <[email protected]> Reviewed-by: Kentaro Hara <[email protected]> Reviewed-by: Kouhei Ueno <[email protected]> Cr-Commit-Position: refs/heads/master@{#810101}
1 parent 47a04de commit 08c2656

File tree

8 files changed

+106
-7
lines changed

8 files changed

+106
-7
lines changed

content/browser/renderer_host/agent_scheduling_group_host.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,26 @@ void AgentSchedulingGroupHost::DestroyView(int32_t routing_id) {
190190
process_.GetRendererInterface()->DestroyView(routing_id);
191191
}
192192

193+
void AgentSchedulingGroupHost::GetRoute(
194+
int32_t routing_id,
195+
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterfaceProvider>
196+
receiver) {
197+
// TODO(crbug.com/1111231): Make AgentSchedulingGroupHost a fully-fledged
198+
// RouteProvider, so we can register routes directly with an
199+
// AgentSchedulingGroupHost rather than RenderProcessHostImpl.
200+
static_cast<RenderProcessHostImpl&>(process_).GetRoute(routing_id,
201+
std::move(receiver));
202+
}
203+
204+
void AgentSchedulingGroupHost::GetAssociatedInterface(
205+
const std::string& name,
206+
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterface>
207+
receiver) {
208+
// TODO(crbug.com/1111231): Make AgentSchedulingGroupHost a fully-fledged
209+
// AssociatedInterfaceProvider, so we can start associating interfaces
210+
// directly with the AgentSchedulingGroupHost interface.
211+
static_cast<RenderProcessHostImpl&>(process_).GetAssociatedInterface(
212+
name, std::move(receiver));
213+
}
214+
193215
} // namespace content

content/browser/renderer_host/agent_scheduling_group_host.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
#include <stdint.h>
99

1010
#include "content/common/agent_scheduling_group.mojom.h"
11-
#include "content/common/associated_interfaces.mojom-forward.h"
11+
#include "content/common/associated_interfaces.mojom.h"
1212
#include "content/common/content_export.h"
1313
#include "content/common/renderer.mojom-forward.h"
1414
#include "mojo/public/cpp/bindings/associated_receiver.h"
1515
#include "mojo/public/cpp/bindings/associated_remote.h"
1616
#include "mojo/public/cpp/bindings/receiver.h"
1717
#include "mojo/public/cpp/bindings/remote.h"
1818
#include "third_party/abseil-cpp/absl/types/variant.h"
19+
#include "third_party/blink/public/mojom/associated_interfaces/associated_interfaces.mojom.h"
1920

2021
namespace IPC {
2122
class ChannelProxy;
@@ -37,7 +38,9 @@ class SiteInstance;
3738
// An AgentSchedulingGroupHost is stored as (and owned by) UserData on the
3839
// RenderProcessHost.
3940
class CONTENT_EXPORT AgentSchedulingGroupHost
40-
: public mojom::AgentSchedulingGroupHost {
41+
: public mojom::AgentSchedulingGroupHost,
42+
public mojom::RouteProvider,
43+
public blink::mojom::AssociatedInterfaceProvider {
4144
public:
4245
// Get the appropriate AgentSchedulingGroupHost for the given |instance| and
4346
// |process|. For now, each RenderProcessHost has a single
@@ -122,6 +125,18 @@ class CONTENT_EXPORT AgentSchedulingGroupHost
122125
// `AgentSchedulingGroup`.
123126
AgentSchedulingGroupHost(RenderProcessHost& process, bool should_associate);
124127

128+
// mojom::RouteProvider
129+
void GetRoute(
130+
int32_t routing_id,
131+
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterfaceProvider>
132+
receiver) override;
133+
134+
// blink::mojom::AssociatedInterfaceProvider
135+
void GetAssociatedInterface(
136+
const std::string& name,
137+
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterface>
138+
receiver) override;
139+
125140
// The RenderProcessHost this AgentSchedulingGroup is assigned to.
126141
RenderProcessHost& process_;
127142

content/browser/renderer_host/render_process_host_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,12 @@ class CONTENT_EXPORT RenderProcessHostImpl
721721
friend class VisitRelayingRenderProcessHost;
722722
friend class StoragePartitonInterceptor;
723723
friend class RenderProcessHostTest;
724+
// TODO(crbug.com/1111231): This class is a friend so that it can call our
725+
// private mojo implementation methods, acting as a pass-through. This is only
726+
// necessary during the associated interface migration, after which,
727+
// AgentSchedulingGroupHost will not act as a pass-through to the private
728+
// methods here. At that point we'll remove this friend class.
729+
friend class AgentSchedulingGroupHost;
724730

725731
// Use CreateRenderProcessHost() instead of calling this constructor
726732
// directly.

content/child/child_thread_impl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ class CONTENT_EXPORT ChildThreadImpl
167167
bool IsInBrowserProcess() const;
168168

169169
private:
170+
// TODO(crbug.com/1111231): This class is a friend so that it can call our
171+
// private mojo implementation methods, acting as a pass-through. This is only
172+
// necessary during the associated interface migration, after which,
173+
// AgentSchedulingGroup will not act as a pass-through to the private methods
174+
// here. At that point we'll remove this friend class.
175+
friend class AgentSchedulingGroup;
176+
170177
class IOThreadState;
171178

172179
class ChildThreadMessageRouter : public IPC::MessageRouter {

content/renderer/agent_scheduling_group.cc

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ AgentSchedulingGroup::MaybeAssociatedRemote::~MaybeAssociatedRemote() = default;
6363

6464
// AgentSchedulingGroup:
6565
AgentSchedulingGroup::AgentSchedulingGroup(
66+
RenderThreadImpl* render_thread,
6667
PendingRemote<mojom::AgentSchedulingGroupHost> host_remote,
6768
PendingReceiver<mojom::AgentSchedulingGroup> receiver,
6869
base::OnceCallback<void(const AgentSchedulingGroup*)>
6970
mojo_disconnect_handler)
7071
// TODO(crbug.com/1111231): Mojo interfaces should be associated with
7172
// per-ASG task runners instead of default.
72-
: receiver_(*this,
73+
: render_thread_(*render_thread),
74+
receiver_(*this,
7375
std::move(receiver),
7476
base::BindOnce(std::move(mojo_disconnect_handler), this)),
7577
host_remote_(std::move(host_remote)) {
@@ -78,13 +80,15 @@ AgentSchedulingGroup::AgentSchedulingGroup(
7880
}
7981

8082
AgentSchedulingGroup::AgentSchedulingGroup(
83+
RenderThreadImpl* render_thread,
8184
PendingAssociatedRemote<mojom::AgentSchedulingGroupHost> host_remote,
8285
PendingAssociatedReceiver<mojom::AgentSchedulingGroup> receiver,
8386
base::OnceCallback<void(const AgentSchedulingGroup*)>
8487
mojo_disconnect_handler)
8588
// TODO(crbug.com/1111231): Mojo interfaces should be associated with
8689
// per-ASG task runners instead of default.
87-
: receiver_(*this,
90+
: render_thread_(*render_thread),
91+
receiver_(*this,
8892
std::move(receiver),
8993
base::BindOnce(std::move(mojo_disconnect_handler), this)),
9094
host_remote_(std::move(host_remote)) {
@@ -94,4 +98,24 @@ AgentSchedulingGroup::AgentSchedulingGroup(
9498

9599
AgentSchedulingGroup::~AgentSchedulingGroup() = default;
96100

101+
void AgentSchedulingGroup::GetRoute(
102+
int32_t routing_id,
103+
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterfaceProvider>
104+
receiver) {
105+
// TODO(crbug.com/1111231): Make AgentSchedulingGroup a fully-fledged
106+
// RouteProvider, so we can start registering routes directly with an
107+
// AgentSchedulingGroup rather than ChildThreadImpl.
108+
render_thread_.GetRoute(routing_id, std::move(receiver));
109+
}
110+
111+
void AgentSchedulingGroup::GetAssociatedInterface(
112+
const std::string& name,
113+
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterface>
114+
receiver) {
115+
// TODO(crbug.com/1111231): Make AgentSchedulingGroup a fully-fledged
116+
// AssociatedInterfaceProvider, so we can start associating interfaces
117+
// directly with the AgentSchedulingGroup interface.
118+
render_thread_.GetAssociatedInterface(name, std::move(receiver));
119+
}
120+
97121
} // namespace content

content/renderer/agent_scheduling_group.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77

88
#include "base/callback.h"
99
#include "content/common/agent_scheduling_group.mojom.h"
10+
#include "content/common/associated_interfaces.mojom.h"
1011
#include "content/common/content_export.h"
12+
#include "content/renderer/render_thread_impl.h"
1113
#include "mojo/public/cpp/bindings/associated_receiver.h"
1214
#include "mojo/public/cpp/bindings/associated_remote.h"
1315
#include "mojo/public/cpp/bindings/receiver.h"
1416
#include "mojo/public/cpp/bindings/remote.h"
1517
#include "third_party/abseil-cpp/absl/types/variant.h"
18+
#include "third_party/blink/public/mojom/associated_interfaces/associated_interfaces.mojom.h"
1619

1720
namespace content {
1821

@@ -21,16 +24,21 @@ namespace content {
2124
// Blink's unit of scheduling and performance isolation, which is the only way
2225
// to obtain ordering guarantees between different Mojo (associated) interfaces
2326
// and legacy IPC messages.
24-
class CONTENT_EXPORT AgentSchedulingGroup : public mojom::AgentSchedulingGroup {
27+
class CONTENT_EXPORT AgentSchedulingGroup
28+
: public mojom::AgentSchedulingGroup,
29+
public mojom::RouteProvider,
30+
public blink::mojom::AssociatedInterfaceProvider {
2531
public:
2632
// |mojo_disconnect_handler| will be called with |this| when |receiver| is
2733
// disconnected.
2834
AgentSchedulingGroup(
35+
RenderThreadImpl* render_thread,
2936
mojo::PendingRemote<mojom::AgentSchedulingGroupHost> host_remote,
3037
mojo::PendingReceiver<mojom::AgentSchedulingGroup> receiver,
3138
base::OnceCallback<void(const AgentSchedulingGroup*)>
3239
mojo_disconnect_handler);
3340
AgentSchedulingGroup(
41+
RenderThreadImpl* render_thread,
3442
mojo::PendingAssociatedRemote<mojom::AgentSchedulingGroupHost>
3543
host_remote,
3644
mojo::PendingAssociatedReceiver<mojom::AgentSchedulingGroup> receiver,
@@ -86,6 +94,20 @@ class CONTENT_EXPORT AgentSchedulingGroup : public mojom::AgentSchedulingGroup {
8694
remote_;
8795
};
8896

97+
// mojom::RouteProvider
98+
void GetRoute(
99+
int32_t routing_id,
100+
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterfaceProvider>
101+
receiver) override;
102+
103+
// blink::mojom::AssociatedInterfaceProvider
104+
void GetAssociatedInterface(
105+
const std::string& name,
106+
mojo::PendingAssociatedReceiver<blink::mojom::AssociatedInterface>
107+
receiver) override;
108+
109+
RenderThreadImpl& render_thread_;
110+
89111
// Implementation of `mojom::AgentSchedulingGroup`, used for responding to
90112
// calls from the (browser-side) `AgentSchedulingGroupHost`.
91113
MaybeAssociatedReceiver receiver_;

content/renderer/render_thread_impl.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,8 @@ void RenderThreadImpl::CreateAgentSchedulingGroup(
18601860
agent_scheduling_group_host,
18611861
mojo::PendingReceiver<mojom::AgentSchedulingGroup> agent_scheduling_group) {
18621862
agent_scheduling_groups_.emplace(std::make_unique<AgentSchedulingGroup>(
1863-
std::move(agent_scheduling_group_host), std::move(agent_scheduling_group),
1863+
this, std::move(agent_scheduling_group_host),
1864+
std::move(agent_scheduling_group),
18641865
remove_agent_scheduling_group_callback_));
18651866
}
18661867

@@ -1870,7 +1871,8 @@ void RenderThreadImpl::CreateAssociatedAgentSchedulingGroup(
18701871
mojo::PendingAssociatedReceiver<mojom::AgentSchedulingGroup>
18711872
agent_scheduling_group) {
18721873
agent_scheduling_groups_.emplace(std::make_unique<AgentSchedulingGroup>(
1873-
std::move(agent_scheduling_group_host), std::move(agent_scheduling_group),
1874+
this, std::move(agent_scheduling_group_host),
1875+
std::move(agent_scheduling_group),
18741876
remove_agent_scheduling_group_callback_));
18751877
}
18761878

content/renderer/render_thread_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ class CONTENT_EXPORT RenderThreadImpl
414414

415415
private:
416416
friend class RenderThreadImplBrowserTest;
417+
friend class AgentSchedulingGroup;
417418

418419
void OnProcessFinalRelease() override;
419420
// IPC::Listener

0 commit comments

Comments
 (0)