Commit 1fa2bbfc authored by Tal Pressman's avatar Tal Pressman Committed by Commit Bot

[MBI] Associate RenderFrameHost with AgentSchedulingGroup.

Add a pointer to the AgentSchedulingGroupHost in RenderFrameHost, and
route some initial calls through it instead of the RenderProcessHost.
This is needed since in the future all frame-specific communication will
be done directly at the agent scheduling group level, and not the
process level.

Bug: 1111231
Change-Id: I62cb6b3bffe79cd143a8aa27f1c471df06f508a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346687
Commit-Queue: Tal Pressman <talp@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799996}
parent 5d8d5abc
...@@ -95,6 +95,7 @@ ...@@ -95,6 +95,7 @@
#include "content/browser/portal/portal.h" #include "content/browser/portal/portal.h"
#include "content/browser/presentation/presentation_service_impl.h" #include "content/browser/presentation/presentation_service_impl.h"
#include "content/browser/push_messaging/push_messaging_manager.h" #include "content/browser/push_messaging/push_messaging_manager.h"
#include "content/browser/renderer_host/agent_scheduling_group_host.h"
#include "content/browser/renderer_host/dip_util.h" #include "content/browser/renderer_host/dip_util.h"
#include "content/browser/renderer_host/input/input_router.h" #include "content/browser/renderer_host/input/input_router.h"
#include "content/browser/renderer_host/input/timeout_monitor.h" #include "content/browser/renderer_host/input/timeout_monitor.h"
...@@ -917,7 +918,7 @@ RenderFrameHostImpl::RenderFrameHostImpl( ...@@ -917,7 +918,7 @@ RenderFrameHostImpl::RenderFrameHostImpl(
: render_view_host_(std::move(render_view_host)), : render_view_host_(std::move(render_view_host)),
delegate_(delegate), delegate_(delegate),
site_instance_(static_cast<SiteInstanceImpl*>(site_instance)), site_instance_(static_cast<SiteInstanceImpl*>(site_instance)),
process_(site_instance->GetProcess()), agent_scheduling_group_(site_instance_->GetAgentSchedulingGroup()),
frame_tree_(frame_tree), frame_tree_(frame_tree),
frame_tree_node_(frame_tree_node), frame_tree_node_(frame_tree_node),
parent_(frame_tree_node_->parent()), parent_(frame_tree_node_->parent()),
...@@ -961,12 +962,12 @@ RenderFrameHostImpl::RenderFrameHostImpl( ...@@ -961,12 +962,12 @@ RenderFrameHostImpl::RenderFrameHostImpl(
DCHECK(lifecycle_state_ == LifecycleState::kSpeculative || DCHECK(lifecycle_state_ == LifecycleState::kSpeculative ||
lifecycle_state_ == LifecycleState::kActive); lifecycle_state_ == LifecycleState::kActive);
GetProcess()->AddRoute(routing_id_, this); agent_scheduling_group().AddRoute(routing_id_, this);
g_routing_id_frame_map.Get().emplace( g_routing_id_frame_map.Get().emplace(
GlobalFrameRoutingId(GetProcess()->GetID(), routing_id_), this); GlobalFrameRoutingId(GetProcess()->GetID(), routing_id_), this);
g_token_frame_map.Get().insert(std::make_pair(frame_token_, this)); g_token_frame_map.Get().insert(std::make_pair(frame_token_, this));
site_instance_->AddObserver(this); site_instance_->AddObserver(this);
process_->AddObserver(this); GetProcess()->AddObserver(this);
GetSiteInstance()->IncrementActiveFrameCount(); GetSiteInstance()->IncrementActiveFrameCount();
if (parent_) { if (parent_) {
...@@ -1074,7 +1075,7 @@ RenderFrameHostImpl::~RenderFrameHostImpl() { ...@@ -1074,7 +1075,7 @@ RenderFrameHostImpl::~RenderFrameHostImpl() {
g_token_frame_map.Get().erase(frame_token_); g_token_frame_map.Get().erase(frame_token_);
site_instance_->RemoveObserver(this); site_instance_->RemoveObserver(this);
process_->RemoveObserver(this); GetProcess()->RemoveObserver(this);
const bool was_created = render_frame_created_; const bool was_created = render_frame_created_;
render_frame_created_ = false; render_frame_created_ = false;
...@@ -1147,7 +1148,7 @@ RenderFrameHostImpl::~RenderFrameHostImpl() { ...@@ -1147,7 +1148,7 @@ RenderFrameHostImpl::~RenderFrameHostImpl() {
if (was_created && render_view_host_->GetMainFrame() != this) if (was_created && render_view_host_->GetMainFrame() != this)
CHECK(IsPendingDeletion() || IsInBackForwardCache()); CHECK(IsPendingDeletion() || IsInBackForwardCache());
GetProcess()->RemoveRoute(routing_id_); agent_scheduling_group().RemoveRoute(routing_id_);
g_routing_id_frame_map.Get().erase( g_routing_id_frame_map.Get().erase(
GlobalFrameRoutingId(GetProcess()->GetID(), routing_id_)); GlobalFrameRoutingId(GetProcess()->GetID(), routing_id_));
...@@ -1391,7 +1392,7 @@ SiteInstanceImpl* RenderFrameHostImpl::GetSiteInstance() { ...@@ -1391,7 +1392,7 @@ SiteInstanceImpl* RenderFrameHostImpl::GetSiteInstance() {
} }
RenderProcessHost* RenderFrameHostImpl::GetProcess() { RenderProcessHost* RenderFrameHostImpl::GetProcess() {
return process_; return agent_scheduling_group_.GetProcess();
} }
RenderFrameHostImpl* RenderFrameHostImpl::GetParent() { RenderFrameHostImpl* RenderFrameHostImpl::GetParent() {
...@@ -1700,11 +1701,8 @@ RenderFrameHostImpl::GetRemoteAssociatedInterfaces() { ...@@ -1700,11 +1701,8 @@ RenderFrameHostImpl::GetRemoteAssociatedInterfaces() {
if (!remote_associated_interfaces_) { if (!remote_associated_interfaces_) {
mojo::AssociatedRemote<blink::mojom::AssociatedInterfaceProvider> mojo::AssociatedRemote<blink::mojom::AssociatedInterfaceProvider>
remote_interfaces; remote_interfaces;
IPC::ChannelProxy* channel = GetProcess()->GetChannel(); if (agent_scheduling_group().GetChannel()) {
if (channel) { agent_scheduling_group().GetRemoteRouteProvider()->GetRoute(
RenderProcessHostImpl* process =
static_cast<RenderProcessHostImpl*>(GetProcess());
process->GetRemoteRouteProvider()->GetRoute(
GetRoutingID(), remote_interfaces.BindNewEndpointAndPassReceiver()); GetRoutingID(), remote_interfaces.BindNewEndpointAndPassReceiver());
} else { } else {
// The channel may not be initialized in some tests environments. In this // The channel may not be initialized in some tests environments. In this
...@@ -1746,7 +1744,7 @@ PageVisibilityState RenderFrameHostImpl::GetVisibilityState() { ...@@ -1746,7 +1744,7 @@ PageVisibilityState RenderFrameHostImpl::GetVisibilityState() {
} }
bool RenderFrameHostImpl::Send(IPC::Message* message) { bool RenderFrameHostImpl::Send(IPC::Message* message) {
return GetProcess()->Send(message); return agent_scheduling_group().Send(message);
} }
bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message& msg) { bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message& msg) {
...@@ -2206,7 +2204,7 @@ bool RenderFrameHostImpl::CreateRenderFrame( ...@@ -2206,7 +2204,7 @@ bool RenderFrameHostImpl::CreateRenderFrame(
// be able to insert the new frame in the frame tree. // be able to insert the new frame in the frame tree.
DCHECK(params->previous_routing_id != MSG_ROUTING_NONE || DCHECK(params->previous_routing_id != MSG_ROUTING_NONE ||
params->parent_routing_id != MSG_ROUTING_NONE); params->parent_routing_id != MSG_ROUTING_NONE);
GetProcess()->GetRendererInterface()->CreateFrame(std::move(params)); agent_scheduling_group().CreateFrame(std::move(params));
if (previous_routing_id != MSG_ROUTING_NONE) { if (previous_routing_id != MSG_ROUTING_NONE) {
RenderFrameProxyHost* proxy = RenderFrameProxyHost::FromID( RenderFrameProxyHost* proxy = RenderFrameProxyHost::FromID(
...@@ -6230,7 +6228,7 @@ void RenderFrameHostImpl::CommitNavigation( ...@@ -6230,7 +6228,7 @@ void RenderFrameHostImpl::CommitNavigation(
browser_context, GetSiteInstance())); browser_context, GetSiteInstance()));
non_network_url_loader_factories_.emplace( non_network_url_loader_factories_.emplace(
url::kFileSystemScheme, content::CreateFileSystemURLLoaderFactory( url::kFileSystemScheme, content::CreateFileSystemURLLoaderFactory(
process_->GetID(), GetFrameTreeNodeId(), GetProcess()->GetID(), GetFrameTreeNodeId(),
partition->GetFileSystemContext(), partition->GetFileSystemContext(),
partition->GetPartitionDomain())); partition->GetPartitionDomain()));
...@@ -6240,7 +6238,8 @@ void RenderFrameHostImpl::CommitNavigation( ...@@ -6240,7 +6238,8 @@ void RenderFrameHostImpl::CommitNavigation(
GetContentClient() GetContentClient()
->browser() ->browser()
->RegisterNonNetworkSubresourceURLLoaderFactories( ->RegisterNonNetworkSubresourceURLLoaderFactories(
process_->GetID(), routing_id_, &non_network_url_loader_factories_); GetProcess()->GetID(), routing_id_,
&non_network_url_loader_factories_);
for (auto& factory : non_network_url_loader_factories_) { for (auto& factory : non_network_url_loader_factories_) {
mojo::PendingRemote<network::mojom::URLLoaderFactory> mojo::PendingRemote<network::mojom::URLLoaderFactory>
...@@ -7478,7 +7477,7 @@ void RenderFrameHostImpl::CreateInstalledAppProvider( ...@@ -7478,7 +7477,7 @@ void RenderFrameHostImpl::CreateInstalledAppProvider(
void RenderFrameHostImpl::CreateDedicatedWorkerHostFactory( void RenderFrameHostImpl::CreateDedicatedWorkerHostFactory(
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver) { mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver) {
// Allocate the worker in the same process as the creator. // Allocate the worker in the same process as the creator.
int worker_process_id = process_->GetID(); int worker_process_id = GetProcess()->GetID();
mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter>
coep_reporter; coep_reporter;
...@@ -7823,7 +7822,7 @@ RenderFrameHostImpl::CreateNavigationRequestForCommit( ...@@ -7823,7 +7822,7 @@ RenderFrameHostImpl::CreateNavigationRequestForCommit(
// one only for cross-document navigations. // one only for cross-document navigations.
if (!is_same_document) { if (!is_same_document) {
coep_reporter = std::make_unique<CrossOriginEmbedderPolicyReporter>( coep_reporter = std::make_unique<CrossOriginEmbedderPolicyReporter>(
process_->GetStoragePartition(), params.url, GetProcess()->GetStoragePartition(), params.url,
cross_origin_embedder_policy_.reporting_endpoint, cross_origin_embedder_policy_.reporting_endpoint,
cross_origin_embedder_policy_.report_only_reporting_endpoint); cross_origin_embedder_policy_.report_only_reporting_endpoint);
} }
...@@ -8483,9 +8482,11 @@ RenderFrameHostImpl::CommitAsTracedValue( ...@@ -8483,9 +8482,11 @@ RenderFrameHostImpl::CommitAsTracedValue(
auto value = std::make_unique<base::trace_event::TracedValue>(); auto value = std::make_unique<base::trace_event::TracedValue>();
// TODO(nasko): Move the process lock into RenderProcessHost. // TODO(nasko): Move the process lock into RenderProcessHost.
value->SetString("process lock", ChildProcessSecurityPolicyImpl::GetInstance() value->SetString(
->GetProcessLock(process_->GetID()) "process lock",
.ToString()); ChildProcessSecurityPolicyImpl::GetInstance()
->GetProcessLock(agent_scheduling_group_.GetProcess()->GetID())
.ToString());
value->SetInteger("nav_entry_id", params->nav_entry_id); value->SetInteger("nav_entry_id", params->nav_entry_id);
value->SetInteger("item_sequence_number", params->item_sequence_number); value->SetInteger("item_sequence_number", params->item_sequence_number);
......
...@@ -185,6 +185,7 @@ class ClipboardFormatType; ...@@ -185,6 +185,7 @@ class ClipboardFormatType;
} }
namespace content { namespace content {
class AgentSchedulingGroupHost;
class AppCacheNavigationHandle; class AppCacheNavigationHandle;
class AuthenticatorImpl; class AuthenticatorImpl;
class BackForwardCacheMetrics; class BackForwardCacheMetrics;
...@@ -530,6 +531,9 @@ class CONTENT_EXPORT RenderFrameHostImpl ...@@ -530,6 +531,9 @@ class CONTENT_EXPORT RenderFrameHostImpl
void DidNavigate(const FrameHostMsg_DidCommitProvisionalLoad_Params& params, void DidNavigate(const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
bool did_create_new_document); bool did_create_new_document);
AgentSchedulingGroupHost& agent_scheduling_group() {
return agent_scheduling_group_;
}
RenderViewHostImpl* render_view_host() { return render_view_host_.get(); } RenderViewHostImpl* render_view_host() { return render_view_host_.get(); }
RenderFrameHostDelegate* delegate() { return delegate_; } RenderFrameHostDelegate* delegate() { return delegate_; }
FrameTree* frame_tree() const { return frame_tree_; } FrameTree* frame_tree() const { return frame_tree_; }
...@@ -2511,13 +2515,13 @@ class CONTENT_EXPORT RenderFrameHostImpl ...@@ -2511,13 +2515,13 @@ class CONTENT_EXPORT RenderFrameHostImpl
// time. // time.
const scoped_refptr<SiteInstanceImpl> site_instance_; const scoped_refptr<SiteInstanceImpl> site_instance_;
// The renderer process this RenderFrameHost is associated with. It is // The agent scheduling group this RenderFrameHost is associated with. It is
// initialized through a call to site_instance_->GetProcess() at creation // initialized through a call to site_instance_->GetAgentSchedulingGroupHost()
// time. RenderFrameHost::GetProcess() uses this cached pointer to avoid // at creation time. This cached pointer is used to avoid recreating the
// recreating the renderer process if it has crashed, since using // renderer process if it has crashed, since using
// SiteInstance::GetProcess() has the side effect of creating the process // SiteInstance::GetProcess()/GetAgentSchedulingGroupHost() has the side
// again if it is gone. // effect of creating the process again if it is gone.
RenderProcessHost* const process_; AgentSchedulingGroupHost& agent_scheduling_group_;
// Reference to the whole frame tree that this RenderFrameHost belongs to. // Reference to the whole frame tree that this RenderFrameHost belongs to.
// Allows this RenderFrameHost to add and remove nodes in response to // Allows this RenderFrameHost to add and remove nodes in response to
......
...@@ -6,11 +6,18 @@ ...@@ -6,11 +6,18 @@
#include <memory> #include <memory>
#include "base/supports_user_data.h" #include "base/supports_user_data.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
namespace content { namespace content {
namespace { namespace {
using IPC::ChannelProxy;
using IPC::Listener;
using mojom::CreateFrameParamsPtr;
using mojom::RouteProvider;
static constexpr char kAgentGroupHostDataKey[] = static constexpr char kAgentGroupHostDataKey[] =
"AgentSchedulingGroupHostUserDataKey"; "AgentSchedulingGroupHostUserDataKey";
class AgentGroupHostUserData : public base::SupportsUserData::Data { class AgentGroupHostUserData : public base::SupportsUserData::Data {
...@@ -55,4 +62,31 @@ RenderProcessHost* AgentSchedulingGroupHost::GetProcess() { ...@@ -55,4 +62,31 @@ RenderProcessHost* AgentSchedulingGroupHost::GetProcess() {
return &process_; return &process_;
} }
ChannelProxy* AgentSchedulingGroupHost::GetChannel() {
return process_.GetChannel();
}
bool AgentSchedulingGroupHost::Send(IPC::Message* message) {
return process_.Send(message);
}
void AgentSchedulingGroupHost::AddRoute(int32_t routing_id,
Listener* listener) {
process_.AddRoute(routing_id, listener);
}
void AgentSchedulingGroupHost::RemoveRoute(int32_t routing_id) {
process_.RemoveRoute(routing_id);
}
RouteProvider* AgentSchedulingGroupHost::GetRemoteRouteProvider() {
RenderProcessHostImpl& process =
static_cast<RenderProcessHostImpl&>(process_);
return process.GetRemoteRouteProvider();
}
void AgentSchedulingGroupHost::CreateFrame(CreateFrameParamsPtr params) {
process_.GetRendererInterface()->CreateFrame(std::move(params));
}
} // namespace content } // namespace content
...@@ -5,12 +5,22 @@ ...@@ -5,12 +5,22 @@
#ifndef CONTENT_BROWSER_RENDERER_HOST_AGENT_SCHEDULING_GROUP_HOST_H_ #ifndef CONTENT_BROWSER_RENDERER_HOST_AGENT_SCHEDULING_GROUP_HOST_H_
#define CONTENT_BROWSER_RENDERER_HOST_AGENT_SCHEDULING_GROUP_HOST_H_ #define CONTENT_BROWSER_RENDERER_HOST_AGENT_SCHEDULING_GROUP_HOST_H_
#include <stdint.h>
#include <memory> #include <memory>
#include "content/common/agent_scheduling_group.mojom.h" #include "content/common/agent_scheduling_group.mojom.h"
#include "content/common/associated_interfaces.mojom-forward.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/common/renderer.mojom-forward.h"
#include "ipc/ipc_listener.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
namespace IPC {
class ChannelProxy;
class Listener;
class Message;
} // namespace IPC
namespace content { namespace content {
class RenderProcessHost; class RenderProcessHost;
...@@ -39,6 +49,18 @@ class CONTENT_EXPORT AgentSchedulingGroupHost { ...@@ -39,6 +49,18 @@ class CONTENT_EXPORT AgentSchedulingGroupHost {
RenderProcessHost* GetProcess(); RenderProcessHost* GetProcess();
// IPC and mojo messages to be forwarded to the RenderProcessHost, for now. In
// the future they will be handled directly by the AgentSchedulingGroupHost.
// IPC:
IPC::ChannelProxy* GetChannel();
bool Send(IPC::Message* message);
void AddRoute(int32_t routing_id, IPC::Listener* listener);
void RemoveRoute(int32_t routing_id);
// Mojo:
mojom::RouteProvider* GetRemoteRouteProvider();
void CreateFrame(mojom::CreateFrameParamsPtr params);
private: private:
// The RenderProcessHost this AgentSchedulingGroup is assigned to. // The RenderProcessHost this AgentSchedulingGroup is assigned to.
RenderProcessHost& process_; RenderProcessHost& process_;
......
...@@ -345,6 +345,21 @@ RenderProcessHost* SiteInstanceImpl::GetProcess() { ...@@ -345,6 +345,21 @@ RenderProcessHost* SiteInstanceImpl::GetProcess() {
return process_; return process_;
} }
AgentSchedulingGroupHost& SiteInstanceImpl::GetAgentSchedulingGroup() {
if (!agent_scheduling_group_) {
// If an AgentSchedulingGroup has not yet been assigned, we need to have it
// assigned (along with a RenderProcessHost). To preserve the invariant that
// |process_| and |agent_scheduling_group_| are always changed together, we
// call GetProcess(), and assume that it will set both members.
GetProcess();
}
DCHECK(agent_scheduling_group_);
DCHECK_EQ(agent_scheduling_group_->GetProcess(), process_);
return *agent_scheduling_group_;
}
void SiteInstanceImpl::ReuseCurrentProcessIfPossible( void SiteInstanceImpl::ReuseCurrentProcessIfPossible(
RenderProcessHost* current_process) { RenderProcessHost* current_process) {
DCHECK(!IsGuest()); DCHECK(!IsGuest());
......
...@@ -477,6 +477,13 @@ class CONTENT_EXPORT SiteInstanceImpl final : public SiteInstance, ...@@ -477,6 +477,13 @@ class CONTENT_EXPORT SiteInstanceImpl final : public SiteInstance,
void PreventOptInOriginIsolation( void PreventOptInOriginIsolation(
const url::Origin& previously_visited_origin); const url::Origin& previously_visited_origin);
// Returns the current AgentSchedulingGroupHost this SiteInstance is
// associated with. Since the AgentSchedulingGroupHost *must* be assigned (and
// cleared) together with the RenderProcessHost, calling this method when no
// AgentSchedulingGroupHost is set will trigger the creation of a new
// RenderProcessHost (with a new ID).
AgentSchedulingGroupHost& GetAgentSchedulingGroup();
private: private:
friend class BrowsingInstance; friend class BrowsingInstance;
friend class SiteInstanceTestBrowserClient; friend class SiteInstanceTestBrowserClient;
......
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