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

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
19 namespace {
20
21 std::string EscapeValue(const std::string& value) {
22 return net::UnescapeURLComponent(value, net::UnescapeRule::URL_SPECIAL_CHARS);
23 }
24 }
Alexei Svitkine (slow) 2015/04/29 22:24:54 Nit: add // namespace and also an empty line abov
danduong 2015/04/29 22:40:47 Done.
25
16 void SetChildProcessLoggingVariationList() { 26 void SetChildProcessLoggingVariationList() {
17 std::vector<std::string> experiment_strings; 27 std::vector<std::string> experiment_strings;
18 variations::GetFieldTrialActiveGroupIdsAsStrings(&experiment_strings); 28 variations::GetFieldTrialActiveGroupIdsAsStrings(&experiment_strings);
19 crash_keys::SetVariationsList(experiment_strings); 29 crash_keys::SetVariationsList(experiment_strings);
20 } 30 }
21 31
32 bool AssociateParamsFromString(const std::string& varations_string) {
33 // Format: Trial1.Group1:k1/v1/k2/v2,Trial2.Group2:k1/v1/k2/v2
34 std::vector<std::string> experiment_groups;
35 base::SplitString(varations_string, ',', &experiment_groups);
36 for (const auto& experiment_group : experiment_groups) {
37 std::vector<std::string> experiment;
38 base::SplitString(experiment_group, ':', &experiment);
39 if (experiment.size() != 2)
40 return false;
41
42 std::vector<std::string> group_parts;
43 base::SplitString(experiment[0], '.', &group_parts);
44 if (group_parts.size() != 2)
45 return false;
46
47 std::vector<std::string> key_values;
48 base::SplitString(experiment[1], '/', &key_values);
49 if (key_values.size() % 2 != 0)
50 return false;
51
52 std::map<std::string, std::string> params;
53 for (int i = 0; i < key_values.size(); i += 2) {
brettw 2015/04/29 22:37:24 int -> size_t (will give warning on Windows).
danduong 2015/04/29 22:40:47 Done.
54 std::string key = EscapeValue(key_values[i]);
55 std::string value = EscapeValue(key_values[i + 1]);
56 params[key] = value;
57 }
58 std::string trial = EscapeValue(group_parts[0]);
59 std::string group = EscapeValue(group_parts[1]);
60 variations::AssociateVariationParams(trial, group, params);
61 }
62 return true;
63 }
64
22 } // namespace chrome_variations 65 } // 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