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..22894d5442b680de6a46ecaa84be9dfd9513fa8d 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,18 @@ std::string FetchResultToString(NTPSnippetsFetcher::FetchResult result) { |
| return "Unknown error"; |
| } |
| +bool isFetchPreconditionFailed(NTPSnippetsFetcher::FetchResult result) { |
|
Marc Treib
2016/08/25 14:19:05
nit: IsFetchPreconditionFailed (start with a capit
|
| + 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; |
| + default: |
|
Marc Treib
2016/08/25 14:19:05
Instead of a default, I'd prefer to list the value
|
| + return false; |
| + } |
| +} |
| + |
| std::string GetFetchEndpoint() { |
| std::string endpoint = variations::GetVariationParamValue( |
| ntp_snippets::kStudyName, kContentSuggestionsBackend); |
| @@ -218,8 +234,15 @@ 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 : |
|
Marc Treib
2016/08/25 14:19:05
nit: wrong indentation I think? (You could try "gi
|
| + FetchResult::NON_INTERACTIVE_QUOTA_ERROR, |
| + /*extra_message=*/std::string()); |
| return; |
| + } |
| hosts_ = hosts; |
| fetch_start_time_ = tick_clock_->NowTicks(); |
| @@ -585,10 +608,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_); |
| } |