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

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

Issue 2714863004: [Remote suggestions] Move the throttler into the Scheduler (Closed)
Patch Set: Created 3 years, 10 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 7a78d50e1cdb1d9d7116cc71fdfa605ce1e73d89..99d00c66e01aaa40a8dbb1b860822ad576217495 100644
--- a/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc
+++ b/components/ntp_snippets/remote/scheduling_remote_suggestions_provider.cc
@@ -186,6 +186,18 @@ SchedulingRemoteSuggestionsProvider::SchedulingRemoteSuggestionsProvider(
persistent_scheduler_(persistent_scheduler),
background_fetch_in_progress_(false),
user_classifier_(user_classifier),
+ request_throttler_rare_ntp_user_(
+ pref_service,
+ RequestThrottler::RequestType::
+ CONTENT_SUGGESTION_FETCHER_RARE_NTP_USER),
+ request_throttler_active_ntp_user_(
+ pref_service,
+ RequestThrottler::RequestType::
+ CONTENT_SUGGESTION_FETCHER_ACTIVE_NTP_USER),
+ request_throttler_active_suggestions_consumer_(
+ pref_service,
+ RequestThrottler::RequestType::
+ CONTENT_SUGGESTION_FETCHER_ACTIVE_SUGGESTIONS_CONSUMER),
pref_service_(pref_service),
clock_(std::move(clock)),
enabled_triggers_(GetEnabledTriggerTypes()) {
@@ -292,6 +304,14 @@ void SchedulingRemoteSuggestionsProvider::RefetchInTheBackground(
return;
}
+ if (!DemandQuotaForRequest(/*interactive_request=*/false)) {
+ if (callback) {
+ callback->Run(Status(StatusCode::TEMPORARY_ERROR,
+ "Non-interactive quota exceeded"));
+ }
+ return;
+ }
+
background_fetch_in_progress_ = true;
RemoteSuggestionsProvider::FetchStatusCallback wrapper_callback = base::Bind(
&SchedulingRemoteSuggestionsProvider::RefetchInTheBackgroundFinished,
@@ -331,6 +351,15 @@ void SchedulingRemoteSuggestionsProvider::Fetch(
const Category& category,
const std::set<std::string>& known_suggestion_ids,
const FetchDoneCallback& callback) {
+ if (!DemandQuotaForRequest(/*interactive_request=*/true)) {
+ if (callback) {
+ callback.Run(
+ Status(StatusCode::TEMPORARY_ERROR, "Interactive quota exceeded"),
+ std::vector<ContentSuggestion>());
+ }
+ return;
+ }
+
provider_->Fetch(
category, known_suggestion_ids,
base::Bind(&SchedulingRemoteSuggestionsProvider::FetchFinished,
@@ -338,6 +367,10 @@ void SchedulingRemoteSuggestionsProvider::Fetch(
}
void SchedulingRemoteSuggestionsProvider::ReloadSuggestions() {
+ if (!DemandQuotaForRequest(/*interactive_request=*/true)) {
+ return;
+ }
+
provider_->ReloadSuggestions();
}
@@ -498,6 +531,23 @@ bool SchedulingRemoteSuggestionsProvider::BackgroundFetchesDisabled(
return false;
}
+bool SchedulingRemoteSuggestionsProvider::DemandQuotaForRequest(
+ bool interactive_request) {
+ switch (user_classifier_->GetUserClass()) {
+ case UserClassifier::UserClass::RARE_NTP_USER:
+ return request_throttler_rare_ntp_user_.DemandQuotaForRequest(
+ interactive_request);
+ case UserClassifier::UserClass::ACTIVE_NTP_USER:
+ return request_throttler_active_ntp_user_.DemandQuotaForRequest(
+ interactive_request);
+ case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER:
+ return request_throttler_active_suggestions_consumer_
+ .DemandQuotaForRequest(interactive_request);
+ }
+ NOTREACHED();
+ return false;
+}
+
void SchedulingRemoteSuggestionsProvider::FetchFinished(
const FetchDoneCallback& callback,
Status fetch_status,

Powered by Google App Engine
This is Rietveld 408576698