| OLD | NEW |
| 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 Loading... |
| 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 base::Base64Encode(serialized, &hashed); | 166 if (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 } |
| 172 } | 176 } |
| 173 | 177 |
| 174 // static | 178 // static |
| 175 bool VariationsHttpHeaderProvider::ShouldAppendHeaders(const GURL& url) { | 179 bool VariationsHttpHeaderProvider::ShouldAppendHeaders(const GURL& url) { |
| 176 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, | 180 if (google_util::IsGoogleDomainUrl(url, google_util::ALLOW_SUBDOMAIN, |
| 177 google_util::ALLOW_NON_STANDARD_PORTS)) { | 181 google_util::ALLOW_NON_STANDARD_PORTS)) { |
| 178 return true; | 182 return true; |
| 179 } | 183 } |
| 180 | 184 |
| 181 // The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>. | 185 // The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>. |
| 182 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) | 186 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) |
| 183 return false; | 187 return false; |
| 184 | 188 |
| 185 const std::string host = url.host(); | 189 const std::string host = url.host(); |
| 186 const size_t tld_length = net::registry_controlled_domains::GetRegistryLength( | 190 const size_t tld_length = net::registry_controlled_domains::GetRegistryLength( |
| 187 host, | 191 host, |
| 188 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 192 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
| 189 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | 193 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| 190 if ((tld_length == 0) || (tld_length == std::string::npos)) | 194 if ((tld_length == 0) || (tld_length == std::string::npos)) |
| 191 return false; | 195 return false; |
| 192 | 196 |
| 193 const std::string host_minus_tld(host, 0, host.length() - tld_length); | 197 const std::string host_minus_tld(host, 0, host.length() - tld_length); |
| 194 return LowerCaseEqualsASCII(host_minus_tld, "youtube.") || | 198 return LowerCaseEqualsASCII(host_minus_tld, "youtube.") || |
| 195 EndsWith(host_minus_tld, ".youtube.", false); | 199 EndsWith(host_minus_tld, ".youtube.", false); |
| 196 } | 200 } |
| 197 | 201 |
| 198 } // namespace chrome_variations | 202 } // namespace chrome_variations |
| OLD | NEW |