| Index: components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc
|
| diff --git a/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc b/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc
|
| index 788ac534fe4bbe6901bd49e23bfeaf21c35f8e9a..b4d3352c7abd0dd0a3cf2f9b6d2d4d9806208921 100644
|
| --- a/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc
|
| +++ b/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc
|
| @@ -37,6 +37,7 @@ enum class FetchingInterval {
|
| PERSISTENT_FALLBACK,
|
| PERSISTENT_WIFI,
|
| SOFT_ON_USAGE_EVENT,
|
| + SOFT_ON_NTP_OPENED,
|
| COUNT
|
| };
|
|
|
| @@ -46,25 +47,30 @@ 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, 12.0};
|
| -const double kDefaultFetchingIntervalHoursActiveNtpUser[] = {24.0, 6.0, 2.0};
|
| +const double kDefaultFetchingIntervalHoursRareNtpUser[] = {48.0, 24.0, 12.0,
|
| + 6.0};
|
| +const double kDefaultFetchingIntervalHoursActiveNtpUser[] = {24.0, 6.0, 2.0,
|
| + 2.0};
|
| const double kDefaultFetchingIntervalHoursActiveSuggestionsConsumer[] = {
|
| - 24.0, 6.0, 2.0};
|
| + 24.0, 6.0, 2.0, 1.0};
|
|
|
| // Variation parameters than can be used to override the default fetching
|
| // intervals.
|
| const char* kFetchingIntervalParamNameRareNtpUser[] = {
|
| "fetching_interval_hours-fallback-rare_ntp_user",
|
| "fetching_interval_hours-wifi-rare_ntp_user",
|
| - "soft_fetching_interval_hours-active-rare_ntp_user"};
|
| + "soft_fetching_interval_hours-active-rare_ntp_user",
|
| + "soft_on_ntp_opened_interval_hours-rare_ntp_user"};
|
| const char* kFetchingIntervalParamNameActiveNtpUser[] = {
|
| "fetching_interval_hours-fallback-active_ntp_user",
|
| "fetching_interval_hours-wifi-active_ntp_user",
|
| - "soft_fetching_interval_hours-active-active_ntp_user"};
|
| + "soft_fetching_interval_hours-active-active_ntp_user",
|
| + "soft_on_ntp_opened_interval_hours-active_ntp_user"};
|
| const char* kFetchingIntervalParamNameActiveSuggestionsConsumer[] = {
|
| "fetching_interval_hours-fallback-active_suggestions_consumer",
|
| "fetching_interval_hours-wifi-active_suggestions_consumer",
|
| - "soft_fetching_interval_hours-active-active_suggestions_consumer"};
|
| + "soft_fetching_interval_hours-active-active_suggestions_consumer",
|
| + "soft_on_ntp_opened_interval_hours-active_suggestions_consumer"};
|
|
|
| static_assert(
|
| static_cast<unsigned int>(FetchingInterval::COUNT) ==
|
| @@ -131,14 +137,15 @@ base::TimeDelta GetDesiredFetchingInterval(
|
| SchedulingRemoteSuggestionsProvider::FetchingSchedule
|
| SchedulingRemoteSuggestionsProvider::FetchingSchedule::Empty() {
|
| return FetchingSchedule{base::TimeDelta(), base::TimeDelta(),
|
| - base::TimeDelta()};
|
| + base::TimeDelta(), base::TimeDelta()};
|
| }
|
|
|
| bool SchedulingRemoteSuggestionsProvider::FetchingSchedule::operator==(
|
| const FetchingSchedule& other) const {
|
| return interval_persistent_wifi == other.interval_persistent_wifi &&
|
| interval_persistent_fallback == other.interval_persistent_fallback &&
|
| - interval_soft_on_usage_event == other.interval_soft_on_usage_event;
|
| + interval_soft_on_usage_event == other.interval_soft_on_usage_event &&
|
| + interval_soft_on_ntp_opened == other.interval_soft_on_ntp_opened;
|
| }
|
|
|
| bool SchedulingRemoteSuggestionsProvider::FetchingSchedule::operator!=(
|
| @@ -149,7 +156,8 @@ bool SchedulingRemoteSuggestionsProvider::FetchingSchedule::operator!=(
|
| bool SchedulingRemoteSuggestionsProvider::FetchingSchedule::is_empty() const {
|
| return interval_persistent_wifi.is_zero() &&
|
| interval_persistent_fallback.is_zero() &&
|
| - interval_soft_on_usage_event.is_zero();
|
| + interval_soft_on_usage_event.is_zero() &&
|
| + interval_soft_on_ntp_opened.is_zero();
|
| }
|
|
|
| // The TriggerType enum specifies values for the events that can trigger
|
| @@ -205,6 +213,8 @@ void SchedulingRemoteSuggestionsProvider::RegisterProfilePrefs(
|
| registry->RegisterInt64Pref(prefs::kSnippetSoftFetchingIntervalOnUsageEvent,
|
| 0);
|
| registry->RegisterInt64Pref(prefs::kSnippetLastFetchAttempt, 0);
|
| + registry->RegisterInt64Pref(prefs::kSnippetSoftFetchingIntervalOnNtpOpened,
|
| + 0);
|
| }
|
|
|
| void SchedulingRemoteSuggestionsProvider::RescheduleFetching() {
|
| @@ -220,7 +230,7 @@ void SchedulingRemoteSuggestionsProvider::OnPersistentSchedulerWakeUp() {
|
| void SchedulingRemoteSuggestionsProvider::OnBrowserForegrounded() {
|
| // TODO(jkrcal): Consider that this is called whenever we open or return to an
|
| // Activity. Therefore, keep work light for fast start up calls.
|
| - if (!ShouldRefetchInTheBackgroundNow()) {
|
| + if (!ShouldRefetchInTheBackgroundNow(TriggerType::BROWSER_FOREGROUNDED)) {
|
| return;
|
| }
|
|
|
| @@ -230,7 +240,7 @@ void SchedulingRemoteSuggestionsProvider::OnBrowserForegrounded() {
|
| void SchedulingRemoteSuggestionsProvider::OnBrowserColdStart() {
|
| // TODO(fhorschig|jkrcal): Consider that work here must be kept light for fast
|
| // cold start ups.
|
| - if (!ShouldRefetchInTheBackgroundNow()) {
|
| + if (!ShouldRefetchInTheBackgroundNow(TriggerType::BROWSER_COLD_START)) {
|
| return;
|
| }
|
|
|
| @@ -238,7 +248,7 @@ void SchedulingRemoteSuggestionsProvider::OnBrowserColdStart() {
|
| }
|
|
|
| void SchedulingRemoteSuggestionsProvider::OnNTPOpened() {
|
| - if (!ShouldRefetchInTheBackgroundNow()) {
|
| + if (!ShouldRefetchInTheBackgroundNow(TriggerType::NTP_OPENED)) {
|
| return;
|
| }
|
|
|
| @@ -396,6 +406,8 @@ SchedulingRemoteSuggestionsProvider::GetDesiredFetchingSchedule() const {
|
| FetchingInterval::PERSISTENT_FALLBACK, user_class);
|
| schedule.interval_soft_on_usage_event = GetDesiredFetchingInterval(
|
| FetchingInterval::SOFT_ON_USAGE_EVENT, user_class);
|
| + schedule.interval_soft_on_ntp_opened = GetDesiredFetchingInterval(
|
| + FetchingInterval::SOFT_ON_NTP_OPENED, user_class);
|
|
|
| return schedule;
|
| }
|
| @@ -408,6 +420,8 @@ void SchedulingRemoteSuggestionsProvider::LoadLastFetchingSchedule() {
|
| prefs::kSnippetPersistentFetchingIntervalFallback));
|
| schedule_.interval_soft_on_usage_event = base::TimeDelta::FromInternalValue(
|
| pref_service_->GetInt64(prefs::kSnippetSoftFetchingIntervalOnUsageEvent));
|
| + schedule_.interval_soft_on_ntp_opened = base::TimeDelta::FromInternalValue(
|
| + pref_service_->GetInt64(prefs::kSnippetSoftFetchingIntervalOnNtpOpened));
|
| }
|
|
|
| void SchedulingRemoteSuggestionsProvider::StoreFetchingSchedule() {
|
| @@ -419,6 +433,9 @@ void SchedulingRemoteSuggestionsProvider::StoreFetchingSchedule() {
|
| pref_service_->SetInt64(
|
| prefs::kSnippetSoftFetchingIntervalOnUsageEvent,
|
| schedule_.interval_soft_on_usage_event.ToInternalValue());
|
| + pref_service_->SetInt64(
|
| + prefs::kSnippetSoftFetchingIntervalOnNtpOpened,
|
| + schedule_.interval_soft_on_ntp_opened.ToInternalValue());
|
| }
|
|
|
| void SchedulingRemoteSuggestionsProvider::RefetchInTheBackgroundIfEnabled(
|
| @@ -434,11 +451,26 @@ void SchedulingRemoteSuggestionsProvider::RefetchInTheBackgroundIfEnabled(
|
| RefetchInTheBackground(/*callback=*/nullptr);
|
| }
|
|
|
| -bool SchedulingRemoteSuggestionsProvider::ShouldRefetchInTheBackgroundNow() {
|
| - base::Time first_allowed_fetch_time =
|
| - base::Time::FromInternalValue(
|
| - pref_service_->GetInt64(prefs::kSnippetLastFetchAttempt)) +
|
| - schedule_.interval_soft_on_usage_event;
|
| +bool SchedulingRemoteSuggestionsProvider::ShouldRefetchInTheBackgroundNow(
|
| + SchedulingRemoteSuggestionsProvider::TriggerType trigger) {
|
| + const base::Time last_fetch_attempt_time = base::Time::FromInternalValue(
|
| + pref_service_->GetInt64(prefs::kSnippetLastFetchAttempt));
|
| + base::Time first_allowed_fetch_time;
|
| + switch (trigger) {
|
| + case TriggerType::NTP_OPENED:
|
| + first_allowed_fetch_time =
|
| + last_fetch_attempt_time + schedule_.interval_soft_on_ntp_opened;
|
| + break;
|
| + case TriggerType::BROWSER_FOREGROUNDED:
|
| + case TriggerType::BROWSER_COLD_START:
|
| + first_allowed_fetch_time =
|
| + last_fetch_attempt_time + schedule_.interval_soft_on_usage_event;
|
| + break;
|
| + case TriggerType::PERSISTENT_SCHEDULER_WAKE_UP:
|
| + case TriggerType::COUNT:
|
| + NOTREACHED();
|
| + break;
|
| + }
|
| return first_allowed_fetch_time <= clock_->Now();
|
| }
|
|
|
|
|