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

Unified Diff: components/ntp_snippets/ntp_snippets_fetcher.cc

Issue 2273323002: NTP Snippets: Added error codes for out of quota events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments Created 4 years, 4 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
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c0018e7d816ad650ff06f25bdf664b5b64034e2e..2296e14157628f07f758c5679c878d56d4db586f 100644
--- a/components/ntp_snippets/ntp_snippets_fetcher.cc
+++ b/components/ntp_snippets/ntp_snippets_fetcher.cc
@@ -86,6 +86,10 @@ std::string FetchResultToString(NTPSnippetsFetcher::FetchResult result) {
return "Invalid / empty list.";
case NTPSnippetsFetcher::FetchResult::OAUTH_TOKEN_ERROR:
return "Error in obtaining an OAuth2 access token.";
+ case NTPSnippetsFetcher::FetchResult::INTERACTIVE_QUOTA_ERROR:
+ return "Out of interactive quota.";
+ case NTPSnippetsFetcher::FetchResult::NON_INTERACTIVE_QUOTA_ERROR:
+ return "Out of non-interactive quota.";
case NTPSnippetsFetcher::FetchResult::RESULT_MAX:
break;
}
@@ -93,6 +97,25 @@ std::string FetchResultToString(NTPSnippetsFetcher::FetchResult result) {
return "Unknown error";
}
+bool IsFetchPreconditionFailed(NTPSnippetsFetcher::FetchResult result) {
+ switch (result) {
+ case NTPSnippetsFetcher::FetchResult::EMPTY_HOSTS:
+ case NTPSnippetsFetcher::FetchResult::OAUTH_TOKEN_ERROR:
+ case NTPSnippetsFetcher::FetchResult::INTERACTIVE_QUOTA_ERROR:
+ case NTPSnippetsFetcher::FetchResult::NON_INTERACTIVE_QUOTA_ERROR:
+ return true;
+ case NTPSnippetsFetcher::FetchResult::SUCCESS:
+ case NTPSnippetsFetcher::FetchResult::URL_REQUEST_STATUS_ERROR:
+ case NTPSnippetsFetcher::FetchResult::HTTP_ERROR:
+ case NTPSnippetsFetcher::FetchResult::JSON_PARSE_ERROR:
+ case NTPSnippetsFetcher::FetchResult::INVALID_SNIPPET_CONTENT_ERROR:
+ case NTPSnippetsFetcher::FetchResult::RESULT_MAX:
Marc Treib 2016/08/25 14:41:06 nit: RESULT_MAX should never happen, so you could
+ return false;
+ }
+ NOTREACHED();
+ return true;
+}
+
std::string GetFetchEndpoint() {
std::string endpoint = variations::GetVariationParamValue(
ntp_snippets::kStudyName, kContentSuggestionsBackend);
@@ -218,8 +241,14 @@ void NTPSnippetsFetcher::FetchSnippetsFromHosts(
const std::string& language_code,
int count,
bool interactive_request) {
- if (!request_throttler_.DemandQuotaForRequest(interactive_request))
+ if (!request_throttler_.DemandQuotaForRequest(interactive_request)) {
+ FetchFinished(OptionalSnippets(),
+ interactive_request
+ ? FetchResult::INTERACTIVE_QUOTA_ERROR
+ : FetchResult::NON_INTERACTIVE_QUOTA_ERROR,
+ /*extra_message=*/std::string());
return;
+ }
hosts_ = hosts;
fetch_start_time_ = tick_clock_->NowTicks();
@@ -585,10 +614,9 @@ void NTPSnippetsFetcher::FetchFinished(OptionalSnippets snippets,
DCHECK(result == FetchResult::SUCCESS || !snippets);
last_status_ = FetchResultToString(result) + extra_message;
- // If the result is EMPTY_HOSTS or OAUTH_TOKEN_ERROR, we didn't actually send
- // a network request, so don't record FetchTime in those cases.
- if (result != FetchResult::EMPTY_HOSTS &&
- result != FetchResult::OAUTH_TOKEN_ERROR) {
+ // Don't record FetchTimes if the result indicates that a precondition
+ // failed and we never actually sent a network request
+ if (!IsFetchPreconditionFailed(result)) {
UMA_HISTOGRAM_TIMES("NewTabPage.Snippets.FetchTime",
tick_clock_->NowTicks() - fetch_start_time_);
}
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698