Commit 323a3571 authored by Sophie Chang's avatar Sophie Chang Committed by Commit Bot

Move hints fetching to after component has arrived in OGKS

This is pretty much guaranteed for DataSaver users to always happen
and this reduces the likelihood of the race condition between data
updates being in flight

Bug: 997106
Change-Id: If2d827e9dc74e93dc8d203a6f7aa27cd590d617f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1768819Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689997}
parent 04206cd3
...@@ -300,8 +300,6 @@ void OptimizationGuideHintsManager::OnHintCacheInitialized() { ...@@ -300,8 +300,6 @@ void OptimizationGuideHintsManager::OnHintCacheInitialized() {
UpdateComponentHints(base::DoNothing(), std::move(hint_update_data)); UpdateComponentHints(base::DoNothing(), std::move(hint_update_data));
} }
MaybeScheduleHintsFetch();
// Register as an observer regardless of hint proto override usage. This is // Register as an observer regardless of hint proto override usage. This is
// needed as a signal during testing. // needed as a signal during testing.
optimization_guide_service_->AddObserver(this); optimization_guide_service_->AddObserver(this);
...@@ -330,7 +328,7 @@ void OptimizationGuideHintsManager::UpdateComponentHints( ...@@ -330,7 +328,7 @@ void OptimizationGuideHintsManager::UpdateComponentHints(
void OptimizationGuideHintsManager::OnComponentHintsUpdated( void OptimizationGuideHintsManager::OnComponentHintsUpdated(
base::OnceClosure update_closure, base::OnceClosure update_closure,
bool hints_updated) const { bool hints_updated) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Record the result of updating the hints. This is used as a signal for the // Record the result of updating the hints. This is used as a signal for the
...@@ -339,6 +337,8 @@ void OptimizationGuideHintsManager::OnComponentHintsUpdated( ...@@ -339,6 +337,8 @@ void OptimizationGuideHintsManager::OnComponentHintsUpdated(
optimization_guide::kComponentHintsUpdatedResultHistogramString, optimization_guide::kComponentHintsUpdatedResultHistogramString,
hints_updated); hints_updated);
MaybeScheduleHintsFetch();
MaybeRunUpdateClosure(std::move(update_closure)); MaybeRunUpdateClosure(std::move(update_closure));
} }
......
...@@ -162,7 +162,7 @@ class OptimizationGuideHintsManager ...@@ -162,7 +162,7 @@ class OptimizationGuideHintsManager
// Called when the hints have been fully updated with the latest hints from // Called when the hints have been fully updated with the latest hints from
// the Component Updater. This is used as a signal during tests. // the Component Updater. This is used as a signal during tests.
void OnComponentHintsUpdated(base::OnceClosure update_closure, void OnComponentHintsUpdated(base::OnceClosure update_closure,
bool hints_updated) const; bool hints_updated);
// Method to decide whether to fetch new hints for user's top sites and // Method to decide whether to fetch new hints for user's top sites and
// proceeds to schedule the fetch. // proceeds to schedule the fetch.
......
...@@ -844,6 +844,7 @@ TEST_F(OptimizationGuideHintsManagerTest, ...@@ -844,6 +844,7 @@ TEST_F(OptimizationGuideHintsManagerTest,
CreateServiceAndHintsManager(/*top_host_provider=*/nullptr); CreateServiceAndHintsManager(/*top_host_provider=*/nullptr);
hints_manager()->SetHintsFetcherForTesting( hints_manager()->SetHintsFetcherForTesting(
BuildTestHintsFetcher(HintsFetcherEndState::kFetchSuccessWithHints)); BuildTestHintsFetcher(HintsFetcherEndState::kFetchSuccessWithHints));
InitializeWithDefaultConfig("1.0.0");
// Force timer to expire and schedule a hints fetch. // Force timer to expire and schedule a hints fetch.
MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs)); MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs));
...@@ -861,6 +862,7 @@ TEST_F(OptimizationGuideHintsManagerTest, ...@@ -861,6 +862,7 @@ TEST_F(OptimizationGuideHintsManagerTest,
EXPECT_CALL(*top_host_provider, GetTopHosts(testing::_)).Times(0); EXPECT_CALL(*top_host_provider, GetTopHosts(testing::_)).Times(0);
CreateServiceAndHintsManager(top_host_provider.get()); CreateServiceAndHintsManager(top_host_provider.get());
InitializeWithDefaultConfig("1.0.0");
} }
TEST_F(OptimizationGuideHintsManagerTest, TEST_F(OptimizationGuideHintsManagerTest,
...@@ -879,6 +881,7 @@ TEST_F(OptimizationGuideHintsManagerTest, ...@@ -879,6 +881,7 @@ TEST_F(OptimizationGuideHintsManagerTest,
CreateServiceAndHintsManager(top_host_provider.get()); CreateServiceAndHintsManager(top_host_provider.get());
hints_manager()->SetHintsFetcherForTesting( hints_manager()->SetHintsFetcherForTesting(
BuildTestHintsFetcher(HintsFetcherEndState::kFetchSuccessWithHints)); BuildTestHintsFetcher(HintsFetcherEndState::kFetchSuccessWithHints));
InitializeWithDefaultConfig("1.0.0");
// Force timer to expire and schedule a hints fetch. // Force timer to expire and schedule a hints fetch.
MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs)); MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs));
...@@ -896,6 +899,7 @@ TEST_F(OptimizationGuideHintsManagerTest, HintsFetcherEnabledNoHostsToFetch) { ...@@ -896,6 +899,7 @@ TEST_F(OptimizationGuideHintsManagerTest, HintsFetcherEnabledNoHostsToFetch) {
CreateServiceAndHintsManager(top_host_provider.get()); CreateServiceAndHintsManager(top_host_provider.get());
hints_manager()->SetHintsFetcherForTesting( hints_manager()->SetHintsFetcherForTesting(
BuildTestHintsFetcher(HintsFetcherEndState::kFetchSuccessWithHints)); BuildTestHintsFetcher(HintsFetcherEndState::kFetchSuccessWithHints));
InitializeWithDefaultConfig("1.0.0");
// Force timer to expire and schedule a hints fetch. // Force timer to expire and schedule a hints fetch.
MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs)); MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs));
...@@ -919,6 +923,7 @@ TEST_F(OptimizationGuideHintsManagerTest, ...@@ -919,6 +923,7 @@ TEST_F(OptimizationGuideHintsManagerTest,
CreateServiceAndHintsManager(top_host_provider.get()); CreateServiceAndHintsManager(top_host_provider.get());
hints_manager()->SetHintsFetcherForTesting( hints_manager()->SetHintsFetcherForTesting(
BuildTestHintsFetcher(HintsFetcherEndState::kFetchSuccessWithNoHints)); BuildTestHintsFetcher(HintsFetcherEndState::kFetchSuccessWithNoHints));
InitializeWithDefaultConfig("1.0.0");
// Force timer to expire and schedule a hints fetch. // Force timer to expire and schedule a hints fetch.
MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs)); MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs));
...@@ -947,6 +952,7 @@ TEST_F(OptimizationGuideHintsManagerTest, HintsFetcherTimerRetryDelay) { ...@@ -947,6 +952,7 @@ TEST_F(OptimizationGuideHintsManagerTest, HintsFetcherTimerRetryDelay) {
CreateServiceAndHintsManager(top_host_provider.get()); CreateServiceAndHintsManager(top_host_provider.get());
hints_manager()->SetHintsFetcherForTesting( hints_manager()->SetHintsFetcherForTesting(
BuildTestHintsFetcher(HintsFetcherEndState::kFetchFailed)); BuildTestHintsFetcher(HintsFetcherEndState::kFetchFailed));
InitializeWithDefaultConfig("1.0.0");
// Force timer to expire and schedule a hints fetch - first time. // Force timer to expire and schedule a hints fetch - first time.
MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs)); MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs));
...@@ -975,6 +981,7 @@ TEST_F(OptimizationGuideHintsManagerTest, HintsFetcherTimerFetchSucceeds) { ...@@ -975,6 +981,7 @@ TEST_F(OptimizationGuideHintsManagerTest, HintsFetcherTimerFetchSucceeds) {
CreateServiceAndHintsManager(top_host_provider.get()); CreateServiceAndHintsManager(top_host_provider.get());
hints_manager()->SetHintsFetcherForTesting( hints_manager()->SetHintsFetcherForTesting(
BuildTestHintsFetcher(HintsFetcherEndState::kFetchSuccessWithHints)); BuildTestHintsFetcher(HintsFetcherEndState::kFetchSuccessWithHints));
InitializeWithDefaultConfig("1.0.0");
// Force timer to expire and schedule a hints fetch that succeeds. // Force timer to expire and schedule a hints fetch that succeeds.
MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs)); MoveClockForwardBy(base::TimeDelta::FromSeconds(kTestFetchRetryDelaySecs));
......
...@@ -499,6 +499,12 @@ class OptimizationGuideKeyedServiceHintsFetcherTest ...@@ -499,6 +499,12 @@ class OptimizationGuideKeyedServiceHintsFetcherTest
OptimizationGuideKeyedServiceCommandLineOverridesTest::SetUpCommandLine( OptimizationGuideKeyedServiceCommandLineOverridesTest::SetUpCommandLine(
cmd); cmd);
// Remove DataSaver switch in case it was added before. This ensures that
// the other implementation does not also run the hints fetch at the same
// time since we have not yet isolated the paths using the
// OptimizationGuideKeyedService feature yet.
cmd->RemoveSwitch("enable-spdy-proxy-auth");
cmd->AppendSwitch(optimization_guide::switches::kFetchHintsOverrideTimer); cmd->AppendSwitch(optimization_guide::switches::kFetchHintsOverrideTimer);
cmd->AppendSwitchASCII( cmd->AppendSwitchASCII(
optimization_guide::switches::kOptimizationGuideServiceURL, optimization_guide::switches::kOptimizationGuideServiceURL,
...@@ -509,7 +515,9 @@ class OptimizationGuideKeyedServiceHintsFetcherTest ...@@ -509,7 +515,9 @@ class OptimizationGuideKeyedServiceHintsFetcherTest
OptimizationGuideKeyedServiceCommandLineOverridesTest::SetUpOnMainThread(); OptimizationGuideKeyedServiceCommandLineOverridesTest::SetUpOnMainThread();
api_server_->StartAcceptingConnections(); api_server_->StartAcceptingConnections();
}
void WaitForHintsFetchToComplete() {
// Expect that the browser initialization will record at least one sample // Expect that the browser initialization will record at least one sample
// in each of the follow histograms as OnePlatform Hints are enabled. // in each of the follow histograms as OnePlatform Hints are enabled.
EXPECT_EQ( EXPECT_EQ(
...@@ -519,7 +527,7 @@ class OptimizationGuideKeyedServiceHintsFetcherTest ...@@ -519,7 +527,7 @@ class OptimizationGuideKeyedServiceHintsFetcherTest
1); 1);
// There should be 2 sites passed via command line. // There should be 2 sites passed via command line.
histogram_tester_.ExpectBucketCount( histogram_tester_.ExpectUniqueSample(
"OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 2, 1); "OptimizationGuide.HintsFetcher.GetHintsRequest.HostCount", 2, 1);
EXPECT_EQ(RetryForHistogramUntilCountReached( EXPECT_EQ(RetryForHistogramUntilCountReached(
...@@ -593,10 +601,16 @@ class OptimizationGuideKeyedServiceHintsFetcherTest ...@@ -593,10 +601,16 @@ class OptimizationGuideKeyedServiceHintsFetcherTest
}; };
// TODO(crbug/969558): Figure out why hints fetcher not fetching on ChromeOS. // TODO(crbug/969558): Figure out why hints fetcher not fetching on ChromeOS.
// TODO(crbug/997106): Flaky on Win, Mac and Linux. #if defined(OS_CHROMEOS)
#define DISABLE_ON_CHROMEOS(x) DISABLED_##x
#else
#define DISABLE_ON_CHROMEOS(x) x
#endif
IN_PROC_BROWSER_TEST_F(OptimizationGuideKeyedServiceHintsFetcherTest, IN_PROC_BROWSER_TEST_F(OptimizationGuideKeyedServiceHintsFetcherTest,
DISABLED_ClearFetchedHints) { DISABLE_ON_CHROMEOS(ClearFetchedHints)) {
PushHintsComponentAndWaitForCompletion(); PushHintsComponentAndWaitForCompletion();
WaitForHintsFetchToComplete();
RegisterWithKeyedService(); RegisterWithKeyedService();
......
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