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

Unified Diff: components/variations/variations_seed_processor.cc

Issue 370463003: Add support for variations controlled overriding UI strings to the variations service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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_seed_processor.cc
diff --git a/components/variations/variations_seed_processor.cc b/components/variations/variations_seed_processor.cc
index e468e4e2d808cddef99f84c3c6414a3a1205eeb0..1bd502a6d963cbbb3d192a1d1dde835081cd0d12 100644
--- a/components/variations/variations_seed_processor.cc
+++ b/components/variations/variations_seed_processor.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
+#include "base/strings/utf_string_conversions.h"
#include "components/variations/processed_study.h"
#include "components/variations/study_filtering.h"
#include "components/variations/variations_associated_data.h"
@@ -58,6 +59,17 @@ void RegisterVariationIds(const Study_Experiment& experiment,
}
}
+void ApplyUIStringOverrides(
Alexei Svitkine (slow) 2014/07/04 15:48:51 Add a comment please.
jwd 2014/07/07 15:52:20 Done.
+ const Study_Experiment& experiment,
+ const VariationsSeedProcessor::UIStringOverrideCallback& override_string) {
+ for (int i = 0; i < experiment.override_ui_string_size(); ++i) {
+ Study_Experiment_OverrideUIString experiment_overrides =
Alexei Svitkine (slow) 2014/07/03 17:54:40 Nit: Remove extra space.
jwd 2014/07/07 15:52:20 Done.
+ experiment.override_ui_string(i);
+ override_string.Run(experiment_overrides.name_hash(),
+ base::ASCIIToUTF16(experiment_overrides.value()));
Alexei Svitkine (slow) 2014/07/03 17:54:41 The value may not be ascii. Use UTF8ToUTF16.
jwd 2014/07/07 15:52:20 Done.
+ }
+}
+
} // namespace
VariationsSeedProcessor::VariationsSeedProcessor() {
@@ -73,17 +85,19 @@ void VariationsSeedProcessor::CreateTrialsFromSeed(
const base::Version& version,
Study_Channel channel,
Study_FormFactor form_factor,
- const std::string& hardware_class) {
+ const std::string& hardware_class,
+ const UIStringOverrideCallback& override_string) {
std::vector<ProcessedStudy> filtered_studies;
FilterAndValidateStudies(seed, locale, reference_date, version, channel,
form_factor, hardware_class, &filtered_studies);
for (size_t i = 0; i < filtered_studies.size(); ++i)
- CreateTrialFromStudy(filtered_studies[i]);
+ CreateTrialFromStudy(filtered_studies[i], override_string);
}
void VariationsSeedProcessor::CreateTrialFromStudy(
- const ProcessedStudy& processed_study) {
+ const ProcessedStudy& processed_study,
+ const UIStringOverrideCallback& override_string) {
const Study& study = *processed_study.study();
// Check if any experiments need to be forced due to a command line
@@ -98,8 +112,11 @@ void VariationsSeedProcessor::CreateTrialFromStudy(
experiment.name()));
RegisterExperimentParams(study, experiment);
RegisterVariationIds(experiment, study.name());
- if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO)
+ if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) {
trial->group();
+ // UI Strings can only be overridden from ACTIVATION_AUTO experiments.
+ ApplyUIStringOverrides(experiment, override_string);
+ }
DVLOG(1) << "Trial " << study.name() << " forced by flag: "
<< experiment.forcing_flag();
@@ -145,8 +162,18 @@ void VariationsSeedProcessor::CreateTrialFromStudy(
trial->SetForced();
if (processed_study.is_expired())
Alexei Svitkine (slow) 2014/07/04 15:48:51 Nit: Add {}'s here.
jwd 2014/07/07 15:52:20 Done.
trial->Disable();
- else if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO)
- trial->group();
+ else if (study.activation_type() == Study_ActivationType_ACTIVATION_AUTO) {
+ const std::string& group_name = trial->group_name();
+
+ // UI Strings can only be overridden from ACTIVATION_AUTO experiments.
+ int experiment_index = processed_study.GetExperimentIndexByName(group_name);
Alexei Svitkine (slow) 2014/07/04 15:48:51 Maybe add a bool to keep track if any experiment h
jwd 2014/07/07 15:52:20 Done.
+
+ // The field trial was defined from |study|, so the active experiment's name
+ // must be in the |study|.
+ DCHECK_GE(experiment_index, 0);
Alexei Svitkine (slow) 2014/07/04 15:48:52 Change to NE(-1,
jwd 2014/07/07 15:52:20 Done.
+
+ ApplyUIStringOverrides(study.experiment(experiment_index), override_string);
+ }
}
} // namespace chrome_variations

Powered by Google App Engine
This is Rietveld 408576698