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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "chrome/browser/google/google_util.h" | 15 #include "chrome/browser/google/google_util.h" |
16 #include "chrome/common/metrics/proto/chrome_experiments.pb.h" | 16 #include "chrome/common/metrics/proto/chrome_experiments.pb.h" |
17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
18 #include "net/http/http_request_headers.h" | 18 #include "net/http/http_request_headers.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 namespace chrome_variations { | 21 namespace chrome_variations { |
22 | 22 |
| 23 namespace { |
| 24 |
| 25 const char* kSuffixesToSetHeadersFor[] = { |
| 26 ".android.com", |
| 27 ".doubleclick.com", |
| 28 ".doubleclick.net", |
| 29 ".ggpht.com", |
| 30 ".googleadservices.com", |
| 31 ".googleapis.com", |
| 32 ".googlesyndication.com", |
| 33 ".googleusercontent.com", |
| 34 ".googlevideo.com", |
| 35 ".gstatic.com", |
| 36 ".ytimg.com", |
| 37 }; |
| 38 |
| 39 } // namespace |
| 40 |
23 VariationsHttpHeaderProvider* VariationsHttpHeaderProvider::GetInstance() { | 41 VariationsHttpHeaderProvider* VariationsHttpHeaderProvider::GetInstance() { |
24 return Singleton<VariationsHttpHeaderProvider>::get(); | 42 return Singleton<VariationsHttpHeaderProvider>::get(); |
25 } | 43 } |
26 | 44 |
27 void VariationsHttpHeaderProvider::AppendHeaders( | 45 void VariationsHttpHeaderProvider::AppendHeaders( |
28 const GURL& url, | 46 const GURL& url, |
29 bool incognito, | 47 bool incognito, |
30 bool uma_enabled, | 48 bool uma_enabled, |
31 net::HttpRequestHeaders* headers) { | 49 net::HttpRequestHeaders* headers) { |
32 // Note the criteria for attaching Chrome experiment headers: | 50 // Note the criteria for attaching Chrome experiment headers: |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 google_util::ALLOW_NON_STANDARD_PORTS)) { | 240 google_util::ALLOW_NON_STANDARD_PORTS)) { |
223 return true; | 241 return true; |
224 } | 242 } |
225 | 243 |
226 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) | 244 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) |
227 return false; | 245 return false; |
228 | 246 |
229 // Some domains don't have international TLD extensions, so testing for them | 247 // Some domains don't have international TLD extensions, so testing for them |
230 // is very straight forward. | 248 // is very straight forward. |
231 const std::string host = url.host(); | 249 const std::string host = url.host(); |
232 if (EndsWith(host, ".doubleclick.net", false) || | 250 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) { |
233 EndsWith(host, ".googlesyndication.com", false) || | 251 if (EndsWith(host, kSuffixesToSetHeadersFor[i], false)) |
234 LowerCaseEqualsASCII(host, "www.googleadservices.com")) { | 252 return true; |
235 return true; | |
236 } | 253 } |
237 | 254 |
238 // The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>. | 255 // The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>. |
239 const size_t tld_length = net::registry_controlled_domains::GetRegistryLength( | 256 const size_t tld_length = net::registry_controlled_domains::GetRegistryLength( |
240 host, | 257 host, |
241 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 258 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
242 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | 259 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
243 if ((tld_length == 0) || (tld_length == std::string::npos)) | 260 if ((tld_length == 0) || (tld_length == std::string::npos)) |
244 return false; | 261 return false; |
245 | 262 |
246 const std::string host_minus_tld(host, 0, host.length() - tld_length); | 263 const std::string host_minus_tld(host, 0, host.length() - tld_length); |
247 return LowerCaseEqualsASCII(host_minus_tld, "youtube.") || | 264 return LowerCaseEqualsASCII(host_minus_tld, "youtube.") || |
248 EndsWith(host_minus_tld, ".youtube.", false); | 265 EndsWith(host_minus_tld, ".youtube.", false); |
249 } | 266 } |
250 | 267 |
251 } // namespace chrome_variations | 268 } // namespace chrome_variations |
OLD | NEW |