Commit 3637ad41 authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

Allow experimental configuration of IsolatedPrerender max body size

Also adds a test for documenting what happens when the limit is
reached.

Bug: 1115736
Change-Id: Ie488adb6b874ae47503670514bd7456bef8bfd6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354536Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797776}
parent 38d4ccfd
......@@ -65,6 +65,12 @@ IsolatedPrerenderMaximumNumberOfNoStatePrefetchAttempts() {
return max;
}
size_t IsolatedPrerenderMainframeBodyLengthLimit() {
return 1024 * base::GetFieldTrialParamByFeatureAsInt(
features::kIsolatePrerenders,
"max_mainframe_body_length_kb", 5 * 1024);
}
size_t IsolatedPrerenderMaximumNumberOfConcurrentPrefetches() {
return static_cast<size_t>(base::GetFieldTrialParamByFeatureAsInt(
features::kIsolatePrerenders, "max_concurrent_prefetches", 1));
......
......@@ -34,6 +34,10 @@ size_t IsolatedPrerenderMaximumNumberOfConcurrentPrefetches();
base::Optional<size_t>
IsolatedPrerenderMaximumNumberOfNoStatePrefetchAttempts();
// The maximum body length allowed to be prefetched for mainframe responses in
// bytes.
size_t IsolatedPrerenderMainframeBodyLengthLimit();
// Whether idle sockets should be closed after every prefetch.
bool IsolatedPrerenderCloseIdleSockets();
......
......@@ -677,7 +677,7 @@ void IsolatedPrerenderTabHelper::StartSinglePrefetch() {
GetURLLoaderFactory(),
base::BindOnce(&IsolatedPrerenderTabHelper::OnPrefetchComplete,
base::Unretained(this), loader.get(), url, isolation_info),
1024 * 1024 * 5 /* 5MB */);
IsolatedPrerenderMainframeBodyLengthLimit());
page_->url_loaders_.emplace(std::move(loader));
}
......
......@@ -811,6 +811,50 @@ TEST_F(IsolatedPrerenderTabHelperTest, NetErrorOKOnly) {
"IsolatedPrerender.Prefetch.Mainframe.TotalRedirects", 0, 1);
}
TEST_F(IsolatedPrerenderTabHelperTest, ResponseBodyLimit) {
base::HistogramTester histogram_tester;
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeatureWithParameters(
features::kIsolatePrerenders, {{"max_mainframe_body_length_kb", "0"}});
NavigateSomewhere();
GURL doc_url("https://www.google.com/search?q=cats");
GURL prediction_url("https://www.cat-food.com/");
MakeNavigationPrediction(web_contents(), doc_url, {prediction_url});
network::ResourceRequest request = VerifyCommonRequestState(prediction_url);
MakeResponseAndWait(net::HTTP_OK, net::OK, kHTMLMimeType, /*headers=*/{},
kHTMLBody);
EXPECT_EQ(predicted_urls_count(), 1U);
EXPECT_EQ(prefetch_eligible_count(), 1U);
EXPECT_EQ(prefetch_attempted_count(), 1U);
EXPECT_EQ(prefetch_successful_count(), 0U);
EXPECT_EQ(prefetch_total_redirect_count(), 0U);
EXPECT_TRUE(navigation_to_prefetch_start().has_value());
histogram_tester.ExpectUniqueSample(
"IsolatedPrerender.Prefetch.Mainframe.NetError",
std::abs(net::ERR_INSUFFICIENT_RESOURCES), 1);
histogram_tester.ExpectTotalCount(
"IsolatedPrerender.Prefetch.Mainframe.RespCode", 0);
histogram_tester.ExpectTotalCount(
"IsolatedPrerender.Prefetch.Mainframe.BodyLength", 0);
histogram_tester.ExpectTotalCount(
"IsolatedPrerender.Prefetch.Mainframe.TotalTime", 0);
histogram_tester.ExpectTotalCount(
"IsolatedPrerender.Prefetch.Mainframe.ConnectTime", 0);
NavigateAndVerifyPrefetchStatus(
prediction_url,
IsolatedPrerenderTabHelper::PrefetchStatus::kPrefetchFailedNetError);
EXPECT_EQ(after_srp_prefetch_eligible_count(), 1U);
EXPECT_EQ(base::Optional<size_t>(0), after_srp_clicked_link_srp_position());
histogram_tester.ExpectUniqueSample(
"IsolatedPrerender.Prefetch.Mainframe.TotalRedirects", 0, 1);
}
TEST_F(IsolatedPrerenderTabHelperTest, NonHTML) {
base::HistogramTester histogram_tester;
base::test::ScopedFeatureList scoped_feature_list;
......
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