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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_fetcher.cc

Issue 2718453002: ntp_snippets: default to staging API on dev/canary (Closed)
Patch Set: Created 3 years, 10 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/remote/remote_suggestions_fetcher.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 case FetchResult::INVALID_SNIPPET_CONTENT_ERROR: 103 case FetchResult::INVALID_SNIPPET_CONTENT_ERROR:
104 case FetchResult::JSON_PARSE_ERROR: 104 case FetchResult::JSON_PARSE_ERROR:
105 return Status(StatusCode::TEMPORARY_ERROR, FetchResultToString(result)); 105 return Status(StatusCode::TEMPORARY_ERROR, FetchResultToString(result));
106 case FetchResult::RESULT_MAX: 106 case FetchResult::RESULT_MAX:
107 break; 107 break;
108 } 108 }
109 NOTREACHED(); 109 NOTREACHED();
110 return Status(StatusCode::PERMANENT_ERROR, std::string()); 110 return Status(StatusCode::PERMANENT_ERROR, std::string());
111 } 111 }
112 112
113 std::string GetFetchEndpoint() {
114 std::string endpoint = variations::GetVariationParamValueByFeature(
115 ntp_snippets::kArticleSuggestionsFeature, kContentSuggestionsBackend);
116 return endpoint.empty() ? kContentSuggestionsServer : endpoint;
117 }
118
119 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) { 113 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) {
120 if (endpoint == kChromeReaderServer) { 114 if (endpoint == kChromeReaderServer) {
121 return false; 115 return false;
122 } 116 }
123 117
124 if (endpoint != kContentSuggestionsServer && 118 if (endpoint != kContentSuggestionsServer &&
125 endpoint != kContentSuggestionsStagingServer && 119 endpoint != kContentSuggestionsStagingServer &&
126 endpoint != kContentSuggestionsAlphaServer) { 120 endpoint != kContentSuggestionsAlphaServer) {
127 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": " 121 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": "
128 << endpoint << "; assuming chromecontentsuggestions-style API"; 122 << endpoint << "; assuming chromecontentsuggestions-style API";
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 categories->clear(); 187 categories->clear();
194 return; 188 return;
195 } 189 }
196 RemoteSuggestionsFetcher::FetchedCategory category = std::move(*category_it); 190 RemoteSuggestionsFetcher::FetchedCategory category = std::move(*category_it);
197 categories->clear(); 191 categories->clear();
198 categories->push_back(std::move(category)); 192 categories->push_back(std::move(category));
199 } 193 }
200 194
201 } // namespace 195 } // namespace
202 196
197 std::string GetFetchEndpoint(bool is_stable_or_beta_channel) {
198 std::string endpoint = variations::GetVariationParamValueByFeature(
199 ntp_snippets::kArticleSuggestionsFeature, kContentSuggestionsBackend);
200 if (endpoint.empty()) {
201 endpoint = is_stable_or_beta_channel ? kContentSuggestionsServer
202 : kContentSuggestionsStagingServer;
203 }
204 return endpoint;
205 }
206
203 CategoryInfo BuildArticleCategoryInfo( 207 CategoryInfo BuildArticleCategoryInfo(
204 const base::Optional<base::string16>& title) { 208 const base::Optional<base::string16>& title) {
205 return CategoryInfo( 209 return CategoryInfo(
206 title.has_value() ? title.value() 210 title.has_value() ? title.value()
207 : l10n_util::GetStringUTF16( 211 : l10n_util::GetStringUTF16(
208 IDS_NTP_ARTICLE_SUGGESTIONS_SECTION_HEADER), 212 IDS_NTP_ARTICLE_SUGGESTIONS_SECTION_HEADER),
209 ContentSuggestionsCardLayout::FULL_CARD, 213 ContentSuggestionsCardLayout::FULL_CARD,
210 /*has_fetch_action=*/true, 214 /*has_fetch_action=*/true,
211 /*has_view_all_action=*/false, 215 /*has_view_all_action=*/false,
212 /*show_if_empty=*/true, 216 /*show_if_empty=*/true,
(...skipping 26 matching lines...) Expand all
239 RemoteSuggestionsFetcher::FetchedCategory::operator=(FetchedCategory&&) = 243 RemoteSuggestionsFetcher::FetchedCategory::operator=(FetchedCategory&&) =
240 default; 244 default;
241 245
242 RemoteSuggestionsFetcher::RemoteSuggestionsFetcher( 246 RemoteSuggestionsFetcher::RemoteSuggestionsFetcher(
243 SigninManagerBase* signin_manager, 247 SigninManagerBase* signin_manager,
244 OAuth2TokenService* token_service, 248 OAuth2TokenService* token_service,
245 scoped_refptr<URLRequestContextGetter> url_request_context_getter, 249 scoped_refptr<URLRequestContextGetter> url_request_context_getter,
246 PrefService* pref_service, 250 PrefService* pref_service,
247 LanguageModel* language_model, 251 LanguageModel* language_model,
248 const ParseJSONCallback& parse_json_callback, 252 const ParseJSONCallback& parse_json_callback,
253 const std::string& api_endpoint,
249 const std::string& api_key, 254 const std::string& api_key,
250 const UserClassifier* user_classifier) 255 const UserClassifier* user_classifier)
251 : OAuth2TokenService::Consumer("ntp_snippets"), 256 : OAuth2TokenService::Consumer("ntp_snippets"),
252 signin_manager_(signin_manager), 257 signin_manager_(signin_manager),
253 token_service_(token_service), 258 token_service_(token_service),
254 url_request_context_getter_(std::move(url_request_context_getter)), 259 url_request_context_getter_(std::move(url_request_context_getter)),
255 language_model_(language_model), 260 language_model_(language_model),
256 parse_json_callback_(parse_json_callback), 261 parse_json_callback_(parse_json_callback),
257 fetch_url_(GetFetchEndpoint()), 262 fetch_url_(api_endpoint),
258 fetch_api_(UsesChromeContentSuggestionsAPI(fetch_url_) 263 fetch_api_(UsesChromeContentSuggestionsAPI(fetch_url_)
259 ? FetchAPI::CHROME_CONTENT_SUGGESTIONS_API 264 ? FetchAPI::CHROME_CONTENT_SUGGESTIONS_API
260 : FetchAPI::CHROME_READER_API), 265 : FetchAPI::CHROME_READER_API),
261 api_key_(api_key), 266 api_key_(api_key),
262 clock_(new base::DefaultClock()), 267 clock_(new base::DefaultClock()),
263 user_classifier_(user_classifier), 268 user_classifier_(user_classifier),
264 request_throttler_rare_ntp_user_( 269 request_throttler_rare_ntp_user_(
265 pref_service, 270 pref_service,
266 RequestThrottler::RequestType:: 271 RequestThrottler::RequestType::
267 CONTENT_SUGGESTION_FETCHER_RARE_NTP_USER), 272 CONTENT_SUGGESTION_FETCHER_RARE_NTP_USER),
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 interactive_request); 586 interactive_request);
582 case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER: 587 case UserClassifier::UserClass::ACTIVE_SUGGESTIONS_CONSUMER:
583 return request_throttler_active_suggestions_consumer_ 588 return request_throttler_active_suggestions_consumer_
584 .DemandQuotaForRequest(interactive_request); 589 .DemandQuotaForRequest(interactive_request);
585 } 590 }
586 NOTREACHED(); 591 NOTREACHED();
587 return false; 592 return false;
588 } 593 }
589 594
590 } // namespace ntp_snippets 595 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698