Add a flag to use strict SiteInstances even when cross-site process sharing is allowed.
This should guarantee that a SiteInstance only contains a single site
url which accurately reflects the documents it contains, rather than
allowing a SiteInstance to contain documents from multiple sites when
strict site isolation is disabled.
The renderer process will have separate FrameTrees for each
SiteInstance, so when this mode is enabled without strict site
isolation, we will attempt to co-locate SiteInstances from the same
BrowsingInstance in a single process, to minimize the creation of
unnecessary processes.
Bug: 928390
Change-Id: I45b643912676b6fcec4b0c8ae5fd1c3dc7dd4176
Reviewed-on: https://chromium-review.googlesource.com/c/1423134
Commit-Queue: Nate Chapin <[email protected]>
Reviewed-by: Alex Moshchuk <[email protected]>
Cr-Commit-Position: refs/heads/master@{#628978}
diff --git a/content/browser/site_instance_impl.cc b/content/browser/site_instance_impl.cc
index b8b2749a..eb202b8 100644
--- a/content/browser/site_instance_impl.cc
+++ b/content/browser/site_instance_impl.cc
@@ -21,6 +21,7 @@
#include "content/public/browser/render_process_host_factory.h"
#include "content/public/browser/site_isolation_policy.h"
#include "content/public/browser/web_ui_controller_factory.h"
+#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
@@ -102,6 +103,33 @@
return browsing_instance_->isolation_context();
}
+RenderProcessHost* SiteInstanceImpl::GetDefaultProcessIfUsable() {
+ if (!base::FeatureList::IsEnabled(
+ features::kProcessSharingWithStrictSiteInstances)) {
+ return nullptr;
+ }
+ if (RequiresDedicatedProcess())
+ return nullptr;
+ return browsing_instance_->default_process();
+}
+
+void SiteInstanceImpl::MaybeSetBrowsingInstanceDefaultProcess() {
+ if (!base::FeatureList::IsEnabled(
+ features::kProcessSharingWithStrictSiteInstances)) {
+ return;
+ }
+ // Wait until this SiteInstance both has a site and a process
+ // assigned, so that we can be sure that RequiresDedicatedProcess()
+ // is accurate and we actually have a process to set.
+ if (!process_ || !has_site_ || RequiresDedicatedProcess())
+ return;
+ if (browsing_instance_->default_process()) {
+ DCHECK_EQ(process_, browsing_instance_->default_process());
+ return;
+ }
+ browsing_instance_->SetDefaultProcess(process_);
+}
+
// static
BrowsingInstanceId SiteInstanceImpl::NextBrowsingInstanceId() {
return BrowsingInstance::NextBrowsingInstanceId();
@@ -152,6 +180,8 @@
CHECK(process_);
process_->AddObserver(this);
+ MaybeSetBrowsingInstanceDefaultProcess();
+
// If we are using process-per-site, we need to register this process
// for the current site so that we can find it again. (If no site is set
// at this time, we will register it in SetSite().)
@@ -223,6 +253,7 @@
RenderProcessHostImpl::RegisterSoleProcessHostForSite(browser_context,
process_, this);
}
+ MaybeSetBrowsingInstanceDefaultProcess();
}
}