Commit 3ebb3282 authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

[Query Tiles]: Fix instant fetch not reset first flow mark.

If user turns on the instant-fetch flag after the first initial flow,
and turn off again after fetch is done, the code path was broken and
could never trigger the next normal flow.

Fix is mark the first flow completed when ever OnFetchCompeleted called.

Have unit test to cover this corner case.



Bug: 1087476
Change-Id: Id763b2ad328b9ca0be3ad6849f778aca182c989f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2259013
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Auto-Submit: Hesen Zhang <hesen@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781464}
parent 3723d4c1
......@@ -48,6 +48,8 @@ class TileServiceSchedulerImpl : public TileServiceScheduler {
}
void OnFetchCompleted(TileInfoRequestStatus status) override {
MarkFirstRunFinished();
if (IsInstantFetchMode())
return;
......@@ -59,7 +61,6 @@ class TileServiceSchedulerImpl : public TileServiceScheduler {
if (hours_past >= 0) {
stats::RecordFirstFetchFlowDuration(hours_past);
}
MarkFirstRunFinished();
}
if (status == TileInfoRequestStatus::kShouldSuspend) {
......
......@@ -230,5 +230,31 @@ TEST_F(TileServiceSchedulerTest, FirstKickoffNotOverride) {
EXPECT_EQ(prefs()->GetTime(kFirstScheduleTimeKey), base::Time());
}
TEST_F(TileServiceSchedulerTest, FirstRunFinishedAfterInstantFetchComplete) {
base::test::ScopedCommandLine scoped_command_line;
auto now = clock()->Now();
EXPECT_CALL(*native_scheduler(), Schedule(_)).Times(1);
tile_service_scheduler()->OnTileManagerInitialized(TileGroupStatus::kNoTiles);
EXPECT_EQ(prefs()->GetTime(kFirstScheduleTimeKey), now);
// Set instant-fetch flag to true after first-kickoff flow was marked and
// scheduled, expecting the mark of first flow also being reset.
scoped_command_line.GetProcessCommandLine()->AppendSwitchASCII(
query_tiles::switches::kQueryTilesInstantBackgroundTask, "true");
EXPECT_CALL(*native_scheduler(), Schedule(_)).Times(0);
tile_service_scheduler()->OnFetchCompleted(TileInfoRequestStatus::kSuccess);
EXPECT_EQ(prefs()->GetTime(kFirstScheduleTimeKey), base::Time());
// Set instant-fetch flag to false after 2 hours. Chrome restarts with no
// tiles, the scheduler should start a new first kickoff flow.
scoped_command_line.GetProcessCommandLine()->RemoveSwitch(
query_tiles::switches::kQueryTilesInstantBackgroundTask);
auto two_hours_later = now + base::TimeDelta::FromHours(2);
clock()->SetNow(two_hours_later);
EXPECT_CALL(*native_scheduler(), Schedule(_)).Times(1);
tile_service_scheduler()->OnTileManagerInitialized(TileGroupStatus::kNoTiles);
EXPECT_EQ(prefs()->GetTime(kFirstScheduleTimeKey), two_hours_later);
}
} // namespace
} // namespace query_tiles
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