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

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

Issue 2759943002: [Remote suggestions] Do not fetch before EULA accepted (Closed)
Patch Set: Fix unit-test Created 3 years, 9 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/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 a26e49e208c47de085fb489e3e82582cf6fa0b91..8a286cd27ba945ef428c65110dcfa712d8b13661 100644
--- a/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc
+++ b/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc
@@ -174,11 +174,12 @@ enum class SchedulingRemoteSuggestionsProvider::TriggerType {
};
SchedulingRemoteSuggestionsProvider::SchedulingRemoteSuggestionsProvider(
- Observer* observer,
+ ContentSuggestionsProvider::Observer* observer,
std::unique_ptr<RemoteSuggestionsProvider> provider,
PersistentScheduler* persistent_scheduler,
const UserClassifier* user_classifier,
- PrefService* pref_service,
+ PrefService* profile_prefs,
+ PrefService* local_state_prefs,
std::unique_ptr<base::Clock> clock)
: RemoteSuggestionsProvider(observer),
RemoteSuggestionsScheduler(),
@@ -187,22 +188,28 @@ SchedulingRemoteSuggestionsProvider::SchedulingRemoteSuggestionsProvider(
background_fetch_in_progress_(false),
user_classifier_(user_classifier),
request_throttler_rare_ntp_user_(
- pref_service,
+ profile_prefs,
RequestThrottler::RequestType::
CONTENT_SUGGESTION_FETCHER_RARE_NTP_USER),
request_throttler_active_ntp_user_(
- pref_service,
+ profile_prefs,
RequestThrottler::RequestType::
CONTENT_SUGGESTION_FETCHER_ACTIVE_NTP_USER),
request_throttler_active_suggestions_consumer_(
- pref_service,
+ profile_prefs,
RequestThrottler::RequestType::
CONTENT_SUGGESTION_FETCHER_ACTIVE_SUGGESTIONS_CONSUMER),
- pref_service_(pref_service),
+ eula_notifier_(
+ web_resource::EulaAcceptedNotifier::Create(local_state_prefs)),
+ profile_prefs_(profile_prefs),
clock_(std::move(clock)),
enabled_triggers_(GetEnabledTriggerTypes()) {
DCHECK(user_classifier);
- DCHECK(pref_service);
+ DCHECK(profile_prefs);
+ // EulaNotifier is not constructed on some platforms (such as desktop).
+ if (eula_notifier_) {
+ eula_notifier_->Init(this);
+ }
LoadLastFetchingSchedule();
}
@@ -393,6 +400,11 @@ void SchedulingRemoteSuggestionsProvider::ClearDismissedSuggestionsForDebugging(
provider_->ClearDismissedSuggestionsForDebugging(category);
}
+void SchedulingRemoteSuggestionsProvider::OnEulaAccepted() {
+ // Emulate a browser foregrounded event.
+ OnBrowserForegrounded();
+}
+
void SchedulingRemoteSuggestionsProvider::StartScheduling() {
FetchingSchedule new_schedule = GetDesiredFetchingSchedule();
@@ -448,26 +460,28 @@ SchedulingRemoteSuggestionsProvider::GetDesiredFetchingSchedule() const {
void SchedulingRemoteSuggestionsProvider::LoadLastFetchingSchedule() {
schedule_.interval_persistent_wifi = base::TimeDelta::FromInternalValue(
- pref_service_->GetInt64(prefs::kSnippetPersistentFetchingIntervalWifi));
+ profile_prefs_->GetInt64(prefs::kSnippetPersistentFetchingIntervalWifi));
schedule_.interval_persistent_fallback =
- base::TimeDelta::FromInternalValue(pref_service_->GetInt64(
+ base::TimeDelta::FromInternalValue(profile_prefs_->GetInt64(
prefs::kSnippetPersistentFetchingIntervalFallback));
- schedule_.interval_soft_on_usage_event = base::TimeDelta::FromInternalValue(
- pref_service_->GetInt64(prefs::kSnippetSoftFetchingIntervalOnUsageEvent));
+ schedule_.interval_soft_on_usage_event =
+ base::TimeDelta::FromInternalValue(profile_prefs_->GetInt64(
+ prefs::kSnippetSoftFetchingIntervalOnUsageEvent));
schedule_.interval_soft_on_ntp_opened = base::TimeDelta::FromInternalValue(
- pref_service_->GetInt64(prefs::kSnippetSoftFetchingIntervalOnNtpOpened));
+ profile_prefs_->GetInt64(prefs::kSnippetSoftFetchingIntervalOnNtpOpened));
}
void SchedulingRemoteSuggestionsProvider::StoreFetchingSchedule() {
- pref_service_->SetInt64(prefs::kSnippetPersistentFetchingIntervalWifi,
- schedule_.interval_persistent_wifi.ToInternalValue());
- pref_service_->SetInt64(
+ profile_prefs_->SetInt64(
+ prefs::kSnippetPersistentFetchingIntervalWifi,
+ schedule_.interval_persistent_wifi.ToInternalValue());
+ profile_prefs_->SetInt64(
prefs::kSnippetPersistentFetchingIntervalFallback,
schedule_.interval_persistent_fallback.ToInternalValue());
- pref_service_->SetInt64(
+ profile_prefs_->SetInt64(
prefs::kSnippetSoftFetchingIntervalOnUsageEvent,
schedule_.interval_soft_on_usage_event.ToInternalValue());
- pref_service_->SetInt64(
+ profile_prefs_->SetInt64(
prefs::kSnippetSoftFetchingIntervalOnNtpOpened,
schedule_.interval_soft_on_ntp_opened.ToInternalValue());
}
@@ -488,7 +502,7 @@ void SchedulingRemoteSuggestionsProvider::RefetchInTheBackgroundIfEnabled(
bool SchedulingRemoteSuggestionsProvider::ShouldRefetchInTheBackgroundNow(
SchedulingRemoteSuggestionsProvider::TriggerType trigger) {
const base::Time last_fetch_attempt_time = base::Time::FromInternalValue(
- pref_service_->GetInt64(prefs::kSnippetLastFetchAttempt));
+ profile_prefs_->GetInt64(prefs::kSnippetLastFetchAttempt));
base::Time first_allowed_fetch_time;
switch (trigger) {
case TriggerType::NTP_OPENED:
@@ -520,6 +534,11 @@ bool SchedulingRemoteSuggestionsProvider::BackgroundFetchesDisabled(
if (enabled_triggers_.count(trigger) == 0) {
return true; // Background fetches for |trigger| are not enabled.
}
+
+ if (eula_notifier_ && !eula_notifier_->IsEulaAccepted()) {
+ return true; // No background fetches are allowed before EULA is accepted.
+ }
+
return false;
}
@@ -562,8 +581,8 @@ void SchedulingRemoteSuggestionsProvider::RefetchInTheBackgroundFinished(
void SchedulingRemoteSuggestionsProvider::OnFetchCompleted(
Status fetch_status) {
- pref_service_->SetInt64(prefs::kSnippetLastFetchAttempt,
- clock_->Now().ToInternalValue());
+ profile_prefs_->SetInt64(prefs::kSnippetLastFetchAttempt,
+ clock_->Now().ToInternalValue());
// Reschedule after a fetch. The persistent schedule is applied only after a
// successful fetch. After a failed fetch, we want to keep the previous
@@ -576,7 +595,7 @@ void SchedulingRemoteSuggestionsProvider::OnFetchCompleted(
}
void SchedulingRemoteSuggestionsProvider::ClearLastFetchAttemptTime() {
- pref_service_->ClearPref(prefs::kSnippetLastFetchAttempt);
+ profile_prefs_->ClearPref(prefs::kSnippetLastFetchAttempt);
}
std::set<SchedulingRemoteSuggestionsProvider::TriggerType>

Powered by Google App Engine
This is Rietveld 408576698