Chromium Code Reviews| Index: components/ntp_snippets/ntp_snippets_fetcher.cc |
| diff --git a/components/ntp_snippets/ntp_snippets_fetcher.cc b/components/ntp_snippets/ntp_snippets_fetcher.cc |
| index 5869644f963492b331dfbcc2dc5eb70accf87db8..29d95325c0d7147a2ea4b7926a10c60081cc7d8f 100644 |
| --- a/components/ntp_snippets/ntp_snippets_fetcher.cc |
| +++ b/components/ntp_snippets/ntp_snippets_fetcher.cc |
| @@ -76,6 +76,8 @@ const char kPersonalizationBothString[] = "both"; // the default value |
| const char kHostRestrictionOnString[] = "on"; // the default value |
| const char kHostRestrictionOffString[] = "off"; |
| +const int kContentFetchesQuotaPerDay = 30; |
|
jkrcal
2016/07/25 10:08:26
I still wonder what is the right limit. I think 30
Marc Treib
2016/07/25 10:11:55
IMO regular users shouldn't hit the throttling lim
jkrcal
2016/07/25 10:26:59
Ok, changed to 50. Does fetching every 30 mins mak
Marc Treib
2016/07/25 11:07:46
Probably not, but that's a separate discussion :)
jkrcal
2016/07/26 08:30:11
Acknowledged.
|
| + |
| std::string FetchResultToString(NTPSnippetsFetcher::FetchResult result) { |
| switch (result) { |
| case NTPSnippetsFetcher::FetchResult::SUCCESS: |
| @@ -158,6 +160,7 @@ NTPSnippetsFetcher::NTPSnippetsFetcher( |
| SigninManagerBase* signin_manager, |
| OAuth2TokenService* token_service, |
| scoped_refptr<URLRequestContextGetter> url_request_context_getter, |
| + PrefService* pref_service, |
| const ParseJSONCallback& parse_json_callback, |
| bool is_stable_channel) |
| : OAuth2TokenService::Consumer("ntp_snippets"), |
| @@ -172,6 +175,10 @@ NTPSnippetsFetcher::NTPSnippetsFetcher( |
| : CHROME_READER_API), |
| is_stable_channel_(is_stable_channel), |
| tick_clock_(new base::DefaultTickClock()), |
| + request_throttler_( |
| + pref_service, |
| + RequestThrottler::RequestType::CONTENT_SUGGESTION_FETCHER, |
| + kContentFetchesQuotaPerDay), |
| weak_ptr_factory_(this) { |
| // Parse the variation parameters and set the defaults if missing. |
| std::string personalization = variations::GetVariationParamValue( |
| @@ -214,7 +221,11 @@ void NTPSnippetsFetcher::SetCallback( |
| void NTPSnippetsFetcher::FetchSnippetsFromHosts( |
| const std::set<std::string>& hosts, |
| const std::string& language_code, |
| - int count) { |
| + int count, |
| + bool force_request) { |
| + if (!request_throttler_.DemandQuotaForRequest(force_request)) |
| + return; |
| + |
| hosts_ = hosts; |
| fetch_start_time_ = tick_clock_->NowTicks(); |