Chromium Code Reviews| Index: chrome/common/variations/variations_util.cc |
| diff --git a/chrome/common/variations/variations_util.cc b/chrome/common/variations/variations_util.cc |
| index baf336c01653f6f4262aa52824f96ef23f82b256..f5230510e530dbea8b2a889bedc366d5c61105eb 100644 |
| --- a/chrome/common/variations/variations_util.cc |
| +++ b/chrome/common/variations/variations_util.cc |
| @@ -7,9 +7,12 @@ |
| #include <string> |
| #include <vector> |
| +#include "base/strings/string_split.h" |
| #include "chrome/common/child_process_logging.h" |
| #include "chrome/common/crash_keys.h" |
| #include "components/variations/active_field_trials.h" |
| +#include "components/variations/variations_associated_data.h" |
| +#include "net/base/escape.h" |
| namespace chrome_variations { |
| @@ -19,4 +22,40 @@ void SetChildProcessLoggingVariationList() { |
| crash_keys::SetVariationsList(experiment_strings); |
| } |
| +bool AssociateParamsFromString(const std::string& varations_string) { |
| + // Format: Trial1.Group1:k1/v1/k2/v2,Trial2.Group2:k1/v1/k2/v2 |
| + std::vector<std::string> experiment_groups; |
| + base::SplitString(varations_string, ',', &experiment_groups); |
| + for (const auto& experiment_group : experiment_groups) { |
| + std::vector<std::string> experiment; |
| + base::SplitString(experiment_group, ':', &experiment); |
| + if (experiment.size() != 2) |
| + continue; |
| + |
| + std::vector<std::string> group_parts; |
| + base::SplitString(experiment[0], '.', &group_parts); |
| + if (group_parts.size() != 2) |
| + continue; |
| + |
| + std::vector<std::string> key_values; |
| + base::SplitString(experiment[1], '/', &key_values); |
| + if (key_values.size() % 2 == 0) { |
| + std::map <std::string, std::string> params; |
| + for (int i = 0; i < key_values.size(); i += 2) { |
| + std::string key = net::UnescapeURLComponent(key_values[i], |
| + net::UnescapeRule::URL_SPECIAL_CHARS); |
| + std::string value = net::UnescapeURLComponent(key_values[i + 1], |
| + net::UnescapeRule::URL_SPECIAL_CHARS); |
| + params[key] = value; |
| + } |
| + std::string trial = net::UnescapeURLComponent(group_parts[0], |
| + 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.
|
| + std::string group = net::UnescapeURLComponent(group_parts[1], |
| + net::UnescapeRule::URL_SPECIAL_CHARS); |
| + variations::AssociateVariationParams(trial, group, params); |
| + } |
| + } |
| + 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.
|
| +} |
| + |
| } // namespace chrome_variations |