[email protected] | 71011c168 | 2014-07-09 17:19:16 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 5 | #include "components/variations/variations_http_header_provider.h" |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 6 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
horo | e09b6c8 | 2014-11-01 02:08:28 | [diff] [blame] | 9 | #include <set> |
| 10 | #include <string> |
[email protected] | 1bd918d | 2013-10-13 18:23:09 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 13 | #include "base/base64.h" |
| 14 | #include "base/memory/singleton.h" |
asvitkine | 454600f | 2015-06-16 16:34:50 | [diff] [blame] | 15 | #include "base/metrics/histogram_macros.h" |
[email protected] | 1bd918d | 2013-10-13 18:23:09 | [diff] [blame] | 16 | #include "base/strings/string_number_conversions.h" |
| 17 | #include "base/strings/string_split.h" |
[email protected] | 7f8a993 | 2013-07-26 20:43:34 | [diff] [blame] | 18 | #include "base/strings/string_util.h" |
fdoray | cddcf0e | 2016-06-23 21:20:30 | [diff] [blame] | 19 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | ea15bd5 | 2014-07-14 22:42:50 | [diff] [blame] | 20 | #include "components/variations/proto/client_variations.pb.h" |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 21 | |
[email protected] | 71011c168 | 2014-07-09 17:19:16 | [diff] [blame] | 22 | namespace variations { |
[email protected] | ab778079 | 2013-01-10 01:26:09 | [diff] [blame] | 23 | |
Jun Cai | f3aba7f9 | 2018-07-12 16:52:40 | [diff] [blame] | 24 | // The following documents how adding/removing http headers for web content |
| 25 | // requests are implemented when Network Service is enabled or not enabled. |
| 26 | // |
| 27 | // When Network Service is not enabled, adding headers is implemented in |
| 28 | // ChromeResourceDispatcherHostDelegate::RequestBeginning() by calling |
| 29 | // variations::AppendVariationHeaders(), and removing headers is implemented in |
| 30 | // ChromeNetworkDelegate::OnBeforeRedirect() by calling |
| 31 | // variations::StripVariationHeaderIfNeeded(). |
| 32 | // |
| 33 | // When Network Service is enabled, adding/removing headers is implemented by |
| 34 | // request consumers, and how it is implemented depends on the request type. |
| 35 | // There are three cases: |
| 36 | // 1. Subresources request in renderer, it is implemented |
| 37 | // in URLLoaderThrottleProviderImpl::CreateThrottles() by adding a |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 38 | // GoogleURLLoaderThrottle to a content::URLLoaderThrottle vector. |
Jun Cai | f3aba7f9 | 2018-07-12 16:52:40 | [diff] [blame] | 39 | // 2. Navigations/Downloads request in browser, it is implemented in |
| 40 | // ChromeContentBrowserClient::CreateURLLoaderThrottles() by also adding a |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 41 | // GoogleURLLoaderThrottle to a content::URLLoaderThrottle vector. |
Jun Cai | f3aba7f9 | 2018-07-12 16:52:40 | [diff] [blame] | 42 | // 3. SimpleURLLoader in browser, it is implemented in a SimpleURLLoader wrapper |
Takashi Toyoshima | f3ceca9 | 2019-02-04 07:49:05 | [diff] [blame] | 43 | // function variations::CreateSimpleURLLoaderWithVariationsHeader(). |
Jun Cai | f3aba7f9 | 2018-07-12 16:52:40 | [diff] [blame] | 44 | |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 45 | // static |
[email protected] | ab778079 | 2013-01-10 01:26:09 | [diff] [blame] | 46 | VariationsHttpHeaderProvider* VariationsHttpHeaderProvider::GetInstance() { |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 47 | return base::Singleton<VariationsHttpHeaderProvider>::get(); |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 48 | } |
| 49 | |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 50 | std::string VariationsHttpHeaderProvider::GetClientDataHeader( |
| 51 | bool is_signed_in) { |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 52 | // Lazily initialize the header, if not already done, before attempting to |
| 53 | // transmit it. |
| 54 | InitVariationIDsCacheIfNeeded(); |
[email protected] | ab778079 | 2013-01-10 01:26:09 | [diff] [blame] | 55 | |
| 56 | std::string variation_ids_header_copy; |
| 57 | { |
| 58 | base::AutoLock scoped_lock(lock_); |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 59 | variation_ids_header_copy = is_signed_in |
| 60 | ? cached_variation_ids_header_signed_in_ |
| 61 | : cached_variation_ids_header_; |
[email protected] | ab778079 | 2013-01-10 01:26:09 | [diff] [blame] | 62 | } |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 63 | return variation_ids_header_copy; |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 64 | } |
| 65 | |
asvitkine | 35ba647 | 2015-12-18 23:52:33 | [diff] [blame] | 66 | std::string VariationsHttpHeaderProvider::GetVariationsString() { |
| 67 | InitVariationIDsCacheIfNeeded(); |
| 68 | |
| 69 | // Construct a space-separated string with leading and trailing spaces from |
| 70 | // the variations set. Note: The ids in it will be in sorted order per the |
| 71 | // std::set contract. |
| 72 | std::string ids_string = " "; |
| 73 | { |
| 74 | base::AutoLock scoped_lock(lock_); |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 75 | for (const VariationIDEntry& entry : GetAllVariationIds()) { |
| 76 | if (entry.second == GOOGLE_WEB_PROPERTIES) { |
Raul Tambre | f88e510 | 2019-02-06 10:54:03 | [diff] [blame] | 77 | ids_string.append(base::NumberToString(entry.first)); |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 78 | ids_string.push_back(' '); |
| 79 | } |
asvitkine | 35ba647 | 2015-12-18 23:52:33 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | return ids_string; |
| 83 | } |
| 84 | |
Roger McFarlane | d4aaef31 | 2019-02-19 17:26:44 | [diff] [blame] | 85 | std::vector<VariationID> VariationsHttpHeaderProvider::GetVariationsVector( |
| 86 | IDCollectionKey key) { |
| 87 | InitVariationIDsCacheIfNeeded(); |
| 88 | |
| 89 | // Get all the active variation ids while holding the lock. |
| 90 | std::set<VariationIDEntry> all_variation_ids; |
| 91 | { |
| 92 | base::AutoLock scoped_lock(lock_); |
| 93 | all_variation_ids = GetAllVariationIds(); |
| 94 | } |
| 95 | |
| 96 | // Copy the requested variations to the output vector. Note that the ids will |
| 97 | // be in sorted order because they're coming from a std::set. |
| 98 | std::vector<VariationID> result; |
| 99 | result.reserve(all_variation_ids.size()); |
| 100 | for (const VariationIDEntry& entry : all_variation_ids) { |
| 101 | if (entry.second == key) |
| 102 | result.push_back(entry.first); |
| 103 | } |
| 104 | return result; |
| 105 | } |
| 106 | |
Alexei Svitkine | 105f942e | 2018-02-17 02:53:48 | [diff] [blame] | 107 | VariationsHttpHeaderProvider::ForceIdsResult |
| 108 | VariationsHttpHeaderProvider::ForceVariationIds( |
| 109 | const std::vector<std::string>& variation_ids, |
| 110 | const std::string& command_line_variation_ids) { |
| 111 | default_variation_ids_set_.clear(); |
| 112 | |
| 113 | if (!AddDefaultVariationIds(variation_ids)) |
| 114 | return ForceIdsResult::INVALID_VECTOR_ENTRY; |
| 115 | |
jkrcal | bf07337 | 2016-07-29 07:21:31 | [diff] [blame] | 116 | if (!command_line_variation_ids.empty()) { |
Alexei Svitkine | 105f942e | 2018-02-17 02:53:48 | [diff] [blame] | 117 | std::vector<std::string> variation_ids_from_command_line = |
jkrcal | bf07337 | 2016-07-29 07:21:31 | [diff] [blame] | 118 | base::SplitString(command_line_variation_ids, ",", |
| 119 | base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
Alexei Svitkine | 105f942e | 2018-02-17 02:53:48 | [diff] [blame] | 120 | if (!AddDefaultVariationIds(variation_ids_from_command_line)) |
| 121 | return ForceIdsResult::INVALID_SWITCH_ENTRY; |
jkrcal | bf07337 | 2016-07-29 07:21:31 | [diff] [blame] | 122 | } |
Alexei Svitkine | 105f942e | 2018-02-17 02:53:48 | [diff] [blame] | 123 | return ForceIdsResult::SUCCESS; |
[email protected] | 1bd918d | 2013-10-13 18:23:09 | [diff] [blame] | 124 | } |
| 125 | |
Jun Cai | 0e56863 | 2018-08-09 02:05:33 | [diff] [blame] | 126 | void VariationsHttpHeaderProvider::AddObserver(Observer* observer) { |
| 127 | observer_list_.AddObserver(observer); |
| 128 | } |
| 129 | |
| 130 | void VariationsHttpHeaderProvider::RemoveObserver(Observer* observer) { |
| 131 | observer_list_.RemoveObserver(observer); |
| 132 | } |
| 133 | |
asvitkine | b4ed7868 | 2015-03-12 18:18:54 | [diff] [blame] | 134 | void VariationsHttpHeaderProvider::ResetForTesting() { |
| 135 | base::AutoLock scoped_lock(lock_); |
| 136 | |
| 137 | // Stop observing field trials so that it can be restarted when this is |
| 138 | // re-inited. Note: This is a no-op if this is not currently observing. |
| 139 | base::FieldTrialList::RemoveObserver(this); |
| 140 | variation_ids_cache_initialized_ = false; |
Olivier Robin | 9edc20f | 2018-10-03 09:51:42 | [diff] [blame] | 141 | variation_ids_set_.clear(); |
| 142 | default_variation_ids_set_.clear(); |
| 143 | synthetic_variation_ids_set_.clear(); |
| 144 | cached_variation_ids_header_.clear(); |
| 145 | cached_variation_ids_header_signed_in_.clear(); |
asvitkine | b4ed7868 | 2015-03-12 18:18:54 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | ab778079 | 2013-01-10 01:26:09 | [diff] [blame] | 148 | VariationsHttpHeaderProvider::VariationsHttpHeaderProvider() |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 149 | : variation_ids_cache_initialized_(false) {} |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 150 | |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 151 | VariationsHttpHeaderProvider::~VariationsHttpHeaderProvider() {} |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 152 | |
[email protected] | ab778079 | 2013-01-10 01:26:09 | [diff] [blame] | 153 | void VariationsHttpHeaderProvider::OnFieldTrialGroupFinalized( |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 154 | const std::string& trial_name, |
| 155 | const std::string& group_name) { |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 156 | base::AutoLock scoped_lock(lock_); |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 157 | const size_t old_size = variation_ids_set_.size(); |
| 158 | CacheVariationsId(trial_name, group_name, GOOGLE_WEB_PROPERTIES); |
| 159 | CacheVariationsId(trial_name, group_name, GOOGLE_WEB_PROPERTIES_SIGNED_IN); |
| 160 | CacheVariationsId(trial_name, group_name, GOOGLE_WEB_PROPERTIES_TRIGGER); |
| 161 | if (variation_ids_set_.size() != old_size) |
| 162 | UpdateVariationIDsHeaderValue(); |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 163 | } |
| 164 | |
asvitkine | e0dbdbe | 2014-10-31 21:59:57 | [diff] [blame] | 165 | void VariationsHttpHeaderProvider::OnSyntheticTrialsChanged( |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 166 | const std::vector<SyntheticTrialGroup>& groups) { |
asvitkine | e0dbdbe | 2014-10-31 21:59:57 | [diff] [blame] | 167 | base::AutoLock scoped_lock(lock_); |
| 168 | |
| 169 | synthetic_variation_ids_set_.clear(); |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 170 | for (const SyntheticTrialGroup& group : groups) { |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 171 | VariationID id = |
asvitkine | e0dbdbe | 2014-10-31 21:59:57 | [diff] [blame] | 172 | GetGoogleVariationIDFromHashes(GOOGLE_WEB_PROPERTIES, group.id); |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 173 | if (id != EMPTY_ID) { |
| 174 | synthetic_variation_ids_set_.insert( |
| 175 | VariationIDEntry(id, GOOGLE_WEB_PROPERTIES)); |
| 176 | } |
| 177 | id = GetGoogleVariationIDFromHashes(GOOGLE_WEB_PROPERTIES_SIGNED_IN, |
| 178 | group.id); |
| 179 | if (id != EMPTY_ID) { |
| 180 | synthetic_variation_ids_set_.insert( |
| 181 | VariationIDEntry(id, GOOGLE_WEB_PROPERTIES_SIGNED_IN)); |
| 182 | } |
asvitkine | e0dbdbe | 2014-10-31 21:59:57 | [diff] [blame] | 183 | } |
| 184 | UpdateVariationIDsHeaderValue(); |
| 185 | } |
| 186 | |
[email protected] | ab778079 | 2013-01-10 01:26:09 | [diff] [blame] | 187 | void VariationsHttpHeaderProvider::InitVariationIDsCacheIfNeeded() { |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 188 | base::AutoLock scoped_lock(lock_); |
| 189 | if (variation_ids_cache_initialized_) |
| 190 | return; |
| 191 | |
| 192 | // Register for additional cache updates. This is done first to avoid a race |
| 193 | // that could cause registered FieldTrials to be missed. |
fdoray | cddcf0e | 2016-06-23 21:20:30 | [diff] [blame] | 194 | DCHECK(base::ThreadTaskRunnerHandle::IsSet()); |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 195 | base::FieldTrialList::AddObserver(this); |
| 196 | |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 197 | base::FieldTrial::ActiveGroups initial_groups; |
| 198 | base::FieldTrialList::GetActiveFieldTrialGroups(&initial_groups); |
asvitkine | 35ba647 | 2015-12-18 23:52:33 | [diff] [blame] | 199 | |
| 200 | for (const auto& entry : initial_groups) { |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 201 | CacheVariationsId(entry.trial_name, entry.group_name, |
| 202 | GOOGLE_WEB_PROPERTIES); |
| 203 | CacheVariationsId(entry.trial_name, entry.group_name, |
| 204 | GOOGLE_WEB_PROPERTIES_SIGNED_IN); |
| 205 | CacheVariationsId(entry.trial_name, entry.group_name, |
| 206 | GOOGLE_WEB_PROPERTIES_TRIGGER); |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 207 | } |
| 208 | UpdateVariationIDsHeaderValue(); |
| 209 | |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 210 | variation_ids_cache_initialized_ = true; |
| 211 | } |
| 212 | |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 213 | void VariationsHttpHeaderProvider::CacheVariationsId( |
| 214 | const std::string& trial_name, |
| 215 | const std::string& group_name, |
| 216 | IDCollectionKey key) { |
| 217 | const VariationID id = GetGoogleVariationID(key, trial_name, group_name); |
| 218 | if (id != EMPTY_ID) |
| 219 | variation_ids_set_.insert(VariationIDEntry(id, key)); |
| 220 | } |
| 221 | |
[email protected] | ab778079 | 2013-01-10 01:26:09 | [diff] [blame] | 222 | void VariationsHttpHeaderProvider::UpdateVariationIDsHeaderValue() { |
| 223 | lock_.AssertAcquired(); |
| 224 | |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 225 | // The header value is a serialized protobuffer of Variation IDs which is |
| 226 | // base64 encoded before transmitting as a string. |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 227 | cached_variation_ids_header_.clear(); |
| 228 | cached_variation_ids_header_signed_in_.clear(); |
[email protected] | 1bd918d | 2013-10-13 18:23:09 | [diff] [blame] | 229 | |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 230 | // If successful, swap the header value with the new one. |
| 231 | // Note that the list of IDs and the header could be temporarily out of sync |
| 232 | // if IDs are added as the header is recreated. The receiving servers are OK |
| 233 | // with such discrepancies. |
| 234 | cached_variation_ids_header_ = GenerateBase64EncodedProto(false); |
| 235 | cached_variation_ids_header_signed_in_ = GenerateBase64EncodedProto(true); |
Jun Cai | 0e56863 | 2018-08-09 02:05:33 | [diff] [blame] | 236 | |
| 237 | for (auto& observer : observer_list_) { |
| 238 | observer.VariationIdsHeaderUpdated(cached_variation_ids_header_, |
| 239 | cached_variation_ids_header_signed_in_); |
| 240 | } |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | std::string VariationsHttpHeaderProvider::GenerateBase64EncodedProto( |
| 244 | bool is_signed_in) { |
| 245 | std::set<VariationIDEntry> all_variation_ids_set = GetAllVariationIds(); |
| 246 | |
| 247 | ClientVariations proto; |
| 248 | for (const VariationIDEntry& entry : all_variation_ids_set) { |
| 249 | switch (entry.second) { |
| 250 | case GOOGLE_WEB_PROPERTIES_SIGNED_IN: |
| 251 | if (is_signed_in) |
| 252 | proto.add_variation_id(entry.first); |
| 253 | break; |
| 254 | case GOOGLE_WEB_PROPERTIES: |
| 255 | proto.add_variation_id(entry.first); |
| 256 | break; |
| 257 | case GOOGLE_WEB_PROPERTIES_TRIGGER: |
| 258 | proto.add_trigger_variation_id(entry.first); |
| 259 | break; |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 260 | case ID_COLLECTION_COUNT: |
Marc Treib | 95d3e773 | 2019-04-10 07:00:24 | [diff] [blame] | 261 | // This case included to get full enum coverage for switch, so that |
| 262 | // new enums introduce compiler warnings. Nothing to do for this. |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 263 | break; |
| 264 | } |
[email protected] | 8c2c544 | 2014-04-04 18:55:29 | [diff] [blame] | 265 | } |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 266 | |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 267 | const size_t total_id_count = |
| 268 | proto.variation_id_size() + proto.trigger_variation_id_size(); |
| 269 | |
| 270 | if (total_id_count == 0) |
| 271 | return std::string(); |
| 272 | |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 273 | // This is the bottleneck for the creation of the header, so validate the size |
| 274 | // here. Force a hard maximum on the ID count in case the Variations server |
| 275 | // returns too many IDs and DOSs receiving servers with large requests. |
Alexei Svitkine | eac4eea | 2019-03-22 17:24:39 | [diff] [blame] | 276 | DCHECK_LE(total_id_count, 35U); |
[email protected] | a27ae2a | 2014-08-01 16:17:52 | [diff] [blame] | 277 | UMA_HISTOGRAM_COUNTS_100("Variations.Headers.ExperimentCount", |
| 278 | total_id_count); |
Alexei Svitkine | eac4eea | 2019-03-22 17:24:39 | [diff] [blame] | 279 | if (total_id_count > 50) |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 280 | return std::string(); |
[email protected] | 8c2c544 | 2014-04-04 18:55:29 | [diff] [blame] | 281 | |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 282 | std::string serialized; |
| 283 | proto.SerializeToString(&serialized); |
| 284 | |
| 285 | std::string hashed; |
[email protected] | 33fca12 | 2013-12-11 01:48:50 | [diff] [blame] | 286 | base::Base64Encode(serialized, &hashed); |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 287 | return hashed; |
[email protected] | bd3b471 | 2012-12-18 17:01:30 | [diff] [blame] | 288 | } |
[email protected] | ab778079 | 2013-01-10 01:26:09 | [diff] [blame] | 289 | |
Alexei Svitkine | 105f942e | 2018-02-17 02:53:48 | [diff] [blame] | 290 | bool VariationsHttpHeaderProvider::AddDefaultVariationIds( |
| 291 | const std::vector<std::string>& variation_ids) { |
| 292 | for (const std::string& entry : variation_ids) { |
| 293 | if (entry.empty()) { |
| 294 | default_variation_ids_set_.clear(); |
| 295 | return false; |
| 296 | } |
| 297 | bool trigger_id = |
| 298 | base::StartsWith(entry, "t", base::CompareCase::SENSITIVE); |
| 299 | // Remove the "t" prefix if it's there. |
| 300 | std::string trimmed_entry = trigger_id ? entry.substr(1) : entry; |
| 301 | |
| 302 | int variation_id = 0; |
| 303 | if (!base::StringToInt(trimmed_entry, &variation_id)) { |
| 304 | default_variation_ids_set_.clear(); |
| 305 | return false; |
| 306 | } |
| 307 | default_variation_ids_set_.insert(VariationIDEntry( |
| 308 | variation_id, |
| 309 | trigger_id ? GOOGLE_WEB_PROPERTIES_TRIGGER : GOOGLE_WEB_PROPERTIES)); |
| 310 | } |
| 311 | return true; |
| 312 | } |
| 313 | |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 314 | std::set<VariationsHttpHeaderProvider::VariationIDEntry> |
| 315 | VariationsHttpHeaderProvider::GetAllVariationIds() { |
asvitkine | 35ba647 | 2015-12-18 23:52:33 | [diff] [blame] | 316 | lock_.AssertAcquired(); |
| 317 | |
yutak | 3305f49d | 2016-12-13 10:32:31 | [diff] [blame] | 318 | std::set<VariationIDEntry> all_variation_ids_set = default_variation_ids_set_; |
| 319 | for (const VariationIDEntry& entry : variation_ids_set_) { |
| 320 | all_variation_ids_set.insert(entry); |
| 321 | } |
| 322 | for (const VariationIDEntry& entry : synthetic_variation_ids_set_) { |
| 323 | all_variation_ids_set.insert(entry); |
| 324 | } |
asvitkine | 35ba647 | 2015-12-18 23:52:33 | [diff] [blame] | 325 | return all_variation_ids_set; |
| 326 | } |
| 327 | |
[email protected] | 71011c168 | 2014-07-09 17:19:16 | [diff] [blame] | 328 | } // namespace variations |