Commit 4bb4b0ae authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

Isolated Prerender should not use cached subresources on a bad probe

If the origin probe fails, then no subresources should be loaded from
the isolated cache.

Bug: 1082505
Change-Id: I8f3411ad9e0fcbc2376cf43317fe8a6cfb125b32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261411Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782062}
parent 1a0facfa
...@@ -617,7 +617,7 @@ class IsolatedPrerenderBrowserTest ...@@ -617,7 +617,7 @@ class IsolatedPrerenderBrowserTest
// will request the HTML file, i.e.: "/simple.html". // will request the HTML file, i.e.: "/simple.html".
if (request.headers.find("Host")->second.find("badprobe.a.test") != if (request.headers.find("Host")->second.find("badprobe.a.test") !=
std::string::npos && std::string::npos &&
request.relative_url == "/") { request.GetURL().path() == "/") {
// This is an invalid response to the net stack and will cause a NetError. // This is an invalid response to the net stack and will cause a NetError.
return std::make_unique<net::test_server::RawHttpResponse>("", ""); return std::make_unique<net::test_server::RawHttpResponse>("", "");
} }
...@@ -2583,9 +2583,28 @@ IN_PROC_BROWSER_TEST_F(ProbingAndNSPEnabledIsolatedPrerenderBrowserTest, ...@@ -2583,9 +2583,28 @@ IN_PROC_BROWSER_TEST_F(ProbingAndNSPEnabledIsolatedPrerenderBrowserTest,
// This run loop will quit when a NSP finishes. // This run loop will quit when a NSP finishes.
nsp_run_loop.Run(); nsp_run_loop.Run();
std::vector<net::test_server::HttpRequest> origin_requests_after_prerender =
origin_server_requests();
std::vector<net::test_server::HttpRequest> proxy_requests_after_prerender =
proxy_server_requests();
// Navigate to the predicted site. // Navigate to the predicted site.
ui_test_utils::NavigateToURL(browser(), eligible_link_bad_probe); ui_test_utils::NavigateToURL(browser(), eligible_link_bad_probe);
std::vector<net::test_server::HttpRequest> origin_requests_after_click =
origin_server_requests();
std::vector<net::test_server::HttpRequest> proxy_requests_after_click =
proxy_server_requests();
// All the resources should be loaded from the server since nothing was
// eligible to be reused from the prefetch on a bad probe.
EXPECT_EQ(origin_requests_after_prerender.size() + 7,
origin_requests_after_click.size());
// The proxy should not be used any further.
EXPECT_EQ(proxy_requests_after_prerender.size(),
proxy_requests_after_click.size());
// Navigate again to trigger UKM recording. // Navigate again to trigger UKM recording.
ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
......
...@@ -158,6 +158,10 @@ void IsolatedPrerenderSubresourceManager::OnSubresourceLoadSuccessful( ...@@ -158,6 +158,10 @@ void IsolatedPrerenderSubresourceManager::OnSubresourceLoadSuccessful(
successfully_loaded_subresources_.emplace(url); successfully_loaded_subresources_.emplace(url);
} }
void IsolatedPrerenderSubresourceManager::NotifyProbeFailed() {
successfully_loaded_subresources_.clear();
}
void IsolatedPrerenderSubresourceManager::RemoveProxiedURLLoaderFactory( void IsolatedPrerenderSubresourceManager::RemoveProxiedURLLoaderFactory(
IsolatedPrerenderProxyingURLLoaderFactory* factory) { IsolatedPrerenderProxyingURLLoaderFactory* factory) {
auto it = proxied_loader_factories_.find(factory); auto it = proxied_loader_factories_.find(factory);
......
...@@ -83,6 +83,10 @@ class IsolatedPrerenderSubresourceManager ...@@ -83,6 +83,10 @@ class IsolatedPrerenderSubresourceManager
// prefetched subresources should be loaded from cache. // prefetched subresources should be loaded from cache.
void NotifyPageNavigatedToAfterSRP(); void NotifyPageNavigatedToAfterSRP();
// Informs |this| that the origin probe to this' |url_| failed and no
// prefetched subresources should be loaded from cache.
void NotifyProbeFailed();
// prerender::PrerenderHandle::Observer: // prerender::PrerenderHandle::Observer:
void OnPrerenderStart(prerender::PrerenderHandle* handle) override {} void OnPrerenderStart(prerender::PrerenderHandle* handle) override {}
void OnPrerenderStopLoading(prerender::PrerenderHandle* handle) override {} void OnPrerenderStopLoading(prerender::PrerenderHandle* handle) override {}
......
...@@ -56,6 +56,25 @@ void RecordCookieWaitTime(base::TimeDelta wait_time) { ...@@ -56,6 +56,25 @@ void RecordCookieWaitTime(base::TimeDelta wait_time) {
base::TimeDelta(), base::TimeDelta::FromSeconds(5), 50); base::TimeDelta(), base::TimeDelta::FromSeconds(5), 50);
} }
void NotifySubresourceManagerOfBadProbe(int frame_tree_node_id,
const GURL& url) {
Profile* profile = ProfileFromFrameTreeNodeID(frame_tree_node_id);
if (!profile)
return;
IsolatedPrerenderService* service =
IsolatedPrerenderServiceFactory::GetForProfile(profile);
if (!service)
return;
IsolatedPrerenderSubresourceManager* subresource_manager =
service->GetSubresourceManagerForURL(url);
if (!subresource_manager)
return;
subresource_manager->NotifyProbeFailed();
}
} // namespace } // namespace
IsolatedPrerenderURLLoaderInterceptor::IsolatedPrerenderURLLoaderInterceptor( IsolatedPrerenderURLLoaderInterceptor::IsolatedPrerenderURLLoaderInterceptor(
...@@ -203,6 +222,10 @@ void IsolatedPrerenderURLLoaderInterceptor::OnProbeComplete( ...@@ -203,6 +222,10 @@ void IsolatedPrerenderURLLoaderInterceptor::OnProbeComplete(
return; return;
} }
// Notify the SubresourceManager for this url so that subresources should not
// be loaded from the prefetch cache.
NotifySubresourceManagerOfBadProbe(frame_tree_node_id_, url_);
NotifyPrefetchStatusUpdate( NotifyPrefetchStatusUpdate(
IsolatedPrerenderTabHelper::PrefetchStatus::kPrefetchNotUsedProbeFailed); IsolatedPrerenderTabHelper::PrefetchStatus::kPrefetchNotUsedProbeFailed);
DoNotInterceptNavigation(); DoNotInterceptNavigation();
......
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