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

Side by Side Diff: components/variations/net/variations_http_header_provider.cc

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

Powered by Google App Engine
This is Rietveld 408576698