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 <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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 130 |
131 base::AutoLock scoped_lock(lock_); | 131 base::AutoLock scoped_lock(lock_); |
132 if (new_id != EMPTY_ID) | 132 if (new_id != EMPTY_ID) |
133 variation_ids_set_.insert(new_id); | 133 variation_ids_set_.insert(new_id); |
134 if (new_trigger_id != EMPTY_ID) | 134 if (new_trigger_id != EMPTY_ID) |
135 variation_trigger_ids_set_.insert(new_trigger_id); | 135 variation_trigger_ids_set_.insert(new_trigger_id); |
136 | 136 |
137 UpdateVariationIDsHeaderValue(); | 137 UpdateVariationIDsHeaderValue(); |
138 } | 138 } |
139 | 139 |
140 void VariationsHttpHeaderProvider::OnSyntheticTrialsChanged( | |
141 const std::vector<metrics::SyntheticTrialGroup>& groups) { | |
142 base::AutoLock scoped_lock(lock_); | |
143 | |
144 synthetic_variation_ids_set_.clear(); | |
145 for (const metrics::SyntheticTrialGroup& group : groups) { | |
146 const VariationID id = | |
147 GetGoogleVariationIDFromHashes(GOOGLE_WEB_PROPERTIES, group.id); | |
jwd
2014/10/31 18:50:26
Are there no plans to support triggering experimen
Alexei Svitkine (slow)
2014/10/31 18:51:06
Not currently. The goal is to enable analysis, not
| |
148 if (id != EMPTY_ID) | |
149 synthetic_variation_ids_set_.insert(id); | |
150 } | |
151 UpdateVariationIDsHeaderValue(); | |
152 } | |
153 | |
140 void VariationsHttpHeaderProvider::InitVariationIDsCacheIfNeeded() { | 154 void VariationsHttpHeaderProvider::InitVariationIDsCacheIfNeeded() { |
141 base::AutoLock scoped_lock(lock_); | 155 base::AutoLock scoped_lock(lock_); |
142 if (variation_ids_cache_initialized_) | 156 if (variation_ids_cache_initialized_) |
143 return; | 157 return; |
144 | 158 |
145 // Register for additional cache updates. This is done first to avoid a race | 159 // Register for additional cache updates. This is done first to avoid a race |
146 // that could cause registered FieldTrials to be missed. | 160 // that could cause registered FieldTrials to be missed. |
147 DCHECK(base::MessageLoop::current()); | 161 DCHECK(base::MessageLoop::current()); |
148 base::FieldTrialList::AddObserver(this); | 162 base::FieldTrialList::AddObserver(this); |
149 | 163 |
(...skipping 29 matching lines...) Expand all Loading... | |
179 } | 193 } |
180 | 194 |
181 void VariationsHttpHeaderProvider::UpdateVariationIDsHeaderValue() { | 195 void VariationsHttpHeaderProvider::UpdateVariationIDsHeaderValue() { |
182 lock_.AssertAcquired(); | 196 lock_.AssertAcquired(); |
183 | 197 |
184 // The header value is a serialized protobuffer of Variation IDs which is | 198 // The header value is a serialized protobuffer of Variation IDs which is |
185 // base64 encoded before transmitting as a string. | 199 // base64 encoded before transmitting as a string. |
186 variation_ids_header_.clear(); | 200 variation_ids_header_.clear(); |
187 | 201 |
188 if (variation_ids_set_.empty() && default_variation_ids_set_.empty() && | 202 if (variation_ids_set_.empty() && default_variation_ids_set_.empty() && |
189 variation_trigger_ids_set_.empty() && default_trigger_id_set_.empty()) { | 203 variation_trigger_ids_set_.empty() && default_trigger_id_set_.empty() && |
204 synthetic_variation_ids_set_.empty()) { | |
190 return; | 205 return; |
191 } | 206 } |
192 | 207 |
193 // This is the bottleneck for the creation of the header, so validate the size | 208 // This is the bottleneck for the creation of the header, so validate the size |
194 // here. Force a hard maximum on the ID count in case the Variations server | 209 // here. Force a hard maximum on the ID count in case the Variations server |
195 // returns too many IDs and DOSs receiving servers with large requests. | 210 // returns too many IDs and DOSs receiving servers with large requests. |
196 const size_t total_id_count = | 211 const size_t total_id_count = |
197 variation_ids_set_.size() + variation_trigger_ids_set_.size(); | 212 variation_ids_set_.size() + variation_trigger_ids_set_.size(); |
198 DCHECK_LE(total_id_count, 10U); | 213 DCHECK_LE(total_id_count, 10U); |
199 UMA_HISTOGRAM_COUNTS_100("Variations.Headers.ExperimentCount", | 214 UMA_HISTOGRAM_COUNTS_100("Variations.Headers.ExperimentCount", |
200 total_id_count); | 215 total_id_count); |
201 if (total_id_count > 20) | 216 if (total_id_count > 20) |
202 return; | 217 return; |
203 | 218 |
204 // Merge the two sets of experiment ids. | 219 // Merge the two sets of experiment ids. |
205 std::set<VariationID> all_variation_ids_set = default_variation_ids_set_; | 220 std::set<VariationID> all_variation_ids_set = default_variation_ids_set_; |
206 for (std::set<VariationID>::const_iterator it = variation_ids_set_.begin(); | 221 for (VariationID id : variation_ids_set_) |
207 it != variation_ids_set_.end(); ++it) { | 222 all_variation_ids_set.insert(id); |
208 all_variation_ids_set.insert(*it); | 223 for (VariationID id : synthetic_variation_ids_set_) |
209 } | 224 all_variation_ids_set.insert(id); |
210 ClientVariations proto; | |
211 for (std::set<VariationID>::const_iterator it = all_variation_ids_set.begin(); | |
212 it != all_variation_ids_set.end(); ++it) { | |
213 proto.add_variation_id(*it); | |
214 } | |
215 | 225 |
216 std::set<VariationID> all_trigger_ids_set = default_trigger_id_set_; | 226 std::set<VariationID> all_trigger_ids_set = default_trigger_id_set_; |
217 for (std::set<VariationID>::const_iterator it = | 227 for (VariationID id : variation_trigger_ids_set_) |
218 variation_trigger_ids_set_.begin(); | 228 all_trigger_ids_set.insert(id); |
219 it != variation_trigger_ids_set_.end(); ++it) { | 229 |
220 all_trigger_ids_set.insert(*it); | 230 ClientVariations proto; |
221 } | 231 for (VariationID id : all_variation_ids_set) |
222 for (std::set<VariationID>::const_iterator it = all_trigger_ids_set.begin(); | 232 proto.add_variation_id(id); |
223 it != all_trigger_ids_set.end(); ++it) { | 233 for (VariationID id : all_trigger_ids_set) |
224 proto.add_trigger_variation_id(*it); | 234 proto.add_trigger_variation_id(id); |
225 } | |
226 | 235 |
227 std::string serialized; | 236 std::string serialized; |
228 proto.SerializeToString(&serialized); | 237 proto.SerializeToString(&serialized); |
229 | 238 |
230 std::string hashed; | 239 std::string hashed; |
231 base::Base64Encode(serialized, &hashed); | 240 base::Base64Encode(serialized, &hashed); |
232 // If successful, swap the header value with the new one. | 241 // If successful, swap the header value with the new one. |
233 // Note that the list of IDs and the header could be temporarily out of sync | 242 // Note that the list of IDs and the header could be temporarily out of sync |
234 // if IDs are added as the header is recreated. The receiving servers are OK | 243 // if IDs are added as the header is recreated. The receiving servers are OK |
235 // with such discrepancies. | 244 // with such discrepancies. |
(...skipping 16 matching lines...) Expand all Loading... | |
252 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) { | 261 for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) { |
253 if (EndsWith(host, kSuffixesToSetHeadersFor[i], false)) | 262 if (EndsWith(host, kSuffixesToSetHeadersFor[i], false)) |
254 return true; | 263 return true; |
255 } | 264 } |
256 | 265 |
257 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN, | 266 return google_util::IsYoutubeDomainUrl(url, google_util::ALLOW_SUBDOMAIN, |
258 google_util::ALLOW_NON_STANDARD_PORTS); | 267 google_util::ALLOW_NON_STANDARD_PORTS); |
259 } | 268 } |
260 | 269 |
261 } // namespace variations | 270 } // namespace variations |
OLD | NEW |