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

Unified Diff: components/ntp_snippets/remote/remote_suggestions_fetcher.cc

Issue 2750393002: [NTP Snippets] Don't attempt to fetch remote suggestions without API key (Closed)
Patch Set: Created 3 years, 9 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/remote/remote_suggestions_fetcher.cc
diff --git a/components/ntp_snippets/remote/remote_suggestions_fetcher.cc b/components/ntp_snippets/remote/remote_suggestions_fetcher.cc
index 2f9b64334f52e5fe57bdb6dd508593042ea330fc..17ebaa7d3049d09581cb6748daae0855c182c931 100644
--- a/components/ntp_snippets/remote/remote_suggestions_fetcher.cc
+++ b/components/ntp_snippets/remote/remote_suggestions_fetcher.cc
@@ -71,6 +71,8 @@ std::string FetchResultToString(FetchResult result) {
return "Invalid / empty list.";
case FetchResult::OAUTH_TOKEN_ERROR:
return "Error in obtaining an OAuth2 access token.";
+ case FetchResult::MISSING_API_KEY:
+ return "No API key available.";
case FetchResult::RESULT_MAX:
break;
}
@@ -85,6 +87,7 @@ Status FetchResultToStatus(FetchResult result) {
// Permanent errors occur if it is more likely that the error originated
// from the client.
case FetchResult::OAUTH_TOKEN_ERROR:
+ case FetchResult::MISSING_API_KEY:
return Status(StatusCode::PERMANENT_ERROR, FetchResultToString(result));
// Temporary errors occur if it's more likely that the client behaved
// correctly but the server failed to respond as expected.
@@ -322,6 +325,12 @@ void RemoteSuggestionsFetcher::FetchSnippets(
void RemoteSuggestionsFetcher::FetchSnippetsNonAuthenticated(
JsonRequest::Builder builder,
SnippetsAvailableCallback callback) {
+ if (api_key_.empty()) {
+ // If we don't have an API key, don't even try.
+ FetchFinished(OptionalFetchedCategories(), std::move(callback),
+ FetchResult::MISSING_API_KEY, std::string());
+ return;
+ }
// When not providing OAuth token, we need to pass the Google API key.
builder.SetUrl(
GURL(base::StringPrintf(kSnippetsServerNonAuthorizedFormat,
« no previous file with comments | « components/ntp_snippets/remote/json_request.h ('k') | components/ntp_snippets/remote/remote_suggestions_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698