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_seed_processor.cc

Issue 71753004: Allow variation id with forcing flag for special setup & unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow variation id with forcing flag for special setup & unit tests. Created 7 years, 1 month 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 e7a33cad035433b67603eabfccb819868d54ca38..aacef718dde771e23e96e9977812a003e6229eb8 100644
--- a/components/variations/variations_seed_processor.cc
+++ b/components/variations/variations_seed_processor.cc
@@ -64,6 +64,27 @@ VariationsSeedProcessor::VariationsSeedProcessor() {
VariationsSeedProcessor::~VariationsSeedProcessor() {
}
+bool VariationsSeedProcessor::AllowVariationIdWithForcingFlag(
Alexei Svitkine (slow) 2013/11/14 16:54:15 This and the other function can just be free-stand
yao 2013/11/14 20:51:12 Done.
+ const Study& study) {
+ if (!study.has_filter())
+ return false;
+ Study_Filter filter = study.filter();
+ if (filter.platform_size() == 0 || filter.channel_size() == 0) {
Alexei Svitkine (slow) 2013/11/14 16:54:15 This doesn't need {}'s. (single line if and single
yao 2013/11/14 20:51:12 Done.
+ return false;
+ }
+ for (int i = 0; i < filter.platform_size(); ++i) {
+ if (filter.platform(i) != Study_Platform_PLATFORM_ANDROID &&
+ filter.platform(i) != Study_Platform_PLATFORM_IOS)
Alexei Svitkine (slow) 2013/11/14 16:54:15 This does need {}'s - multi-line if. (Same below).
yao 2013/11/14 20:51:12 Done.
+ return false;
+ }
+ for (int i = 0; i < filter.channel_size(); ++i) {
+ if (filter.channel(i) != Study_Channel_CANARY &&
+ filter.channel(i) != Study_Channel_DEV)
+ return false;
+ }
+ return true;
+}
+
void VariationsSeedProcessor::CreateTrialsFromSeed(
const VariationsSeed& seed,
const std::string& locale,
@@ -210,9 +231,31 @@ bool VariationsSeedProcessor::CheckStudyVersion(
return true;
}
+void VariationsSeedProcessor::CheckVariationId(
Alexei Svitkine (slow) 2013/11/14 16:54:15 This should be called RegisterVariationIds().
yao 2013/11/14 20:51:12 Done.
+ const Study_Experiment& experiment,
+ const std::string& trial_name) {
+ if (experiment.has_google_web_experiment_id()) {
+ const VariationID variation_id =
+ static_cast<VariationID>(experiment.google_web_experiment_id());
+ AssociateGoogleVariationIDForce(GOOGLE_WEB_PROPERTIES,
+ trial_name,
+ experiment.name(),
+ variation_id);
+ }
+ if (experiment.has_google_update_experiment_id()) {
+ const VariationID variation_id =
+ static_cast<VariationID>(experiment.google_update_experiment_id());
+ AssociateGoogleVariationIDForce(GOOGLE_UPDATE_SERVICE,
+ trial_name,
+ experiment.name(),
+ variation_id);
+ }
+}
+
void VariationsSeedProcessor::CreateTrialFromStudy(
const ProcessedStudy& processed_study) {
const Study& study = *processed_study.study;
+ bool allowBoth = AllowVariationIdWithForcingFlag(study);
Alexei Svitkine (slow) 2013/11/14 16:54:15 Can we do this check lazily? (e.g. block below whe
yao 2013/11/14 20:51:12 Done.
// Check if any experiments need to be forced due to a command line
// flag. Force the first experiment with an existing flag.
@@ -225,6 +268,9 @@ void VariationsSeedProcessor::CreateTrialFromStudy(
RegisterExperimentParams(study, experiment);
DVLOG(1) << "Trial " << study.name() << " forced by flag: "
<< experiment.forcing_flag();
+ if (allowBoth) {
+ CheckVariationId(experiment, study.name());
+ }
return;
}
}
@@ -255,28 +301,13 @@ void VariationsSeedProcessor::CreateTrialFromStudy(
// Groups with flags can't be selected randomly, so we don't add them to
// the field trial.
- if (experiment.has_forcing_flag())
+ if (experiment.has_forcing_flag() && !allowBoth)
Alexei Svitkine (slow) 2013/11/14 16:54:15 I think we don't need this logic in this case. It'
yao 2013/11/14 20:51:12 Done.
continue;
if (experiment.name() != study.default_experiment_name())
trial->AppendGroup(experiment.name(), experiment.probability_weight());
- if (experiment.has_google_web_experiment_id()) {
- const VariationID variation_id =
- static_cast<VariationID>(experiment.google_web_experiment_id());
- AssociateGoogleVariationIDForce(GOOGLE_WEB_PROPERTIES,
- study.name(),
- experiment.name(),
- variation_id);
- }
- if (experiment.has_google_update_experiment_id()) {
- const VariationID variation_id =
- static_cast<VariationID>(experiment.google_update_experiment_id());
- AssociateGoogleVariationIDForce(GOOGLE_UPDATE_SERVICE,
- study.name(),
- experiment.name(),
- variation_id);
- }
+ CheckVariationId(experiment, study.name());
}
trial->SetForced();

Powered by Google App Engine
This is Rietveld 408576698