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

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

Issue 2552813005: Use improved VariationParamsManager to hide details. (Closed)
Patch Set: Rebased, Created 4 years 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/ntp_snippets_fetcher.h" 5 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstdlib> 8 #include <cstdlib>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 int Get5xxRetryCount(bool interactive_request) { 139 int Get5xxRetryCount(bool interactive_request) {
140 if (interactive_request) { 140 if (interactive_request) {
141 return 2; 141 return 2;
142 } 142 }
143 return std::max(0, variations::GetVariationParamByFeatureAsInt( 143 return std::max(0, variations::GetVariationParamByFeatureAsInt(
144 ntp_snippets::kArticleSuggestionsFeature, 144 ntp_snippets::kArticleSuggestionsFeature,
145 kBackground5xxRetriesName, 0)); 145 kBackground5xxRetriesName, 0));
146 } 146 }
147 147
148 bool IsSendingTopLanguagesEnabled() {
149 return IsBooleanParameterEnabled(kSendTopLanguagesName,
150 /*default_value=*/false);
151 }
152
153 bool IsSendingUserClassEnabled() {
154 return IsBooleanParameterEnabled(kSendUserClassName,
155 /*default_value=*/false);
156 }
157
148 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) { 158 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) {
149 if (endpoint == kChromeReaderServer) { 159 if (endpoint == kChromeReaderServer) {
150 return false; 160 return false;
151 } 161 }
152 162
153 if (endpoint != kContentSuggestionsServer && 163 if (endpoint != kContentSuggestionsServer &&
154 endpoint != kContentSuggestionsStagingServer && 164 endpoint != kContentSuggestionsStagingServer &&
155 endpoint != kContentSuggestionsAlphaServer) { 165 endpoint != kContentSuggestionsAlphaServer) {
156 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": " 166 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": "
157 << "assuming chromecontentsuggestions-style API"; 167 << "assuming chromecontentsuggestions-style API";
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 677
668 NTPSnippetsFetcher::RequestBuilder& 678 NTPSnippetsFetcher::RequestBuilder&
669 NTPSnippetsFetcher::RequestBuilder::SetUserClassifier( 679 NTPSnippetsFetcher::RequestBuilder::SetUserClassifier(
670 const UserClassifier& user_classifier) { 680 const UserClassifier& user_classifier) {
671 if (IsSendingUserClassEnabled()) { 681 if (IsSendingUserClassEnabled()) {
672 user_class_ = GetUserClassString(user_classifier.GetUserClass()); 682 user_class_ = GetUserClassString(user_classifier.GetUserClass());
673 } 683 }
674 return *this; 684 return *this;
675 } 685 }
676 686
677 bool NTPSnippetsFetcher::RequestBuilder::IsSendingTopLanguagesEnabled() const {
678 return IsBooleanParameterEnabled(kSendTopLanguagesName,
679 /*default_value=*/false);
680 }
681
682 bool NTPSnippetsFetcher::RequestBuilder::IsSendingUserClassEnabled() const {
683 return IsBooleanParameterEnabled(kSendUserClassName,
684 /*default_value=*/false);
685 }
686
687 std::string NTPSnippetsFetcher::RequestBuilder::BuildHeaders() const { 687 std::string NTPSnippetsFetcher::RequestBuilder::BuildHeaders() const {
688 net::HttpRequestHeaders headers; 688 net::HttpRequestHeaders headers;
689 headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); 689 headers.SetHeader("Content-Type", "application/json; charset=UTF-8");
690 if (!auth_header_.empty()) { 690 if (!auth_header_.empty()) {
691 headers.SetHeader("Authorization", auth_header_); 691 headers.SetHeader("Authorization", auth_header_);
692 } 692 }
693 // Add X-Client-Data header with experiment IDs from field trials. 693 // Add X-Client-Data header with experiment IDs from field trials.
694 variations::AppendVariationHeaders(url_, 694 variations::AppendVariationHeaders(url_,
695 false, // incognito 695 false, // incognito
696 false, // uma_enabled 696 false, // uma_enabled
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 NOTREACHED(); 1110 NOTREACHED();
1111 return false; 1111 return false;
1112 } 1112 }
1113 1113
1114 bool NTPSnippetsFetcher::NeedsAuthentication() const { 1114 bool NTPSnippetsFetcher::NeedsAuthentication() const {
1115 return (personalization_ == Personalization::kPersonal || 1115 return (personalization_ == Personalization::kPersonal ||
1116 personalization_ == Personalization::kBoth); 1116 personalization_ == Personalization::kBoth);
1117 } 1117 }
1118 1118
1119 } // namespace ntp_snippets 1119 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/ntp_snippets_fetcher.h ('k') | components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698