Commit 12970ea5 authored by Dmitry Titov's avatar Dmitry Titov Committed by Commit Bot

Fix the reporting timeout for ExploreSites.MonthlyHostCount.

Writing timestamp before the actual reporting may actually result in skipping the reporting and waiting another week before the next opportunity. Move the timestamp writing to the after the reporting was actually done.

Bug: 939213
Change-Id: I540d1780ed95c361959732655796270e95787dc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1507393Reviewed-by: default avatarJustin DeWitt <dewittj@chromium.org>
Commit-Queue: Dmitry Titov <dimich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638704}
parent 75fdde1a
......@@ -56,7 +56,6 @@ void HistoryStatisticsReporter::ScheduleReportStatistics() {
base::Time last_report_time = prefs_->GetTime(kWeeklyStatsReportingTimestamp);
if (last_report_time > clock_->Now() - base::TimeDelta::FromDays(7))
return;
prefs_->SetTime(kWeeklyStatsReportingTimestamp, clock_->Now());
base::TimeDelta computeStatisticsDelay =
base::TimeDelta::FromSeconds(kComputeStatisticsDelaySeconds);
......@@ -103,5 +102,7 @@ void HistoryStatisticsReporter::ReportStatistics(
if (!result.success)
return;
UMA_HISTOGRAM_COUNTS_1000("ExploreSites.MonthlyHostCount", result.count);
// Remember when stats were reported to skip attempts until next week.
prefs_->SetTime(kWeeklyStatsReportingTimestamp, clock_->Now());
}
} // namespace explore_sites
......@@ -192,8 +192,6 @@ TEST_F(HistoryStatisticsReporterTest, OneRunPerSession) {
}
TEST_F(HistoryStatisticsReporterTest, OneRunPerWeekSaveTimestamp) {
base::Time time_now = task_runner()->GetMockClock()->Now();
ASSERT_TRUE(LoadHistory());
ScheduleReportAndRunUntilIdle();
......@@ -202,6 +200,7 @@ TEST_F(HistoryStatisticsReporterTest, OneRunPerWeekSaveTimestamp) {
histograms().ExpectTotalCount("History.DatabaseMonthlyHostCountTime", 1);
// Reporter should have left the time of request in Prefs.
base::Time time_now = task_runner()->GetMockClock()->Now();
EXPECT_EQ(time_now, prefs()->GetTime(kWeeklyStatsReportingTimestamp));
}
......@@ -217,8 +216,6 @@ TEST_F(HistoryStatisticsReporterTest, OneRunPerWeekReadTimestamp) {
}
TEST_F(HistoryStatisticsReporterTest, OneRunPerWeekReadTimestampAfterWeek) {
base::Time time_now = task_runner()->GetMockClock()->Now();
ASSERT_TRUE(LoadHistory());
prefs()->SetTime(
......@@ -229,6 +226,7 @@ TEST_F(HistoryStatisticsReporterTest, OneRunPerWeekReadTimestampAfterWeek) {
// More than a week since last query, should have gone through.
histograms().ExpectTotalCount("History.DatabaseMonthlyHostCountTime", 1);
// Reporter should have left the time of request in Prefs.
base::Time time_now = task_runner()->GetMockClock()->Now();
EXPECT_EQ(time_now, prefs()->GetTime(kWeeklyStatsReportingTimestamp));
}
......
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