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

Unified Diff: components/ntp_snippets/remote/remote_suggestions_fetcher.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/remote_suggestions_fetcher.cc
diff --git a/components/ntp_snippets/remote/remote_suggestions_fetcher.cc b/components/ntp_snippets/remote/remote_suggestions_fetcher.cc
index f292fef105776a2d0f3d16d93c1ecf34237ddfa9..e320c49305546b641d7dd1732c08fbf479ba3bd9 100644
--- a/components/ntp_snippets/remote/remote_suggestions_fetcher.cc
+++ b/components/ntp_snippets/remote/remote_suggestions_fetcher.cc
@@ -73,10 +73,9 @@ std::string FetchResultToString(FetchResult result) {
return "Invalid / empty list.";
case FetchResult::OAUTH_TOKEN_ERROR:
return "Error in obtaining an OAuth2 access token.";
- case FetchResult::INTERACTIVE_QUOTA_ERROR:
- return "Out of interactive quota.";
- case FetchResult::NON_INTERACTIVE_QUOTA_ERROR:
- return "Out of non-interactive quota.";
+ // Enum elements that do not represent any valid fetch result.
+ case FetchResult::INTERACTIVE_QUOTA_ERROR_OBSOLETE:
+ case FetchResult::NON_INTERACTIVE_QUOTA_ERROR_OBSOLETE:
case FetchResult::RESULT_MAX:
break;
}
@@ -97,12 +96,13 @@ Status FetchResultToStatus(FetchResult result) {
// correctly but the server failed to respond as expected.
// TODO(fhorschig): Revisit HTTP_ERROR once the rescheduling was reworked.
case FetchResult::HTTP_ERROR:
- case FetchResult::INTERACTIVE_QUOTA_ERROR:
- case FetchResult::NON_INTERACTIVE_QUOTA_ERROR:
case FetchResult::URL_REQUEST_STATUS_ERROR:
case FetchResult::INVALID_SNIPPET_CONTENT_ERROR:
case FetchResult::JSON_PARSE_ERROR:
return Status(StatusCode::TEMPORARY_ERROR, FetchResultToString(result));
+ // Enum elements that do not represent any valid fetch result.
+ case FetchResult::INTERACTIVE_QUOTA_ERROR_OBSOLETE:
+ case FetchResult::NON_INTERACTIVE_QUOTA_ERROR_OBSOLETE:
case FetchResult::RESULT_MAX:
break;
}
@@ -260,19 +260,7 @@ RemoteSuggestionsFetcher::RemoteSuggestionsFetcher(
: FetchAPI::CHROME_READER_API),
api_key_(api_key),
clock_(new base::DefaultClock()),
- 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) {}
+ user_classifier_(user_classifier) {}
RemoteSuggestionsFetcher::~RemoteSuggestionsFetcher() {
if (waiting_for_refresh_token_) {
@@ -283,15 +271,6 @@ RemoteSuggestionsFetcher::~RemoteSuggestionsFetcher() {
void RemoteSuggestionsFetcher::FetchSnippets(
const RequestParams& params,
SnippetsAvailableCallback callback) {
- if (!DemandQuotaForRequest(params.interactive_request)) {
- FetchFinished(OptionalFetchedCategories(), std::move(callback),
- params.interactive_request
- ? FetchResult::INTERACTIVE_QUOTA_ERROR
- : FetchResult::NON_INTERACTIVE_QUOTA_ERROR,
- /*error_details=*/std::string());
- return;
- }
-
if (!params.interactive_request) {
UMA_HISTOGRAM_SPARSE_SLOWLY(
"NewTabPage.Snippets.FetchTimeLocal",
@@ -571,20 +550,4 @@ bool RemoteSuggestionsFetcher::JsonToSnippets(
return false;
}
-bool RemoteSuggestionsFetcher::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;
-}
-
} // namespace ntp_snippets

Powered by Google App Engine
This is Rietveld 408576698