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

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: introudce ServiceWorkerContext::AddExcludedHeaderNameForFetchEvent 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 <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 "components/google/core/browser/google_util.h" 15 #include "components/google/core/browser/google_util.h"
16 #include "components/variations/proto/client_variations.pb.h" 16 #include "components/variations/proto/client_variations.pb.h"
17 #include "content/public/browser/service_worker_context.h"
Alexei Svitkine (slow) 2014/10/27 15:09:00 Hmm, I don't think we want to do this. This code
17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
18 #include "net/http/http_request_headers.h" 19 #include "net/http/http_request_headers.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 namespace variations { 22 namespace variations {
22 23
23 namespace { 24 namespace {
24 25
25 const char* kSuffixesToSetHeadersFor[] = { 26 const char* kSuffixesToSetHeadersFor[] = {
26 ".android.com", 27 ".android.com",
27 ".doubleclick.com", 28 ".doubleclick.com",
28 ".doubleclick.net", 29 ".doubleclick.net",
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 16 matching lines...) Expand all
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) {
119 content::ServiceWorkerContext::AddExcludedHeaderNameForFetchEvent(
Alexei Svitkine (slow) 2014/10/27 15:09:00 Since this code can't depend on content/ per my co
michaeln 2014/10/27 21:50:26 Sounds reasonable, maybe the ChromeResourceDispatc
horo 2014/10/28 02:35:05 Done.
120 kChromeUMAEnabled);
121 content::ServiceWorkerContext::AddExcludedHeaderNameForFetchEvent(
122 kClientData);
116 } 123 }
117 124
118 VariationsHttpHeaderProvider::~VariationsHttpHeaderProvider() { 125 VariationsHttpHeaderProvider::~VariationsHttpHeaderProvider() {
119 } 126 }
120 127
121 void VariationsHttpHeaderProvider::OnFieldTrialGroupFinalized( 128 void VariationsHttpHeaderProvider::OnFieldTrialGroupFinalized(
122 const std::string& trial_name, 129 const std::string& trial_name,
123 const std::string& group_name) { 130 const std::string& group_name) {
124 VariationID new_id = 131 VariationID new_id =
125 GetGoogleVariationID(GOOGLE_WEB_PROPERTIES, trial_name, group_name); 132 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) { 259 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) {
253 if (EndsWith(host, kSuffixesToSetHeadersFor[i], false)) 260 if (EndsWith(host, kSuffixesToSetHeadersFor[i], false))
254 return true; 261 return true;
255 } 262 }
256 263
257 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN, 264 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN,
258 google_util::ALLOW_NON_STANDARD_PORTS); 265 google_util::ALLOW_NON_STANDARD_PORTS);
259 } 266 }
260 267
261 } // namespace variations 268 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698