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

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

Issue 2552813005: Use improved VariationParamsManager to hide details. (Closed)
Patch Set: 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 <cstdlib> 7 #include <cstdlib>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 if (param_value == kBooleanParameterDisabled) { 125 if (param_value == kBooleanParameterDisabled) {
126 return false; 126 return false;
127 } 127 }
128 if (!param_value.empty()) { 128 if (!param_value.empty()) {
129 LOG(WARNING) << "Invalid value \"" << param_value 129 LOG(WARNING) << "Invalid value \"" << param_value
130 << "\" for variation parameter " << param_name; 130 << "\" for variation parameter " << param_name;
131 } 131 }
132 return default_value; 132 return default_value;
133 } 133 }
134 134
135 bool IsSendingTopLanguagesEnabled() {
136 return IsBooleanParameterEnabled(kSendTopLanguagesName,
137 /*default_value=*/false);
138 }
139
140 bool IsSendingUserClassEnabled() {
141 return IsBooleanParameterEnabled(kSendUserClassName,
142 /*default_value=*/false);
143 }
144
135 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) { 145 bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) {
136 if (endpoint == kChromeReaderServer) { 146 if (endpoint == kChromeReaderServer) {
137 return false; 147 return false;
138 } 148 }
139 149
140 if (endpoint != kContentSuggestionsServer && 150 if (endpoint != kContentSuggestionsServer &&
141 endpoint != kContentSuggestionsStagingServer && 151 endpoint != kContentSuggestionsStagingServer &&
142 endpoint != kContentSuggestionsAlphaServer) { 152 endpoint != kContentSuggestionsAlphaServer) {
143 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": " 153 LOG(WARNING) << "Unknown value for " << kContentSuggestionsBackend << ": "
144 << "assuming chromecontentsuggestions-style API"; 154 << "assuming chromecontentsuggestions-style API";
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 664
655 NTPSnippetsFetcher::RequestBuilder& 665 NTPSnippetsFetcher::RequestBuilder&
656 NTPSnippetsFetcher::RequestBuilder::SetUserClassifier( 666 NTPSnippetsFetcher::RequestBuilder::SetUserClassifier(
657 const UserClassifier& user_classifier) { 667 const UserClassifier& user_classifier) {
658 if (IsSendingUserClassEnabled()) { 668 if (IsSendingUserClassEnabled()) {
659 user_class_ = GetUserClassString(user_classifier.GetUserClass()); 669 user_class_ = GetUserClassString(user_classifier.GetUserClass());
660 } 670 }
661 return *this; 671 return *this;
662 } 672 }
663 673
664 bool NTPSnippetsFetcher::RequestBuilder::IsSendingTopLanguagesEnabled() const {
665 return IsBooleanParameterEnabled(kSendTopLanguagesName,
666 /*default_value=*/false);
667 }
668
669 bool NTPSnippetsFetcher::RequestBuilder::IsSendingUserClassEnabled() const {
670 return IsBooleanParameterEnabled(kSendUserClassName,
671 /*default_value=*/false);
672 }
673
674 std::string NTPSnippetsFetcher::RequestBuilder::BuildHeaders() const { 674 std::string NTPSnippetsFetcher::RequestBuilder::BuildHeaders() const {
675 net::HttpRequestHeaders headers; 675 net::HttpRequestHeaders headers;
676 headers.SetHeader("Content-Type", "application/json; charset=UTF-8"); 676 headers.SetHeader("Content-Type", "application/json; charset=UTF-8");
677 if (!auth_header_.empty()) { 677 if (!auth_header_.empty()) {
678 headers.SetHeader("Authorization", auth_header_); 678 headers.SetHeader("Authorization", auth_header_);
679 } 679 }
680 // Add X-Client-Data header with experiment IDs from field trials. 680 // Add X-Client-Data header with experiment IDs from field trials.
681 variations::AppendVariationHeaders(url_, 681 variations::AppendVariationHeaders(url_,
682 false, // incognito 682 false, // incognito
683 false, // uma_enabled 683 false, // uma_enabled
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 NOTREACHED(); 1097 NOTREACHED();
1098 return false; 1098 return false;
1099 } 1099 }
1100 1100
1101 bool NTPSnippetsFetcher::NeedsAuthentication() const { 1101 bool NTPSnippetsFetcher::NeedsAuthentication() const {
1102 return (personalization_ == Personalization::kPersonal || 1102 return (personalization_ == Personalization::kPersonal ||
1103 personalization_ == Personalization::kBoth); 1103 personalization_ == Personalization::kBoth);
1104 } 1104 }
1105 1105
1106 } // namespace ntp_snippets 1106 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698