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

Side by Side Diff: components/variations/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: Created 6 years, 2 months 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/variations_http_header_provider.h" 5 #include "components/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 18 matching lines...) Expand all
29 ".ggpht.com", 29 ".ggpht.com",
30 ".googleadservices.com", 30 ".googleadservices.com",
31 ".googleapis.com", 31 ".googleapis.com",
32 ".googlesyndication.com", 32 ".googlesyndication.com",
33 ".googleusercontent.com", 33 ".googleusercontent.com",
34 ".googlevideo.com", 34 ".googlevideo.com",
35 ".gstatic.com", 35 ".gstatic.com",
36 ".ytimg.com", 36 ".ytimg.com",
37 }; 37 };
38 38
39 // Keep in sync with service_worker_url_request_job.cc.
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 15 matching lines...) Expand all
105 } 108 }
106 if (trigger_id) 109 if (trigger_id)
107 default_trigger_id_set_.insert(variation_id); 110 default_trigger_id_set_.insert(variation_id);
108 else 111 else
109 default_variation_ids_set_.insert(variation_id); 112 default_variation_ids_set_.insert(variation_id);
110 } 113 }
111 return true; 114 return true;
112 } 115 }
113 116
114 VariationsHttpHeaderProvider::VariationsHttpHeaderProvider() 117 VariationsHttpHeaderProvider::VariationsHttpHeaderProvider()
115 : variation_ids_cache_initialized_(false) { 118 : variation_ids_cache_initialized_(false) {
michaeln 2014/10/22 22:19:40 Instead of hand coding matching values in two plac
116 } 119 }
117 120
118 VariationsHttpHeaderProvider::~VariationsHttpHeaderProvider() { 121 VariationsHttpHeaderProvider::~VariationsHttpHeaderProvider() {
119 } 122 }
120 123
121 void VariationsHttpHeaderProvider::OnFieldTrialGroupFinalized( 124 void VariationsHttpHeaderProvider::OnFieldTrialGroupFinalized(
122 const std::string& trial_name, 125 const std::string& trial_name,
123 const std::string& group_name) { 126 const std::string& group_name) {
124 VariationID new_id = 127 VariationID new_id =
125 GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, trial_name, group_name); 128 GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, trial_name, group_name);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
261 } // namespace variations 264 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698