Commit 42e682e5 authored by sreejakshetty@chromium.org's avatar sreejakshetty@chromium.org Committed by Commit Bot

[bfcache] Specify binding level for page in BFCache on Android

Currently the process binding strength of the page in back-forward cache
is same as foreground page.

We want to set the process binding strength of the page once it enters the
back-forward cache to the same level as background tabs to ensure that the OS
can kill a process with bfcached page instead of the process with foreground
page.

Bug: 998608

Here is the document explaining more details:
https://docs.google.com/document/d/12xiw5jqR7A_cvpDYPoX1dyv0XyMPJJVh1uEHZRyE8TE/edit?usp=sharing

Change-Id: I6dd9fbaf90b6640c602734784dc5c51338a115a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893067
Commit-Queue: Sreeja Kamishetty <sreejakshetty@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Reviewed-by: default avatarCarlos Caballero <carlscab@google.com>
Cr-Commit-Position: refs/heads/master@{#721848}
parent fd7b0a79
......@@ -96,6 +96,10 @@ class BackForwardCacheBrowserTest : public ContentBrowserTest {
// TODO(sreejakshetty): Initialize ScopedFeatureLists from test constructor.
EnableFeatureAndSetParams(features::kBackForwardCache,
"TimeToLiveInBackForwardCacheInSeconds", "3600");
#if defined(OS_ANDROID)
EnableFeatureAndSetParams(features::kBackForwardCache,
"process_binding_strength", "NORMAL");
#endif
SetupFeaturesAndParameters();
command_line->AppendSwitchASCII(
......@@ -4684,4 +4688,37 @@ IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest, WebMidiNotCached) {
FROM_HERE);
}
#if defined(OS_ANDROID)
IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest,
ChildImportanceTestForBackForwardCachedPagesTest) {
web_contents()->SetMainFrameImportance(ChildProcessImportance::MODERATE);
ASSERT_TRUE(embedded_test_server()->Start());
GURL url_a(embedded_test_server()->GetURL("a.com", "/title1.html"));
GURL url_b(embedded_test_server()->GetURL("b.com", "/title1.html"));
// 1) Navigate to A.
EXPECT_TRUE(NavigateToURL(shell(), url_a));
RenderFrameHostImpl* rfh_a = current_frame_host();
RenderFrameDeletedObserver delete_observer_rfh_a(rfh_a);
// 2) Navigate to B.
EXPECT_TRUE(NavigateToURL(shell(), url_b));
ASSERT_FALSE(delete_observer_rfh_a.deleted());
// 3) Verify the importance of page after entering back-forward cache to be
// "NORMAL".
EXPECT_EQ(ChildProcessImportance::NORMAL,
rfh_a->GetProcess()->GetEffectiveImportance());
// 4) Go back to A.
web_contents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
// 5) Verify the importance was restored correctly after page leaves
// back-forward cache.
EXPECT_EQ(ChildProcessImportance::MODERATE,
rfh_a->GetProcess()->GetEffectiveImportance());
}
#endif
} // namespace content
......@@ -21,6 +21,9 @@
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "third_party/blink/public/common/scheduler/web_scheduler_tracked_feature.h"
#if defined(OS_ANDROID)
#include "content/public/browser/android/child_process_importance.h"
#endif
namespace content {
......@@ -43,6 +46,31 @@ static constexpr int kDefaultTimeToLiveInBackForwardCacheInSeconds = 15;
// don't need |navigation_start|.
constexpr base::TimeTicks kInvalidNavigationStart = base::TimeTicks();
#if defined(OS_ANDROID)
bool IsProcessBindingEnabled() {
const std::string process_binding_param =
base::GetFieldTrialParamValueByFeature(features::kBackForwardCache,
"process_binding_strength");
return process_binding_param.empty() || process_binding_param == "DISABLE";
}
// Association of ChildProcessImportance to corresponding string names.
const base::FeatureParam<ChildProcessImportance>::Option
child_process_importance_options[] = {
{ChildProcessImportance::IMPORTANT, "IMPORTANT"},
{ChildProcessImportance::MODERATE, "MODERATE"},
{ChildProcessImportance::NORMAL, "NORMAL"}};
// Defines the binding strength for a processes holding cached pages. The value
// is read from an experiment parameter value. Ideally this would be lower than
// the one for processes holding the foreground page and similar to that of
// background tabs so that the OS will hopefully kill the foreground tab last.
// The default importance is set to MODERATE.
const base::FeatureParam<ChildProcessImportance> kChildProcessImportanceParam{
&features::kBackForwardCache, "process_binding_strength",
ChildProcessImportance::MODERATE, &child_process_importance_options};
#endif
void SetPageFrozenImpl(
RenderFrameHostImpl* render_frame_host,
bool frozen,
......@@ -327,6 +355,21 @@ void BackForwardCacheImpl::StoreEntry(
TRACE_EVENT0("navigation", "BackForwardCache::StoreEntry");
DCHECK(CanStoreDocument(entry->render_frame_host.get()));
#if defined(OS_ANDROID)
if (!IsProcessBindingEnabled()) {
// Set the priority of the main frame on entering the back-forward cache to
// make sure the page gets evicted instead of foreground tab. This might not
// become the effective priority of the process if it owns other higher
// priority RenderWidgetHost. We don't need to reset the priority in
// RestoreEntry as it is taken care by WebContentsImpl::NotifyFrameSwapped
// on restoration.
RenderWidgetHostImpl* rwh = entry->render_frame_host->GetRenderWidgetHost();
ChildProcessImportance current_importance = rwh->importance();
rwh->SetImportance(
std::min(current_importance, kChildProcessImportanceParam.Get()));
}
#endif
entry->render_frame_host->EnterBackForwardCache();
entries_.push_front(std::move(entry));
......
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