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

Side by Side Diff: chrome/browser/metrics/variations/variations_http_header_provider.cc

Issue 86913002: Make base::Base64Encode() return void (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: One more chromeos-specific fix. Created 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/metrics/variations/variations_http_header_provider.h" 5 #include "chrome/browser/metrics/variations/variations_http_header_provider.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 metrics::ChromeVariations proto; 156 metrics::ChromeVariations proto;
157 for (std::set<VariationID>::const_iterator it = all_variation_ids_set.begin(); 157 for (std::set<VariationID>::const_iterator it = all_variation_ids_set.begin();
158 it != all_variation_ids_set.end(); ++it) { 158 it != all_variation_ids_set.end(); ++it) {
159 proto.add_variation_id(*it); 159 proto.add_variation_id(*it);
160 } 160 }
161 161
162 std::string serialized; 162 std::string serialized;
163 proto.SerializeToString(&serialized); 163 proto.SerializeToString(&serialized);
164 164
165 std::string hashed; 165 std::string hashed;
166 if (base::Base64Encode(serialized, &hashed)) { 166 base::Base64Encode(serialized, &hashed);
167 // If successful, swap the header value with the new one. 167 // If successful, swap the header value with the new one.
168 // Note that the list of IDs and the header could be temporarily out of sync 168 // Note that the list of IDs and the header could be temporarily out of sync
169 // if IDs are added as the header is recreated. The receiving servers are OK 169 // if IDs are added as the header is recreated. The receiving servers are OK
170 // with such discrepancies. 170 // with such discrepancies.
171 variation_ids_header_ = hashed; 171 variation_ids_header_ = hashed;
172 } else {
173 NOTREACHED() << "Failed to base64 encode Variation IDs value: "
174 << serialized;
175 }
176 } 172 }
177 173
178 // static 174 // static
179 bool VariationsHttpHeaderProvider::ShouldAppendHeaders(const GURL& url) { 175 bool VariationsHttpHeaderProvider::ShouldAppendHeaders(const GURL& url) {
180 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, 176 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
181 google_util::ALLOW_NON_STANDARD_PORTS)) { 177 google_util::ALLOW_NON_STANDARD_PORTS)) {
182 return true; 178 return true;
183 } 179 }
184 180
185 // The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>. 181 // The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>.
186 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) 182 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS())
187 return false; 183 return false;
188 184
189 const std::string host = url.host(); 185 const std::string host = url.host();
190 const size_t tld_length = net::registry_controlled_domains::GetRegistryLength( 186 const size_t tld_length = net::registry_controlled_domains::GetRegistryLength(
191 host, 187 host,
192 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, 188 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
193 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); 189 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
194 if ((tld_length == 0) || (tld_length == std::string::npos)) 190 if ((tld_length == 0) || (tld_length == std::string::npos))
195 return false; 191 return false;
196 192
197 const std::string host_minus_tld(host, 0, host.length() - tld_length); 193 const std::string host_minus_tld(host, 0, host.length() - tld_length);
198 return LowerCaseEqualsASCII(host_minus_tld, "youtube.") || 194 return LowerCaseEqualsASCII(host_minus_tld, "youtube.") ||
199 EndsWith(host_minus_tld, ".youtube.", false); 195 EndsWith(host_minus_tld, ".youtube.", false);
200 } 196 }
201 197
202 } // namespace chrome_variations 198 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_log_serializer.cc ('k') | chrome/browser/metrics/variations/variations_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698