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

Unified Diff: components/variations/variations_associated_data.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, 8 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 side-by-side diff with in-line comments
Download patch
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..3ab09fe184f526b9d29e06118a2fbbd5e078821d 100644
--- a/components/variations/variations_associated_data.cc
+++ b/components/variations/variations_associated_data.cc
@@ -9,6 +9,9 @@
#include <vector>
#include "base/memory/singleton.h"
+#include "base/strings/string_split.h"
+
+// #include "net/base/escape.h"
danduong 2015/04/29 01:09:12 Any suggestions on where this code should live? We
Alexei Svitkine (slow) 2015/04/29 15:34:24 Couple options. One is we can put this code in ch
namespace variations {
@@ -215,6 +218,40 @@ bool AssociateVariationParams(
trial_name, group_name, params);
}
+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 (auto& experiment_group : experiment_groups) {
+ std::vector<std::string> experiment;
+ base::SplitString(experiment_group, ':', &experiment);
+ if (experiment.size() == 2) {
+ std::vector<std::string> group_parts;
+ base::SplitString(experiment[0], '.', &group_parts);
+ if (group_parts.size() == 2) {
+ 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);
+ std::string group = net::UnescapeURLComponent(group_parts[1],
+ net::UnescapeRule::URL_SPECIAL_CHARS);
+ AssociateVariationParams(trial, group, params);
+ }
+ }
+ }
+ }
+ return true;
+}
+
bool GetVariationParams(const std::string& trial_name,
std::map<std::string, std::string>* params) {
return VariationsParamAssociator::GetInstance()->GetVariationParams(
« no previous file with comments | « components/variations/variations_associated_data.h ('k') | components/variations/variations_associated_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698