| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/variations/net/variations_http_header_provider.h" | 5 #include "components/variations/net/variations_http_header_provider.h" |
| 6 | 6 |
| 7 #include <string> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/base64.h" | 10 #include "base/base64.h" |
| 10 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "components/google/core/browser/google_util.h" | 16 #include "components/google/core/browser/google_util.h" |
| 16 #include "components/variations/proto/client_variations.pb.h" | 17 #include "components/variations/proto/client_variations.pb.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 29 ".ggpht.com", | 30 ".ggpht.com", |
| 30 ".googleadservices.com", | 31 ".googleadservices.com", |
| 31 ".googleapis.com", | 32 ".googleapis.com", |
| 32 ".googlesyndication.com", | 33 ".googlesyndication.com", |
| 33 ".googleusercontent.com", | 34 ".googleusercontent.com", |
| 34 ".googlevideo.com", | 35 ".googlevideo.com", |
| 35 ".gstatic.com", | 36 ".gstatic.com", |
| 36 ".ytimg.com", | 37 ".ytimg.com", |
| 37 }; | 38 }; |
| 38 | 39 |
| 40 const char kChromeUMAEnabled[] = "X-Chrome-UMA-Enabled"; |
| 41 const char kClientData[] = "X-Client-Data"; |
| 42 |
| 39 } // namespace | 43 } // namespace |
| 40 | 44 |
| 41 VariationsHttpHeaderProvider* VariationsHttpHeaderProvider::GetInstance() { | 45 VariationsHttpHeaderProvider* VariationsHttpHeaderProvider::GetInstance() { |
| 42 return Singleton<VariationsHttpHeaderProvider>::get(); | 46 return Singleton<VariationsHttpHeaderProvider>::get(); |
| 43 } | 47 } |
| 44 | 48 |
| 45 void VariationsHttpHeaderProvider::AppendHeaders( | 49 void VariationsHttpHeaderProvider::AppendHeaders( |
| 46 const GURL& url, | 50 const GURL& url, |
| 47 bool incognito, | 51 bool incognito, |
| 48 bool uma_enabled, | 52 bool uma_enabled, |
| 49 net::HttpRequestHeaders* headers) { | 53 net::HttpRequestHeaders* headers) { |
| 50 // Note the criteria for attaching client experiment headers: | 54 // Note the criteria for attaching client experiment headers: |
| 51 // 1. We only transmit to Google owned domains which can evaluate experiments. | 55 // 1. We only transmit to Google owned domains which can evaluate experiments. |
| 52 // 1a. These include hosts which have a standard postfix such as: | 56 // 1a. These include hosts which have a standard postfix such as: |
| 53 // *.doubleclick.net or *.googlesyndication.com or | 57 // *.doubleclick.net or *.googlesyndication.com or |
| 54 // exactly www.googleadservices.com or | 58 // exactly www.googleadservices.com or |
| 55 // international TLD domains *.google.<TLD> or *.youtube.<TLD>. | 59 // international TLD domains *.google.<TLD> or *.youtube.<TLD>. |
| 56 // 2. Only transmit for non-Incognito profiles. | 60 // 2. Only transmit for non-Incognito profiles. |
| 57 // 3. For the X-Chrome-UMA-Enabled bit, only set it if UMA is in fact enabled | 61 // 3. For the X-Chrome-UMA-Enabled bit, only set it if UMA is in fact enabled |
| 58 // for this install of Chrome. | 62 // for this install of Chrome. |
| 59 // 4. For the X-Client-Data header, only include non-empty variation IDs. | 63 // 4. For the X-Client-Data header, only include non-empty variation IDs. |
| 60 if (incognito || !ShouldAppendHeaders(url)) | 64 if (incognito || !ShouldAppendHeaders(url)) |
| 61 return; | 65 return; |
| 62 | 66 |
| 63 if (uma_enabled) | 67 if (uma_enabled) |
| 64 headers->SetHeaderIfMissing("X-Chrome-UMA-Enabled", "1"); | 68 headers->SetHeaderIfMissing(kChromeUMAEnabled, "1"); |
| 65 | 69 |
| 66 // Lazily initialize the header, if not already done, before attempting to | 70 // Lazily initialize the header, if not already done, before attempting to |
| 67 // transmit it. | 71 // transmit it. |
| 68 InitVariationIDsCacheIfNeeded(); | 72 InitVariationIDsCacheIfNeeded(); |
| 69 | 73 |
| 70 std::string variation_ids_header_copy; | 74 std::string variation_ids_header_copy; |
| 71 { | 75 { |
| 72 base::AutoLock scoped_lock(lock_); | 76 base::AutoLock scoped_lock(lock_); |
| 73 variation_ids_header_copy = variation_ids_header_; | 77 variation_ids_header_copy = variation_ids_header_; |
| 74 } | 78 } |
| 75 | 79 |
| 76 if (!variation_ids_header_copy.empty()) { | 80 if (!variation_ids_header_copy.empty()) { |
| 77 // Note that prior to M33 this header was named X-Chrome-Variations. | 81 // Note that prior to M33 this header was named X-Chrome-Variations. |
| 78 headers->SetHeaderIfMissing("X-Client-Data", | 82 headers->SetHeaderIfMissing(kClientData, variation_ids_header_copy); |
| 79 variation_ids_header_copy); | |
| 80 } | 83 } |
| 81 } | 84 } |
| 82 | 85 |
| 83 bool VariationsHttpHeaderProvider::SetDefaultVariationIds( | 86 bool VariationsHttpHeaderProvider::SetDefaultVariationIds( |
| 84 const std::string& variation_ids) { | 87 const std::string& variation_ids) { |
| 85 default_variation_ids_set_.clear(); | 88 default_variation_ids_set_.clear(); |
| 86 default_trigger_id_set_.clear(); | 89 default_trigger_id_set_.clear(); |
| 87 std::vector<std::string> entries; | 90 std::vector<std::string> entries; |
| 88 base::SplitString(variation_ids, ',', &entries); | 91 base::SplitString(variation_ids, ',', &entries); |
| 89 for (std::vector<std::string>::const_iterator it = entries.begin(); | 92 for (std::vector<std::string>::const_iterator it = entries.begin(); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 const std::string host = url.host(); | 254 const std::string host = url.host(); |
| 252 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) { | 255 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) { |
| 253 if (EndsWith(host, kSuffixesToSetHeadersFor[i], false)) | 256 if (EndsWith(host, kSuffixesToSetHeadersFor[i], false)) |
| 254 return true; | 257 return true; |
| 255 } | 258 } |
| 256 | 259 |
| 257 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN, | 260 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN, |
| 258 google_util::ALLOW_NON_STANDARD_PORTS); | 261 google_util::ALLOW_NON_STANDARD_PORTS); |
| 259 } | 262 } |
| 260 | 263 |
| 264 std::vector<std::string> VariationsHttpHeaderProvider::GetVariationHeaderNames() |
| 265 const { |
| 266 std::vector<std::string> headers; |
| 267 headers.push_back(kChromeUMAEnabled); |
| 268 headers.push_back(kClientData); |
| 269 return headers; |
| 270 } |
| 271 |
| 261 } // namespace variations | 272 } // namespace variations |
| OLD | NEW |