| Index: components/variations/variations_associated_data.cc
|
| diff --git a/components/variations/variations_associated_data.cc b/components/variations/variations_associated_data.cc
|
| index a26470438fb2cc3fd69acd89a336e9c5c33d750f..684dc93fd5d3da4d8cf6f354b7eac113e8d723ba 100644
|
| --- a/components/variations/variations_associated_data.cc
|
| +++ b/components/variations/variations_associated_data.cc
|
| @@ -9,6 +9,7 @@
|
| #include <vector>
|
|
|
| #include "base/memory/singleton.h"
|
| +#include "base/strings/string_split.h"
|
|
|
| namespace variations {
|
|
|
| @@ -215,6 +216,53 @@ bool AssociateVariationParams(
|
| trial_name, group_name, params);
|
| }
|
|
|
| +struct VarationsParams {
|
| + std::string GroupName;
|
| + std::map<std::string, std::string> Params;
|
| +};
|
| +
|
| +bool AssociateParamsFromString(const std::string& varations_string) {
|
| + std::map <std::string, VarationsParams> data;
|
| + std::vector<std::string> tokens;
|
| + base::SplitString(varations_string, '/', &tokens);
|
| + if (tokens.size() % 2 == 0) {
|
| + // Build out parameters
|
| + for (int i = 0; i < tokens.size(); i += 2) {
|
| + std::vector<std::string> key;
|
| + base::SplitString(tokens[i], '.', &key);
|
| + DCHECK(key.size() == 3) << "Expecting format Trial.Group.Key";
|
| + if (key.size() == 3) {
|
| + const std::string& trial = key[0];
|
| + const std::string& group = key[1];
|
| + const std::string& param = key[2];
|
| + const std::string& value = tokens[i + 1];
|
| + const auto& iter = data.find(trial);
|
| + if (iter != data.end()) {
|
| + if (iter->second.GroupName == group) {
|
| + iter->second.Params[param] = value;
|
| + }
|
| + }
|
| + else {
|
| + VarationsParams vp;
|
| + vp.GroupName = group;
|
| + vp.Params[param] = value;
|
| + data[trial] = vp;
|
| + }
|
| + }
|
| + }
|
| + // Associate parameters
|
| + for (const auto& iter : data) {
|
| + const std::string& trial = iter.first;
|
| + const VarationsParams& params = iter.second;
|
| + AssociateVariationParams(trial, params.GroupName, params.Params);
|
| + }
|
| + } else {
|
| + DCHECK(false) << "Expecting pairs of values";
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| bool GetVariationParams(const std::string& trial_name,
|
| std::map<std::string, std::string>* params) {
|
| return VariationsParamAssociator::GetInstance()->GetVariationParams(
|
|
|