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 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_); |
| } |