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..255bc88dd7ca6cb1e5be7afc54c9008e9307afaf 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 kArticlesQuotaPerDay = 20; |
Marc Treib
2016/07/22 13:52:52
This sounds like "number of articles per day", but
jkrcal
2016/07/25 10:05:38
Done.
Overriding by variation params is built in
Marc Treib
2016/07/25 10:11:55
I see... this is surprising to me. Since everythin
jkrcal
2016/07/25 10:26:59
Makes sense. Done.
|
+ |
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, |
+ kArticlesQuotaPerDay), |
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(); |