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

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

Issue 2875953003: [Soft fetches] Set-up different intervals for <Chrome started> events. (Closed)
Patch Set: Created 3 years, 7 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 4b5a0e10b420a73bc834ea12d68efcf182a5c50e..c951e449b1aaed5d5b710028a165d68cc7c665ed 100644
--- a/components/ntp_snippets/remote/remote_suggestions_scheduler_impl.cc
+++ b/components/ntp_snippets/remote/remote_suggestions_scheduler_impl.cc
@@ -33,11 +33,15 @@ namespace {
// for each interval. Initially all the timers are started at the same time.
// Fetches are only performed when conditions associated with the intervals are
// met:
-// - A "soft" fetch is performed only at a moment when the user actively uses
-// Chrome after the interval has elapsed and causes a trigger that is currently
-// enabled while
+// - A "startup" fetch is performed only at a moment when the user starts /
markusheintz_ 2017/05/15 09:35:47 Can we mention the FetchInterval names from below
jkrcal 2017/05/15 11:40:24 Rephrased (I do not want to mention all cases I wa
+// switches to Chrome after the interval has elapsed (the triggers
+// BROWSER_FOREGROUNDED / BROWSER_COLD_START must be enabled);
markusheintz_ 2017/05/15 09:35:47 I don't understand the part about the triggers. Co
jkrcal 2017/05/15 11:40:24 Not needed here, removed.
+// - A "shown" fetch is performed only at a moment when the suggestions
+// surface is shown after the interval has elapsed (the trigger NTP_OPENED
+// must be enabled);
// - a "persistent" fetch is initiated automatically by the OS after the
-// interval elapses.
+// interval elapses.
+// Furthermore we distinguish:
// - A "wifi" fetch is performed only when the user is on a connection that
// the OS classifies as unmetered while
// - a "fallback" fetch happens on any connection.
@@ -46,8 +50,10 @@ namespace {
enum class FetchingInterval {
PERSISTENT_FALLBACK,
PERSISTENT_WIFI,
- SOFT_FALLBACK,
- SOFT_WIFI,
+ STARTUP_FALLBACK,
+ STARTUP_WIFI,
+ SHOWN_FALLBACK,
+ SHOWN_WIFI,
COUNT
};
@@ -57,28 +63,36 @@ enum class FetchingInterval {
// The values of each array specify a default time interval for the intervals
// defined by the enum FetchingInterval. The default time intervals defined in
// the arrays can be overridden using different variation parameters.
-const double kDefaultFetchingIntervalHoursRareNtpUser[] = {48.0, 24.0, 8.0,
- 4.0};
-const double kDefaultFetchingIntervalHoursActiveNtpUser[] = {24.0, 8.0, 6.0,
- 3.0};
+const double kDefaultFetchingIntervalHoursRareNtpUser[] = {48.0, 24.0, 48.0,
+ 24.0, 8.0, 4.0};
markusheintz_ 2017/05/15 09:35:47 nit: remove one space before "4.0"
jkrcal 2017/05/15 11:40:24 Done.
+const double kDefaultFetchingIntervalHoursActiveNtpUser[] = {24.0, 8.0, 24.0,
+ 8.0, 6.0, 3.0};
const double kDefaultFetchingIntervalHoursActiveSuggestionsConsumer[] = {
- 24.0, 6.0, 2.0, 1.0};
+ 24.0, 6.0, 24.0, 6.0, 2.0, 1.0};
// Variation parameters than can be used to override the default fetching
-// intervals.
+// intervals. For backwards compatibility, we do not rename
+// - the "fetching_" params (should be "persistent_fetching_");
+// - the "soft_" params (should be "shown_").
const char* kFetchingIntervalParamNameRareNtpUser[] = {
"fetching_interval_hours-fallback-rare_ntp_user",
"fetching_interval_hours-wifi-rare_ntp_user",
+ "startup_fetching_interval_hours-fallback-rare_ntp_user",
+ "startup_fetching_interval_hours-wifi-rare_ntp_user",
"soft_fetching_interval_hours-fallback-rare_ntp_user",
"soft_fetching_interval_hours-wifi-rare_ntp_user"};
const char* kFetchingIntervalParamNameActiveNtpUser[] = {
"fetching_interval_hours-fallback-active_ntp_user",
"fetching_interval_hours-wifi-active_ntp_user",
+ "startup_fetching_interval_hours-fallback-active_ntp_user",
+ "startup_fetching_interval_hours-wifi-active_ntp_user",
"soft_fetching_interval_hours-fallback-active_ntp_user",
"soft_fetching_interval_hours-wifi-active_ntp_user"};
const char* kFetchingIntervalParamNameActiveSuggestionsConsumer[] = {
"fetching_interval_hours-fallback-active_suggestions_consumer",
"fetching_interval_hours-wifi-active_suggestions_consumer",
+ "startup_fetching_interval_hours-fallback-active_suggestions_consumer",
+ "startup_fetching_interval_hours-wifi-active_suggestions_consumer",
"soft_fetching_interval_hours-fallback-active_suggestions_consumer",
"soft_fetching_interval_hours-wifi-active_suggestions_consumer"};
@@ -174,14 +188,14 @@ void ReportTimeUntilFirstSoftTrigger(UserClassifier::UserClass user_class,
}
}
-void ReportTimeUntilSoftFetch(UserClassifier::UserClass user_class,
- base::TimeDelta time_until_soft_fetch) {
+void ReportTimeUntilShownFetch(UserClassifier::UserClass user_class,
+ base::TimeDelta time_until_shown_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),
+ time_until_shown_fetch, base::TimeDelta::FromSeconds(1),
base::TimeDelta::FromDays(7),
/*bucket_count=*/50);
break;
@@ -189,7 +203,7 @@ void ReportTimeUntilSoftFetch(UserClassifier::UserClass user_class,
UMA_HISTOGRAM_CUSTOM_TIMES(
"NewTabPage.ContentSuggestions.TimeUntilSoftFetch."
"ActiveNTPUser",
- time_until_soft_fetch, base::TimeDelta::FromSeconds(1),
+ time_until_shown_fetch, base::TimeDelta::FromSeconds(1),
base::TimeDelta::FromDays(7),
/*bucket_count=*/50);
break;
@@ -197,7 +211,37 @@ void ReportTimeUntilSoftFetch(UserClassifier::UserClass user_class,
UMA_HISTOGRAM_CUSTOM_TIMES(
"NewTabPage.ContentSuggestions.TimeUntilSoftFetch."
"ActiveSuggestionsConsumer",
- time_until_soft_fetch, base::TimeDelta::FromSeconds(1),
+ time_until_shown_fetch, base::TimeDelta::FromSeconds(1),
+ base::TimeDelta::FromDays(7),
+ /*bucket_count=*/50);
+ break;
+ }
+}
+
+void ReportTimeUntilStartupFetch(UserClassifier::UserClass user_class,
+ base::TimeDelta time_until_startup_fetch) {
+ switch (user_class) {
+ case UserClassifier::UserClass::RARE_NTP_USER:
+ UMA_HISTOGRAM_CUSTOM_TIMES(
+ "NewTabPage.ContentSuggestions.TimeUntilStartupFetch."
+ "RareNTPUser",
+ time_until_startup_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.TimeUntilStartupFetch."
+ "ActiveNTPUser",
+ time_until_startup_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.TimeUntilStartupFetch."
+ "ActiveSuggestionsConsumer",
+ time_until_startup_fetch, base::TimeDelta::FromSeconds(1),
base::TimeDelta::FromDays(7),
/*bucket_count=*/50);
break;
@@ -288,8 +332,10 @@ bool RemoteSuggestionsSchedulerImpl::FetchingSchedule::operator==(
const FetchingSchedule& other) const {
return interval_persistent_wifi == other.interval_persistent_wifi &&
interval_persistent_fallback == other.interval_persistent_fallback &&
- interval_soft_wifi == other.interval_soft_wifi &&
- interval_soft_fallback == other.interval_soft_fallback;
+ interval_startup_wifi == other.interval_startup_wifi &&
+ interval_startup_fallback == other.interval_startup_fallback &&
+ interval_shown_wifi == other.interval_shown_wifi &&
+ interval_shown_fallback == other.interval_shown_fallback;
}
bool RemoteSuggestionsSchedulerImpl::FetchingSchedule::operator!=(
@@ -300,7 +346,9 @@ bool RemoteSuggestionsSchedulerImpl::FetchingSchedule::operator!=(
bool RemoteSuggestionsSchedulerImpl::FetchingSchedule::is_empty() const {
return interval_persistent_wifi.is_zero() &&
interval_persistent_fallback.is_zero() &&
- interval_soft_wifi.is_zero() && interval_soft_fallback.is_zero();
+ interval_startup_wifi.is_zero() &&
+ interval_startup_fallback.is_zero() && interval_shown_wifi.is_zero() &&
+ interval_shown_fallback.is_zero();
}
// The TriggerType enum specifies values for the events that can trigger
@@ -361,8 +409,11 @@ void RemoteSuggestionsSchedulerImpl::RegisterProfilePrefs(
registry->RegisterInt64Pref(prefs::kSnippetPersistentFetchingIntervalWifi, 0);
registry->RegisterInt64Pref(prefs::kSnippetPersistentFetchingIntervalFallback,
0);
- registry->RegisterInt64Pref(prefs::kSnippetSoftFetchingIntervalWifi, 0);
- registry->RegisterInt64Pref(prefs::kSnippetSoftFetchingIntervalFallback, 0);
+ registry->RegisterInt64Pref(prefs::kSnippetStartupFetchingIntervalWifi, 0);
+ registry->RegisterInt64Pref(prefs::kSnippetStartupFetchingIntervalFallback,
+ 0);
+ registry->RegisterInt64Pref(prefs::kSnippetShownFetchingIntervalWifi, 0);
+ registry->RegisterInt64Pref(prefs::kSnippetShownFetchingIntervalFallback, 0);
registry->RegisterInt64Pref(prefs::kSnippetLastFetchAttempt, 0);
// Cleanup procedure in M59. Remove for M62.
@@ -488,10 +539,14 @@ RemoteSuggestionsSchedulerImpl::GetDesiredFetchingSchedule() const {
GetDesiredFetchingInterval(FetchingInterval::PERSISTENT_WIFI, user_class);
schedule.interval_persistent_fallback = GetDesiredFetchingInterval(
FetchingInterval::PERSISTENT_FALLBACK, user_class);
- schedule.interval_soft_wifi =
- GetDesiredFetchingInterval(FetchingInterval::SOFT_WIFI, user_class);
- schedule.interval_soft_fallback =
- GetDesiredFetchingInterval(FetchingInterval::SOFT_FALLBACK, user_class);
+ schedule.interval_startup_wifi =
+ GetDesiredFetchingInterval(FetchingInterval::STARTUP_WIFI, user_class);
+ schedule.interval_startup_fallback = GetDesiredFetchingInterval(
+ FetchingInterval::STARTUP_FALLBACK, user_class);
+ schedule.interval_shown_wifi =
+ GetDesiredFetchingInterval(FetchingInterval::SHOWN_WIFI, user_class);
+ schedule.interval_shown_fallback =
+ GetDesiredFetchingInterval(FetchingInterval::SHOWN_FALLBACK, user_class);
return schedule;
}
@@ -502,10 +557,14 @@ void RemoteSuggestionsSchedulerImpl::LoadLastFetchingSchedule() {
schedule_.interval_persistent_fallback =
base::TimeDelta::FromInternalValue(profile_prefs_->GetInt64(
prefs::kSnippetPersistentFetchingIntervalFallback));
- schedule_.interval_soft_wifi = base::TimeDelta::FromInternalValue(
- profile_prefs_->GetInt64(prefs::kSnippetSoftFetchingIntervalWifi));
- schedule_.interval_soft_fallback = base::TimeDelta::FromInternalValue(
- profile_prefs_->GetInt64(prefs::kSnippetSoftFetchingIntervalFallback));
+ schedule_.interval_startup_wifi = base::TimeDelta::FromInternalValue(
+ profile_prefs_->GetInt64(prefs::kSnippetStartupFetchingIntervalWifi));
+ schedule_.interval_startup_fallback = base::TimeDelta::FromInternalValue(
+ profile_prefs_->GetInt64(prefs::kSnippetStartupFetchingIntervalFallback));
+ schedule_.interval_shown_wifi = base::TimeDelta::FromInternalValue(
+ profile_prefs_->GetInt64(prefs::kSnippetShownFetchingIntervalWifi));
+ schedule_.interval_shown_fallback = base::TimeDelta::FromInternalValue(
+ profile_prefs_->GetInt64(prefs::kSnippetShownFetchingIntervalFallback));
}
void RemoteSuggestionsSchedulerImpl::StoreFetchingSchedule() {
@@ -515,10 +574,15 @@ void RemoteSuggestionsSchedulerImpl::StoreFetchingSchedule() {
profile_prefs_->SetInt64(
prefs::kSnippetPersistentFetchingIntervalFallback,
schedule_.interval_persistent_fallback.ToInternalValue());
- profile_prefs_->SetInt64(prefs::kSnippetSoftFetchingIntervalWifi,
- schedule_.interval_soft_wifi.ToInternalValue());
- profile_prefs_->SetInt64(prefs::kSnippetSoftFetchingIntervalFallback,
- schedule_.interval_soft_fallback.ToInternalValue());
+ profile_prefs_->SetInt64(prefs::kSnippetStartupFetchingIntervalWifi,
+ schedule_.interval_startup_wifi.ToInternalValue());
+ profile_prefs_->SetInt64(
+ prefs::kSnippetStartupFetchingIntervalFallback,
+ schedule_.interval_startup_fallback.ToInternalValue());
+ profile_prefs_->SetInt64(prefs::kSnippetShownFetchingIntervalWifi,
+ schedule_.interval_shown_wifi.ToInternalValue());
+ profile_prefs_->SetInt64(prefs::kSnippetShownFetchingIntervalFallback,
+ schedule_.interval_shown_fallback.ToInternalValue());
}
void RemoteSuggestionsSchedulerImpl::RefetchInTheBackgroundIfAppropriate(
@@ -541,7 +605,8 @@ void RemoteSuggestionsSchedulerImpl::RefetchInTheBackgroundIfAppropriate(
clock_->Now() - last_fetch_attempt_time);
}
- if (is_soft && !ShouldRefetchInTheBackgroundNow(last_fetch_attempt_time)) {
+ if (is_soft &&
+ !ShouldRefetchInTheBackgroundNow(last_fetch_attempt_time, trigger)) {
return;
}
@@ -549,12 +614,20 @@ 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);
+ base::TimeDelta diff = clock_->Now() - last_fetch_attempt_time;
+ switch (trigger) {
+ case TriggerType::PERSISTENT_SCHEDULER_WAKE_UP:
+ ReportTimeUntilPersistentFetch(user_classifier_->GetUserClass(), diff);
+ break;
+ case TriggerType::NTP_OPENED:
+ ReportTimeUntilShownFetch(user_classifier_->GetUserClass(), diff);
+ break;
+ case TriggerType::BROWSER_FOREGROUNDED:
+ case TriggerType::BROWSER_COLD_START:
+ ReportTimeUntilStartupFetch(user_classifier_->GetUserClass(), diff);
+ break;
+ case TriggerType::COUNT:
+ NOTREACHED();
}
UMA_HISTOGRAM_ENUMERATION(
@@ -568,16 +641,23 @@ void RemoteSuggestionsSchedulerImpl::RefetchInTheBackgroundIfAppropriate(
}
bool RemoteSuggestionsSchedulerImpl::ShouldRefetchInTheBackgroundNow(
- base::Time last_fetch_attempt_time) {
+ base::Time last_fetch_attempt_time,
+ TriggerType trigger) {
// If we have no persistent scheduler to ask, err on the side of caution.
bool wifi = false;
if (persistent_scheduler_) {
wifi = persistent_scheduler_->IsOnUnmeteredConnection();
}
- base::Time first_allowed_fetch_time =
- last_fetch_attempt_time +
- (wifi ? schedule_.interval_soft_wifi : schedule_.interval_soft_fallback);
+ base::Time first_allowed_fetch_time = last_fetch_attempt_time;
+ if (trigger == TriggerType::NTP_OPENED) {
+ first_allowed_fetch_time += (wifi ? schedule_.interval_shown_wifi
+ : schedule_.interval_shown_fallback);
+ } else {
+ first_allowed_fetch_time += (wifi ? schedule_.interval_startup_wifi
+ : schedule_.interval_startup_fallback);
+ }
+
base::Time now = clock_->Now();
return background_fetches_allowed_after_ <= now &&
first_allowed_fetch_time <= now;

Powered by Google App Engine
This is Rietveld 408576698