Commit 95c40cef authored by Sophie Chang's avatar Sophie Chang Committed by Commit Bot

Make sure to check if we have a hint in the cache before racing navigation

I left the SRP check there since that contains more hosts and doing the
HasHint check for every host is probably not worth it.

Bug: 1022624
Change-Id: I1b4c782df2c9fb76e08e09d3674178420a5a3728
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904822Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713714}
parent 298984c0
...@@ -935,7 +935,8 @@ void OptimizationGuideHintsManager::OnNavigationStartOrRedirect( ...@@ -935,7 +935,8 @@ void OptimizationGuideHintsManager::OnNavigationStartOrRedirect(
return; return;
} }
if (IsAllowedToFetchNavigationHints(navigation_handle->GetURL())) { if (IsAllowedToFetchNavigationHints(navigation_handle->GetURL()) &&
!hint_cache_->HasHint(navigation_handle->GetURL().host())) {
std::vector<std::string> hosts{navigation_handle->GetURL().host()}; std::vector<std::string> hosts{navigation_handle->GetURL().host()};
navigation_hosts_last_fetched_real_time_.clear(); navigation_hosts_last_fetched_real_time_.clear();
navigation_hosts_last_fetched_real_time_.push_back( navigation_hosts_last_fetched_real_time_.push_back(
......
...@@ -1941,6 +1941,30 @@ TEST_F(OptimizationGuideHintsManagerTest, ...@@ -1941,6 +1941,30 @@ TEST_F(OptimizationGuideHintsManagerTest,
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1, 1); "OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 1, 1);
} }
TEST_F(OptimizationGuideHintsManagerTest,
HintsFetchedAtNavigationTime_HasComponentHintButNotFetched) {
hints_manager()->RegisterOptimizationTypes(
{optimization_guide::proto::DEFER_ALL_SCRIPT});
base::test::ScopedFeatureList scoped_list;
scoped_list.InitAndEnableFeature(
optimization_guide::features::kOptimizationHintsFetching);
InitializeWithDefaultConfig("1.0.0.0");
// Set ECT estimate so hint is activated.
hints_manager()->OnEffectiveConnectionTypeChanged(
net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
std::unique_ptr<content::MockNavigationHandle> navigation_handle =
CreateMockNavigationHandleWithOptimizationGuideWebContentsObserver(
url_with_hints());
base::RunLoop run_loop;
base::HistogramTester histogram_tester;
hints_manager()->OnNavigationStartOrRedirect(navigation_handle.get(),
run_loop.QuitClosure());
run_loop.Run();
histogram_tester.ExpectTotalCount(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 0);
}
TEST_F(OptimizationGuideHintsManagerTest, TEST_F(OptimizationGuideHintsManagerTest,
HintsNotFetchedAtNavigationTime_ECT_4G) { HintsNotFetchedAtNavigationTime_ECT_4G) {
hints_manager()->RegisterOptimizationTypes( hints_manager()->RegisterOptimizationTypes(
......
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