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

Side by Side Diff: components/variations/variations_associated_data.cc

Issue 2182553002: Add other variations (with ids) for NTPSnippets to chrome://flags (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Alexei's comments #2 Created 4 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_associated_data.h" 5 #include "components/variations/variations_associated_data.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/strings/string_split.h"
15 #include "components/variations/variations_http_header_provider.h"
14 16
15 namespace variations { 17 namespace variations {
16 18
17 namespace { 19 namespace {
18 20
19 const char kGroupTesting[] = "Testing"; 21 const char kGroupTesting[] = "Testing";
20 22
21 // The internal singleton accessor for the map, used to keep it thread-safe. 23 // The internal singleton accessor for the map, used to keep it thread-safe.
22 class GroupMapAccessor { 24 class GroupMapAccessor {
23 public: 25 public:
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 ~VariationsParamAssociator() {} 161 ~VariationsParamAssociator() {}
160 162
161 base::Lock lock_; 163 base::Lock lock_;
162 std::map<VariationKey, VariationParams> variation_params_; 164 std::map<VariationKey, VariationParams> variation_params_;
163 165
164 DISALLOW_COPY_AND_ASSIGN(VariationsParamAssociator); 166 DISALLOW_COPY_AND_ASSIGN(VariationsParamAssociator);
165 }; 167 };
166 168
167 } // namespace 169 } // namespace
168 170
171 VariationsHttpHeaderProvider* ForceVariationIDsForHttpHeaders(
172 std::vector<std::string> variation_ids,
173 std::string command_line_variation_ids) {
Alexei Svitkine (slow) 2016/07/26 16:43:35 Pass the string by const& and the |variations_ids|
jkrcal 2016/07/27 10:09:03 Huh, a silly mistake. Done.
174 if (!variation_ids.empty()) {
175 // Combine the variation ids from chrome://flags with the ones from the
Alexei Svitkine (slow) 2016/07/26 16:43:35 Seems strange to mention chrome://flags here, sinc
jkrcal 2016/07/27 10:09:04 Done. (Actually, had a bug there, wanted to check
176 // command-line flag.
177 std::vector<std::string> variation_ids_flags =
178 base::SplitString(command_line_variation_ids, ",",
179 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
180 variation_ids.insert(variation_ids.end(), variation_ids_flags.begin(),
181 variation_ids_flags.end());
182 }
183
184 if (!variation_ids.empty()) {
185 // Create default variation ids which will always be included in the
186 // X-Client-Data request header.
187 VariationsHttpHeaderProvider* provider =
188 VariationsHttpHeaderProvider::GetInstance();
189 CHECK(provider->SetDefaultVariationIds(variation_ids))
190 << "Invalid list of variation ids specified";
191 return provider;
192 }
193 return nullptr;
Alexei Svitkine (slow) 2016/07/26 16:43:35 Seems like the previous code actually had a bug, s
jkrcal 2016/07/27 10:09:04 Done.
194 }
195
169 void AssociateGoogleVariationID(IDCollectionKey key, 196 void AssociateGoogleVariationID(IDCollectionKey key,
170 const std::string& trial_name, 197 const std::string& trial_name,
171 const std::string& group_name, 198 const std::string& group_name,
172 VariationID id) { 199 VariationID id) {
173 GroupMapAccessor::GetInstance()->AssociateID( 200 GroupMapAccessor::GetInstance()->AssociateID(
174 key, MakeActiveGroupId(trial_name, group_name), id, false); 201 key, MakeActiveGroupId(trial_name, group_name), id, false);
175 } 202 }
176 203
177 void AssociateGoogleVariationIDForce(IDCollectionKey key, 204 void AssociateGoogleVariationIDForce(IDCollectionKey key,
178 const std::string& trial_name, 205 const std::string& trial_name,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); 305 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting();
279 } 306 }
280 307
281 void ClearAllVariationParams() { 308 void ClearAllVariationParams() {
282 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting(); 309 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting();
283 } 310 }
284 311
285 } // namespace testing 312 } // namespace testing
286 313
287 } // namespace variations 314 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/variations_associated_data.h ('k') | components/variations/variations_http_header_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698