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