Chromium Code Reviews| 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 |
| 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 return false; | |
| 34 | |
| 35 std::vector<std::string> group_parts; | |
| 36 base::SplitString(experiment[0], '.', &group_parts); | |
| 37 if (group_parts.size() != 2) | |
| 38 return false; | |
| 39 | |
| 40 std::vector<std::string> key_values; | |
| 41 base::SplitString(experiment[1], '/', &key_values); | |
| 42 if (key_values.size() % 2 != 0) | |
| 43 return false; | |
| 44 | |
| 45 std::map<std::string, std::string> params; | |
| 46 for (int i = 0; i < key_values.size(); i += 2) { | |
| 47 std::string key = net::UnescapeURLComponent( | |
| 48 key_values[i], net::UnescapeRule::URL_SPECIAL_CHARS); | |
| 49 std::string value = net::UnescapeURLComponent( | |
| 50 key_values[i + 1], net::UnescapeRule::URL_SPECIAL_CHARS); | |
| 51 params[key] = value; | |
| 52 } | |
| 53 std::string trial = net::UnescapeURLComponent( | |
| 54 group_parts[0], net::UnescapeRule::URL_SPECIAL_CHARS); | |
|
Alexei Svitkine (slow)
2015/04/29 22:02:39
Nit: I think if you make a helper wrapping this ne
danduong
2015/04/29 22:17:49
Done.
| |
| 55 std::string group = net::UnescapeURLComponent( | |
| 56 group_parts[1], net::UnescapeRule::URL_SPECIAL_CHARS); | |
| 57 variations::AssociateVariationParams(trial, group, params); | |
| 58 } | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 22 } // namespace chrome_variations | 62 } // namespace chrome_variations |
| OLD | NEW |