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

Side by Side Diff: components/variations/variations_seed_processor.cc

Issue 2919143002: Fix variations crashes when the chosen trial group is not in study. (Closed)
Patch Set: Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/variations/variations_seed_processor_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/variations/variations_seed_processor.h" 5 #include "components/variations/variations_seed_processor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 ApplyUIStringOverrides(experiment, override_callback); 94 ApplyUIStringOverrides(experiment, override_callback);
95 } 95 }
96 } 96 }
97 97
98 // Registers feature overrides for the chosen experiment in the specified study. 98 // Registers feature overrides for the chosen experiment in the specified study.
99 void RegisterFeatureOverrides(const ProcessedStudy& processed_study, 99 void RegisterFeatureOverrides(const ProcessedStudy& processed_study,
100 base::FieldTrial* trial, 100 base::FieldTrial* trial,
101 base::FeatureList* feature_list) { 101 base::FeatureList* feature_list) {
102 const std::string& group_name = trial->GetGroupNameWithoutActivation(); 102 const std::string& group_name = trial->GetGroupNameWithoutActivation();
103 int experiment_index = processed_study.GetExperimentIndexByName(group_name); 103 int experiment_index = processed_study.GetExperimentIndexByName(group_name);
104 // The field trial was defined from |study|, so the active experiment's name 104 // If the chosen experiment was not found in the study, simply return.
105 // must be in the |study|. 105 // Although not normally expected, but could happen in exception cases, see
106 DCHECK_NE(-1, experiment_index); 106 // tests: ExpiredStudy_NoDefaultGroup, ExistingFieldTrial_ExpiredByConfig
107 if (experiment_index == -1)
108 return;
107 109
108 const Study& study = *processed_study.study(); 110 const Study& study = *processed_study.study();
109 const Study_Experiment& experiment = study.experiment(experiment_index); 111 const Study_Experiment& experiment = study.experiment(experiment_index);
110 112
111 // Process all the features to enable. 113 // Process all the features to enable.
112 int feature_count = experiment.feature_association().enable_feature_size(); 114 int feature_count = experiment.feature_association().enable_feature_size();
113 for (int i = 0; i < feature_count; ++i) { 115 for (int i = 0; i < feature_count; ++i) {
114 feature_list->RegisterFieldTrialOverride( 116 feature_list->RegisterFieldTrialOverride(
115 experiment.feature_association().enable_feature(i), 117 experiment.feature_association().enable_feature(i),
116 base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial); 118 base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // params won't be registered under the correct key. 320 // params won't be registered under the correct key.
319 const std::string& group_name = trial->group_name(); 321 const std::string& group_name = trial->group_name();
320 322
321 // Don't try to apply overrides if none of the experiments in this study had 323 // Don't try to apply overrides if none of the experiments in this study had
322 // any. 324 // any.
323 if (!has_overrides) 325 if (!has_overrides)
324 return; 326 return;
325 327
326 // UI Strings can only be overridden from ACTIVATION_AUTO experiments. 328 // UI Strings can only be overridden from ACTIVATION_AUTO experiments.
327 int experiment_index = processed_study.GetExperimentIndexByName(group_name); 329 int experiment_index = processed_study.GetExperimentIndexByName(group_name);
328 330 // If the chosen experiment was not found in the study, simply return.
329 // The field trial was defined from |study|, so the active experiment's name 331 // Although not normally expected, but could happen in exception cases, see
330 // must be in the |study|. 332 // tests: ExpiredStudy_NoDefaultGroup, ExistingFieldTrial_ExpiredByConfig
331 DCHECK_NE(-1, experiment_index); 333 if (experiment_index != -1) {
332 334 ApplyUIStringOverrides(study.experiment(experiment_index),
333 ApplyUIStringOverrides(study.experiment(experiment_index), 335 override_callback);
334 override_callback); 336 }
335 } 337 }
336 } 338 }
337 339
338 } // namespace variations 340 } // namespace variations
OLDNEW
« no previous file with comments | « no previous file | components/variations/variations_seed_processor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698