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

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

Issue 1090813005: Add a mechanism to force parameters of a group to a specific value. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/strings/string_split.h"
13
14 // #include "net/base/escape.h"
danduong 2015/04/29 01:09:12 Any suggestions on where this code should live? We
Alexei Svitkine (slow) 2015/04/29 15:34:24 Couple options. One is we can put this code in ch
12 15
13 namespace variations { 16 namespace variations {
14 17
15 namespace { 18 namespace {
16 19
17 // The internal singleton accessor for the map, used to keep it thread-safe. 20 // The internal singleton accessor for the map, used to keep it thread-safe.
18 class GroupMapAccessor { 21 class GroupMapAccessor {
19 public: 22 public:
20 typedef std::map<ActiveGroupId, VariationID, ActiveGroupIdCompare> 23 typedef std::map<ActiveGroupId, VariationID, ActiveGroupIdCompare>
21 GroupToIDMap; 24 GroupToIDMap;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 211 }
209 212
210 bool AssociateVariationParams( 213 bool AssociateVariationParams(
211 const std::string& trial_name, 214 const std::string& trial_name,
212 const std::string& group_name, 215 const std::string& group_name,
213 const std::map<std::string, std::string>& params) { 216 const std::map<std::string, std::string>& params) {
214 return VariationsParamAssociator::GetInstance()->AssociateVariationParams( 217 return VariationsParamAssociator::GetInstance()->AssociateVariationParams(
215 trial_name, group_name, params); 218 trial_name, group_name, params);
216 } 219 }
217 220
221 bool AssociateParamsFromString(const std::string& varations_string) {
222 // Format: Trial1.Group1:k1/v1/k2/v2,Trial2.Group2:k1/v1/k2/v2
223 std::vector<std::string> experiment_groups;
224 base::SplitString(varations_string, ',', &experiment_groups);
225 for (auto& experiment_group : experiment_groups) {
226 std::vector<std::string> experiment;
227 base::SplitString(experiment_group, ':', &experiment);
228 if (experiment.size() == 2) {
229 std::vector<std::string> group_parts;
230 base::SplitString(experiment[0], '.', &group_parts);
231 if (group_parts.size() == 2) {
232 std::vector<std::string> key_values;
233 base::SplitString(experiment[1], '/', &key_values);
234 if (key_values.size() % 2 == 0) {
235 std::map <std::string, std::string> params;
236 for (int i = 0; i < key_values.size(); i += 2) {
237 std::string key = net::UnescapeURLComponent(key_values[i],
238 net::UnescapeRule::URL_SPECIAL_CHARS);
239 std::string value = net::UnescapeURLComponent(key_values[i + 1],
240 net::UnescapeRule::URL_SPECIAL_CHARS);
241 params[key] = value;
242 }
243 std::string trial = net::UnescapeURLComponent(group_parts[0],
244 net::UnescapeRule::URL_SPECIAL_CHARS);
245 std::string group = net::UnescapeURLComponent(group_parts[1],
246 net::UnescapeRule::URL_SPECIAL_CHARS);
247 AssociateVariationParams(trial, group, params);
248 }
249 }
250 }
251 }
252 return true;
253 }
254
218 bool GetVariationParams(const std::string& trial_name, 255 bool GetVariationParams(const std::string& trial_name,
219 std::map<std::string, std::string>* params) { 256 std::map<std::string, std::string>* params) {
220 return VariationsParamAssociator::GetInstance()->GetVariationParams( 257 return VariationsParamAssociator::GetInstance()->GetVariationParams(
221 trial_name, params); 258 trial_name, params);
222 } 259 }
223 260
224 std::string GetVariationParamValue(const std::string& trial_name, 261 std::string GetVariationParamValue(const std::string& trial_name,
225 const std::string& param_name) { 262 const std::string& param_name) {
226 std::map<std::string, std::string> params; 263 std::map<std::string, std::string> params;
227 if (GetVariationParams(trial_name, &params)) { 264 if (GetVariationParams(trial_name, &params)) {
(...skipping 12 matching lines...) Expand all
240 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting(); 277 GroupMapAccessor::GetInstance()->ClearAllMapsForTesting();
241 } 278 }
242 279
243 void ClearAllVariationParams() { 280 void ClearAllVariationParams() {
244 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting(); 281 VariationsParamAssociator::GetInstance()->ClearAllParamsForTesting();
245 } 282 }
246 283
247 } // namespace testing 284 } // namespace testing
248 285
249 } // namespace variations 286 } // namespace variations
OLDNEW
« no previous file with comments | « components/variations/variations_associated_data.h ('k') | components/variations/variations_associated_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698