Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Unified Diff: components/ntp_snippets/remote/remote_suggestions_scheduler_impl.cc

Issue 2810053004: [Remote suggestions] Report time distribution of triggers (Closed)
Patch Set: Ilya's comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/remote/remote_suggestions_scheduler_impl.cc
diff --git a/components/ntp_snippets/remote/remote_suggestions_scheduler_impl.cc b/components/ntp_snippets/remote/remote_suggestions_scheduler_impl.cc
index 699c3b5a246cbceafee6b7c8c5cd0355eb9bd183..25a1528195c3476f29ad3d27078b9a24b35ff6df 100644
--- a/components/ntp_snippets/remote/remote_suggestions_scheduler_impl.cc
+++ b/components/ntp_snippets/remote/remote_suggestions_scheduler_impl.cc
@@ -145,6 +145,96 @@ base::TimeDelta GetDesiredFetchingInterval(
return base::TimeDelta::FromSecondsD(value_hours * 3600.0);
}
+void ReportTimeUntilFirstSoftTrigger(UserClassifier::UserClass user_class,
+ base::TimeDelta time_until_first_trigger) {
+ switch (user_class) {
+ case UserClassifier::UserClass::RARE_NTP_USER:
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NewTabPage.ContentSuggestions.TimeUntilFirstSoftTrigger.RareNTPUser",
+ time_until_first_trigger, base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromDays(7),
+ /*bucket_count=*/50);
+ break;
+ case UserClassifier::UserClass::ACTIVE_NTP_USER:
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NewTabPage.ContentSuggestions.TimeUntilFirstSoftTrigger."
+ "ActiveNTPUser",
+ time_until_first_trigger, base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromDays(7),
+ /*bucket_count=*/50);
+ break;
+ case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER:
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NewTabPage.ContentSuggestions.TimeUntilFirstSoftTrigger."
+ "ActiveSuggestionsConsumer",
+ time_until_first_trigger, base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromDays(7),
+ /*bucket_count=*/50);
+ break;
+ }
+}
+
+void ReportTimeUntilSoftFetch(UserClassifier::UserClass user_class,
+ base::TimeDelta time_until_soft_fetch) {
+ switch (user_class) {
+ case UserClassifier::UserClass::RARE_NTP_USER:
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NewTabPage.ContentSuggestions.TimeUntilSoftFetch."
+ "RareNTPUser",
+ time_until_soft_fetch, base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromDays(7),
+ /*bucket_count=*/50);
+ break;
+ case UserClassifier::UserClass::ACTIVE_NTP_USER:
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NewTabPage.ContentSuggestions.TimeUntilSoftFetch."
+ "ActiveNTPUser",
+ time_until_soft_fetch, base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromDays(7),
+ /*bucket_count=*/50);
+ break;
+ case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER:
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NewTabPage.ContentSuggestions.TimeUntilSoftFetch."
+ "ActiveSuggestionsConsumer",
+ time_until_soft_fetch, base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromDays(7),
+ /*bucket_count=*/50);
+ break;
+ }
+}
+
+void ReportTimeUntilPersistentFetch(
+ UserClassifier::UserClass user_class,
+ base::TimeDelta time_until_persistent_fetch) {
+ switch (user_class) {
+ case UserClassifier::UserClass::RARE_NTP_USER:
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NewTabPage.ContentSuggestions.TimeUntilPersistentFetch."
+ "RareNTPUser",
+ time_until_persistent_fetch, base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromDays(7),
+ /*bucket_count=*/50);
+ break;
+ case UserClassifier::UserClass::ACTIVE_NTP_USER:
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NewTabPage.ContentSuggestions.TimeUntilPersistentFetch."
+ "ActiveNTPUser",
+ time_until_persistent_fetch, base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromDays(7),
+ /*bucket_count=*/50);
+ break;
+ case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER:
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NewTabPage.ContentSuggestions.TimeUntilPersistentFetch."
+ "ActiveSuggestionsConsumer",
+ time_until_persistent_fetch, base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromDays(7),
+ /*bucket_count=*/50);
+ break;
+ }
+}
+
} // namespace
class EulaState : public web_resource::EulaAcceptedNotifier::Observer {
@@ -246,6 +336,7 @@ RemoteSuggestionsSchedulerImpl::RemoteSuggestionsSchedulerImpl(
profile_prefs,
RequestThrottler::RequestType::
CONTENT_SUGGESTION_FETCHER_ACTIVE_SUGGESTIONS_CONSUMER),
+ time_until_first_trigger_reported_(false),
eula_state_(base::MakeUnique<EulaState>(local_state_prefs, this)),
profile_prefs_(profile_prefs),
clock_(std::move(clock)),
@@ -438,8 +529,17 @@ void RemoteSuggestionsSchedulerImpl::RefetchInTheBackgroundIfAppropriate(
return;
}
- if (trigger != TriggerType::PERSISTENT_SCHEDULER_WAKE_UP &&
- !ShouldRefetchInTheBackgroundNow()) {
+ bool is_soft = trigger != TriggerType::PERSISTENT_SCHEDULER_WAKE_UP;
+ const base::Time last_fetch_attempt_time = base::Time::FromInternalValue(
+ profile_prefs_->GetInt64(prefs::kSnippetLastFetchAttempt));
+
+ if (is_soft && !time_until_first_trigger_reported_) {
+ time_until_first_trigger_reported_ = true;
+ ReportTimeUntilFirstSoftTrigger(user_classifier_->GetUserClass(),
+ clock_->Now() - last_fetch_attempt_time);
+ }
+
+ if (is_soft && !ShouldRefetchInTheBackgroundNow(last_fetch_attempt_time)) {
return;
}
@@ -447,6 +547,14 @@ void RemoteSuggestionsSchedulerImpl::RefetchInTheBackgroundIfAppropriate(
return;
}
+ if (is_soft) {
+ ReportTimeUntilSoftFetch(user_classifier_->GetUserClass(),
+ clock_->Now() - last_fetch_attempt_time);
+ } else {
+ ReportTimeUntilPersistentFetch(user_classifier_->GetUserClass(),
+ clock_->Now() - last_fetch_attempt_time);
+ }
+
UMA_HISTOGRAM_ENUMERATION(
"NewTabPage.ContentSuggestions.BackgroundFetchTrigger",
static_cast<int>(trigger), static_cast<int>(TriggerType::COUNT));
@@ -457,10 +565,8 @@ void RemoteSuggestionsSchedulerImpl::RefetchInTheBackgroundIfAppropriate(
base::Unretained(this)));
}
-bool RemoteSuggestionsSchedulerImpl::ShouldRefetchInTheBackgroundNow() {
- const base::Time last_fetch_attempt_time = base::Time::FromInternalValue(
- profile_prefs_->GetInt64(prefs::kSnippetLastFetchAttempt));
-
+bool RemoteSuggestionsSchedulerImpl::ShouldRefetchInTheBackgroundNow(
+ base::Time last_fetch_attempt_time) {
// If we have no persistent scheduler to ask, err on the side of caution.
bool wifi = false;
if (persistent_scheduler_) {
@@ -521,6 +627,7 @@ void RemoteSuggestionsSchedulerImpl::RefetchInTheBackgroundFinished(
void RemoteSuggestionsSchedulerImpl::OnFetchCompleted(Status fetch_status) {
profile_prefs_->SetInt64(prefs::kSnippetLastFetchAttempt,
clock_->Now().ToInternalValue());
+ time_until_first_trigger_reported_ = false;
// Reschedule after a fetch. The persistent schedule is applied only after a
// successful fetch. After a failed fetch, we want to keep the previous
« no previous file with comments | « components/ntp_snippets/remote/remote_suggestions_scheduler_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698