Commit bc580c5c authored by Olivier Li's avatar Olivier Li Committed by Commit Bot

Make domain mixing metrics time lengths more explicit.

The test part of this change is necessary to support running HistoryBackend on
the ThreadPool.(Feature:HistoryServiceUsesTaskScheduler) On the ThreaPoool  we cannot
FastForwardUntilNoTasksRemain() for tasks using repeating timers.

Regardless of the new feature this change is intended to be a no-op and has
the added benefit of being more explicit in the time related expectations.

Bug: 661143
Change-Id: I1dcd2f3e2d1e5a5455953b0555c6475b2d0fdafd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1932417Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarCait Phillips <caitkp@chromium.org>
Auto-Submit: Oliver Li <olivierli@chromium.org>
Commit-Queue: Oliver Li <olivierli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719223}
parent 40bd5c22
......@@ -8,6 +8,7 @@
#include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_clock.h"
#include "base/timer/mock_timer.h"
#include "components/history/core/browser/domain_mixing_metrics.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/test/history_service_test_util.h"
......@@ -152,7 +153,11 @@ TEST_F(GoogleSearchDomainMixingMetricsEmitterTest, EmitsMetricsOnStart) {
emitter_->Start();
base::HistogramTester tester;
task_environment_.FastForwardUntilNoTasksRemain();
// Fast forward far enough that histograms have been written to for all
// intervals.
task_environment_.FastForwardBy(
base::TimeDelta::FromDays(history::kOneMonth));
BlockUntilHistoryProcessesPendingRequests(history_service_.get());
VerifyHistograms(tester);
}
......@@ -173,8 +178,10 @@ TEST_F(GoogleSearchDomainMixingMetricsEmitterTest, EmitsMetricsWhenTimerFires) {
// Start the emitter.
emitter_->Start();
// Wait for the first run to be done.
task_environment_.FastForwardUntilNoTasksRemain();
// Fast forward far enough that histograms have been written to for all
// intervals.
task_environment_.FastForwardBy(
base::TimeDelta::FromDays(history::kOneMonth));
BlockUntilHistoryProcessesPendingRequests(history_service_.get());
// last_metrics_time is expected to have been incremented.
......@@ -195,7 +202,10 @@ TEST_F(GoogleSearchDomainMixingMetricsEmitterTest, EmitsMetricsWhenTimerFires) {
timer_->Fire();
base::HistogramTester tester;
task_environment_.FastForwardUntilNoTasksRemain();
// Fast forward far enough that histograms have been written to for all
// intervals.
task_environment_.FastForwardBy(
base::TimeDelta::FromDays(history::kOneMonth));
BlockUntilHistoryProcessesPendingRequests(history_service_.get());
VerifyHistograms(tester);
......
......@@ -21,7 +21,7 @@ using DomainVisitsPerDay = base::flat_map<Day, DomainVisits>;
// The time intervals in days to compute domain mixing metrics for, sorted
// in ascending order.
std::vector<int> NumDaysForMetrics() {
return {1, 7, 14, 30};
return {kOneDay, kOneWeek, kTwoWeeks, kOneMonth};
}
// Maps a time to the start of a day using ref_start_of_day as the reference
......@@ -87,16 +87,16 @@ void EmitDomainMixingMetric(const DomainVisits& domain_visits, int num_days) {
double domain_mixing_ratio = ComputeDomainMixingRatio(domain_visits);
int percentage = gfx::ToRoundedInt(100 * domain_mixing_ratio);
switch (num_days) {
case 1:
case kOneDay:
UMA_HISTOGRAM_PERCENTAGE("DomainMixing.OneDay", percentage);
break;
case 7:
case kOneWeek:
UMA_HISTOGRAM_PERCENTAGE("DomainMixing.OneWeek", percentage);
break;
case 14:
case kTwoWeeks:
UMA_HISTOGRAM_PERCENTAGE("DomainMixing.TwoWeeks", percentage);
break;
case 30:
case kOneMonth:
UMA_HISTOGRAM_PERCENTAGE("DomainMixing.OneMonth", percentage);
break;
default:
......@@ -147,4 +147,4 @@ void EmitDomainMixingMetrics(const std::vector<DomainVisit>& domain_visits,
}
}
} // namespace history
\ No newline at end of file
} // namespace history
......@@ -13,6 +13,11 @@
namespace history {
constexpr int kOneDay = 1;
constexpr int kOneWeek = 7;
constexpr int kTwoWeeks = 14;
constexpr int kOneMonth = 30;
// Emits domain mixing metrics given a list of domain visits and the start of
// the first day to compute metrics for.
//
......@@ -32,4 +37,4 @@ void EmitDomainMixingMetrics(const std::vector<DomainVisit>& domain_visits,
} // namespace history
#endif
\ No newline at end of file
#endif // COMPONENTS_HISTORY_CORE_BROWSER_DOMAIN_MIXING_METRICS_H_
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