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 12 matching lines...) Expand all Loading... |
23 VariationsHttpHeaderProvider* VariationsHttpHeaderProvider::GetInstance() { | 23 VariationsHttpHeaderProvider* VariationsHttpHeaderProvider::GetInstance() { |
24 return Singleton<VariationsHttpHeaderProvider>::get(); | 24 return Singleton<VariationsHttpHeaderProvider>::get(); |
25 } | 25 } |
26 | 26 |
27 void VariationsHttpHeaderProvider::AppendHeaders( | 27 void VariationsHttpHeaderProvider::AppendHeaders( |
28 const GURL& url, | 28 const GURL& url, |
29 bool incognito, | 29 bool incognito, |
30 bool uma_enabled, | 30 bool uma_enabled, |
31 net::HttpRequestHeaders* headers) { | 31 net::HttpRequestHeaders* headers) { |
32 // Note the criteria for attaching Chrome experiment headers: | 32 // Note the criteria for attaching Chrome experiment headers: |
33 // 1. We only transmit to *.google.<TLD> or *.youtube.<TLD> domains. | 33 // 1. We only transmit to Google owned domains which can evaluate experiments. |
| 34 // 1a. These include hosts which have a standard postfix such as: |
| 35 // *.doubleclick.net or *.googlesyndication.com or |
| 36 // exactly www.googleadservices.com or |
| 37 // international TLD domains *.google.<TLD> or *.youtube.<TLD>. |
34 // 2. Only transmit for non-Incognito profiles. | 38 // 2. Only transmit for non-Incognito profiles. |
35 // 3. For the X-Chrome-UMA-Enabled bit, only set it if UMA is in fact enabled | 39 // 3. For the X-Chrome-UMA-Enabled bit, only set it if UMA is in fact enabled |
36 // for this install of Chrome. | 40 // for this install of Chrome. |
37 // 4. For the X-Client-Data header, only include non-empty variation IDs. | 41 // 4. For the X-Client-Data header, only include non-empty variation IDs. |
38 if (incognito || !ShouldAppendHeaders(url)) | 42 if (incognito || !ShouldAppendHeaders(url)) |
39 return; | 43 return; |
40 | 44 |
41 if (uma_enabled) | 45 if (uma_enabled) |
42 headers->SetHeaderIfMissing("X-Chrome-UMA-Enabled", "1"); | 46 headers->SetHeaderIfMissing("X-Chrome-UMA-Enabled", "1"); |
43 | 47 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 variation_ids_header_ = hashed; | 175 variation_ids_header_ = hashed; |
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 |
| 185 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) |
| 186 return false; |
| 187 |
| 188 // Some domains don't have international TLD extensions, so testing for them |
| 189 // is very straight forward. |
| 190 const std::string host = url.host(); |
| 191 if (EndsWith(host, ".doubleclick.net", false) || |
| 192 EndsWith(host, ".googlesyndication.com", false) || |
| 193 LowerCaseEqualsASCII(host, "www.googleadservices.com")) { |
| 194 return true; |
| 195 } |
| 196 |
181 // The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>. | 197 // The below mirrors logic in IsGoogleDomainUrl(), but for youtube.<TLD>. |
182 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) | |
183 return false; | |
184 | |
185 const std::string host = url.host(); | |
186 const size_t tld_length = net::registry_controlled_domains::GetRegistryLength( | 198 const size_t tld_length = net::registry_controlled_domains::GetRegistryLength( |
187 host, | 199 host, |
188 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, | 200 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, |
189 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); | 201 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
190 if ((tld_length == 0) || (tld_length == std::string::npos)) | 202 if ((tld_length == 0) || (tld_length == std::string::npos)) |
191 return false; | 203 return false; |
192 | 204 |
193 const std::string host_minus_tld(host, 0, host.length() - tld_length); | 205 const std::string host_minus_tld(host, 0, host.length() - tld_length); |
194 return LowerCaseEqualsASCII(host_minus_tld, "youtube.") || | 206 return LowerCaseEqualsASCII(host_minus_tld, "youtube.") || |
195 EndsWith(host_minus_tld, ".youtube.", false); | 207 EndsWith(host_minus_tld, ".youtube.", false); |
196 } | 208 } |
197 | 209 |
198 } // namespace chrome_variations | 210 } // namespace chrome_variations |
OLD | NEW |