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

Unified Diff: components/ntp_snippets/ntp_snippets_fetcher.cc

Issue 2162533002: Adding a request counter to the snippets fetcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@traffic-monitor
Patch Set: Bernhard's comments Created 4 years, 5 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/ntp_snippets_fetcher.cc
diff --git a/components/ntp_snippets/ntp_snippets_fetcher.cc b/components/ntp_snippets/ntp_snippets_fetcher.cc
index 5869644f963492b331dfbcc2dc5eb70accf87db8..8e888abf50f507f447aac0215d3906ed9a0deb9f 100644
--- a/components/ntp_snippets/ntp_snippets_fetcher.cc
+++ b/components/ntp_snippets/ntp_snippets_fetcher.cc
@@ -158,6 +158,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 +173,9 @@ 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),
weak_ptr_factory_(this) {
// Parse the variation parameters and set the defaults if missing.
std::string personalization = variations::GetVariationParamValue(
@@ -214,7 +218,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();
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.h ('k') | components/ntp_snippets/ntp_snippets_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698