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

Side by Side 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: Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/ntp_snippets/ntp_snippets_fetcher.h" 5 #include "components/ntp_snippets/ntp_snippets_fetcher.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 case NTPSnippetsFetcher::FetchResult::URL_REQUEST_STATUS_ERROR: 79 case NTPSnippetsFetcher::FetchResult::URL_REQUEST_STATUS_ERROR:
80 return "URLRequestStatus error"; 80 return "URLRequestStatus error";
81 case NTPSnippetsFetcher::FetchResult::HTTP_ERROR: 81 case NTPSnippetsFetcher::FetchResult::HTTP_ERROR:
82 return "HTTP error"; 82 return "HTTP error";
83 case NTPSnippetsFetcher::FetchResult::JSON_PARSE_ERROR: 83 case NTPSnippetsFetcher::FetchResult::JSON_PARSE_ERROR:
84 return "Received invalid JSON"; 84 return "Received invalid JSON";
85 case NTPSnippetsFetcher::FetchResult::INVALID_SNIPPET_CONTENT_ERROR: 85 case NTPSnippetsFetcher::FetchResult::INVALID_SNIPPET_CONTENT_ERROR:
86 return "Invalid / empty list."; 86 return "Invalid / empty list.";
87 case NTPSnippetsFetcher::FetchResult::OAUTH_TOKEN_ERROR: 87 case NTPSnippetsFetcher::FetchResult::OAUTH_TOKEN_ERROR:
88 return "Error in obtaining an OAuth2 access token."; 88 return "Error in obtaining an OAuth2 access token.";
89 case NTPSnippetsFetcher::FetchResult::INTERACTIVE_QUOTA_ERROR:
90 return "Out of interactive quota.";
91 case NTPSnippetsFetcher::FetchResult::NON_INTERACTIVE_QUOTA_ERROR:
92 return "Out of non-interactive quota.";
89 case NTPSnippetsFetcher::FetchResult::RESULT_MAX: 93 case NTPSnippetsFetcher::FetchResult::RESULT_MAX:
90 break; 94 break;
91 } 95 }
92 NOTREACHED(); 96 NOTREACHED();
93 return "Unknown error"; 97 return "Unknown error";
94 } 98 }
95 99
96 std::string GetFetchEndpoint() { 100 std::string GetFetchEndpoint() {
97 std::string endpoint = variations::GetVariationParamValue( 101 std::string endpoint = variations::GetVariationParamValue(
98 ntp_snippets::kStudyName, kContentSuggestionsBackend); 102 ntp_snippets::kStudyName, kContentSuggestionsBackend);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 void NTPSnippetsFetcher::SetCallback( 215 void NTPSnippetsFetcher::SetCallback(
212 const SnippetsAvailableCallback& callback) { 216 const SnippetsAvailableCallback& callback) {
213 snippets_available_callback_ = callback; 217 snippets_available_callback_ = callback;
214 } 218 }
215 219
216 void NTPSnippetsFetcher::FetchSnippetsFromHosts( 220 void NTPSnippetsFetcher::FetchSnippetsFromHosts(
217 const std::set<std::string>& hosts, 221 const std::set<std::string>& hosts,
218 const std::string& language_code, 222 const std::string& language_code,
219 int count, 223 int count,
220 bool interactive_request) { 224 bool interactive_request) {
221 if (!request_throttler_.DemandQuotaForRequest(interactive_request)) 225 if (!request_throttler_.DemandQuotaForRequest(interactive_request)) {
226 FetchFinished(
227 OptionalSnippets(),
228 interactive_request ?
229 FetchResult::INTERACTIVE_QUOTA_ERROR :
230 FetchResult::NON_INTERACTIVE_QUOTA_ERROR,
231 /*extra_message=*/std::string());
222 return; 232 return;
233 }
223 234
224 hosts_ = hosts; 235 hosts_ = hosts;
225 fetch_start_time_ = tick_clock_->NowTicks(); 236 fetch_start_time_ = tick_clock_->NowTicks();
226 237
227 if (UsesHostRestrictions() && hosts_.empty()) { 238 if (UsesHostRestrictions() && hosts_.empty()) {
228 FetchFinished(OptionalSnippets(), FetchResult::EMPTY_HOSTS, 239 FetchFinished(OptionalSnippets(), FetchResult::EMPTY_HOSTS,
229 /*extra_message=*/std::string()); 240 /*extra_message=*/std::string());
230 return; 241 return;
231 } 242 }
232 243
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 592
582 void NTPSnippetsFetcher::FetchFinished(OptionalSnippets snippets, 593 void NTPSnippetsFetcher::FetchFinished(OptionalSnippets snippets,
583 FetchResult result, 594 FetchResult result,
584 const std::string& extra_message) { 595 const std::string& extra_message) {
585 DCHECK(result == FetchResult::SUCCESS || !snippets); 596 DCHECK(result == FetchResult::SUCCESS || !snippets);
586 last_status_ = FetchResultToString(result) + extra_message; 597 last_status_ = FetchResultToString(result) + extra_message;
587 598
588 // If the result is EMPTY_HOSTS or OAUTH_TOKEN_ERROR, we didn't actually send 599 // If the result is EMPTY_HOSTS or OAUTH_TOKEN_ERROR, we didn't actually send
589 // a network request, so don't record FetchTime in those cases. 600 // a network request, so don't record FetchTime in those cases.
590 if (result != FetchResult::EMPTY_HOSTS && 601 if (result != FetchResult::EMPTY_HOSTS &&
591 result != FetchResult::OAUTH_TOKEN_ERROR) { 602 result != FetchResult::OAUTH_TOKEN_ERROR) {
Marc Treib 2016/08/25 11:58:27 You should probably add the new errors here, since
592 UMA_HISTOGRAM_TIMES("NewTabPage.Snippets.FetchTime", 603 UMA_HISTOGRAM_TIMES("NewTabPage.Snippets.FetchTime",
593 tick_clock_->NowTicks() - fetch_start_time_); 604 tick_clock_->NowTicks() - fetch_start_time_);
594 } 605 }
595 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult", 606 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Snippets.FetchResult",
596 static_cast<int>(result), 607 static_cast<int>(result),
597 static_cast<int>(FetchResult::RESULT_MAX)); 608 static_cast<int>(FetchResult::RESULT_MAX));
598 609
599 if (!snippets_available_callback_.is_null()) 610 if (!snippets_available_callback_.is_null())
600 snippets_available_callback_.Run(std::move(snippets)); 611 snippets_available_callback_.Run(std::move(snippets));
601 } 612 }
602 613
603 } // namespace ntp_snippets 614 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698