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

Side by Side Diff: chrome/common/variations/variations_util.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 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 "chrome/common/variations/variations_util.h" 5 #include "chrome/common/variations/variations_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/string_split.h"
10 #include "chrome/common/child_process_logging.h" 11 #include "chrome/common/child_process_logging.h"
11 #include "chrome/common/crash_keys.h" 12 #include "chrome/common/crash_keys.h"
12 #include "components/variations/active_field_trials.h" 13 #include "components/variations/active_field_trials.h"
14 #include "components/variations/variations_associated_data.h"
15 #include "net/base/escape.h"
13 16
14 namespace chrome_variations { 17 namespace chrome_variations {
15 18
16 void SetChildProcessLoggingVariationList() { 19 void SetChildProcessLoggingVariationList() {
17 std::vector<std::string> experiment_strings; 20 std::vector<std::string> experiment_strings;
18 variations::GetFieldTrialActiveGroupIdsAsStrings(&experiment_strings); 21 variations::GetFieldTrialActiveGroupIdsAsStrings(&experiment_strings);
19 crash_keys::SetVariationsList(experiment_strings); 22 crash_keys::SetVariationsList(experiment_strings);
20 } 23 }
21 24
25 bool AssociateParamsFromString(const std::string& varations_string) {
26 // Format: Trial1.Group1:k1/v1/k2/v2,Trial2.Group2:k1/v1/k2/v2
27 std::vector<std::string> experiment_groups;
28 base::SplitString(varations_string, ',', &experiment_groups);
29 for (const auto& experiment_group : experiment_groups) {
30 std::vector<std::string> experiment;
31 base::SplitString(experiment_group, ':', &experiment);
32 if (experiment.size() != 2)
33 continue;
34
35 std::vector<std::string> group_parts;
36 base::SplitString(experiment[0], '.', &group_parts);
37 if (group_parts.size() != 2)
38 continue;
39
40 std::vector<std::string> key_values;
41 base::SplitString(experiment[1], '/', &key_values);
42 if (key_values.size() % 2 == 0) {
43 std::map <std::string, std::string> params;
44 for (int i = 0; i < key_values.size(); i += 2) {
45 std::string key = net::UnescapeURLComponent(key_values[i],
46 net::UnescapeRule::URL_SPECIAL_CHARS);
47 std::string value = net::UnescapeURLComponent(key_values[i + 1],
48 net::UnescapeRule::URL_SPECIAL_CHARS);
49 params[key] = value;
50 }
51 std::string trial = net::UnescapeURLComponent(group_parts[0],
52 net::UnescapeRule::URL_SPECIAL_CHARS);
Alexei Svitkine (slow) 2015/04/29 21:08:10 Indent 2 more. You can also run "git cl format" to
danduong 2015/04/29 21:28:14 Done.
53 std::string group = net::UnescapeURLComponent(group_parts[1],
54 net::UnescapeRule::URL_SPECIAL_CHARS);
55 variations::AssociateVariationParams(trial, group, params);
56 }
57 }
58 return true;
Alexei Svitkine (slow) 2015/04/29 21:08:10 You always return true. Perhaps we should return f
danduong 2015/04/29 21:28:14 Done.
59 }
60
22 } // namespace chrome_variations 61 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « chrome/common/variations/variations_util.h ('k') | chrome/common/variations/variations_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698