diff options
Diffstat (limited to 'chromium/components/flags_ui/feature_entry.cc')
-rw-r--r-- | chromium/components/flags_ui/feature_entry.cc | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/chromium/components/flags_ui/feature_entry.cc b/chromium/components/flags_ui/feature_entry.cc index 384393fa529..5298b138795 100644 --- a/chromium/components/flags_ui/feature_entry.cc +++ b/chromium/components/flags_ui/feature_entry.cc @@ -44,7 +44,21 @@ bool FeatureEntry::InternalNameMatches(const std::string& name) const { return name.size() > internal_name_length + 1 && name[internal_name_length] == kMultiSeparatorChar && base::StringToInt(name.substr(internal_name_length + 1), &index) && - index >= 0 && index < num_options; + index >= 0 && index < NumOptions(); + } +} + +int FeatureEntry::NumOptions() const { + switch (type) { + case ENABLE_DISABLE_VALUE: + case FEATURE_VALUE: + return 3; + case MULTI_VALUE: + return choices.size(); + case FEATURE_WITH_PARAMS_VALUE: + return 3 + feature.feature_variations.size(); + default: + return 0; } } @@ -53,7 +67,7 @@ std::string FeatureEntry::NameForOption(int index) const { type == FeatureEntry::ENABLE_DISABLE_VALUE || type == FeatureEntry::FEATURE_VALUE || type == FeatureEntry::FEATURE_WITH_PARAMS_VALUE); - DCHECK_LT(index, num_options); + DCHECK_LT(index, NumOptions()); return std::string(internal_name) + testing::kMultiSeparator + base::NumberToString(index); } @@ -63,7 +77,7 @@ base::string16 FeatureEntry::DescriptionForOption(int index) const { type == FeatureEntry::ENABLE_DISABLE_VALUE || type == FeatureEntry::FEATURE_VALUE || type == FeatureEntry::FEATURE_WITH_PARAMS_VALUE); - DCHECK_LT(index, num_options); + DCHECK_LT(index, NumOptions()); const char* description = nullptr; if (type == FeatureEntry::ENABLE_DISABLE_VALUE || type == FeatureEntry::FEATURE_VALUE) { @@ -77,16 +91,16 @@ base::string16 FeatureEntry::DescriptionForOption(int index) const { description = kGenericExperimentChoiceDefault; } else if (index == 1) { description = kGenericExperimentChoiceEnabled; - } else if (index < num_options - 1) { + } else if (index < NumOptions() - 1) { // First two options do not have variations params. int variation_index = index - 2; return base::ASCIIToUTF16( base::StringPiece(kGenericExperimentChoiceEnabled)) + base::ASCIIToUTF16(" ") + base::ASCIIToUTF16( - feature_variations[variation_index].description_text); + feature.feature_variations[variation_index].description_text); } else { - DCHECK_EQ(num_options - 1, index); + DCHECK_EQ(NumOptions() - 1, index); description = kGenericExperimentChoiceDisabled; } } else { @@ -97,7 +111,7 @@ base::string16 FeatureEntry::DescriptionForOption(int index) const { const FeatureEntry::Choice& FeatureEntry::ChoiceForOption(int index) const { DCHECK_EQ(FeatureEntry::MULTI_VALUE, type); - DCHECK_LT(index, num_options); + DCHECK_LT(index, NumOptions()); return choices[index]; } @@ -105,11 +119,11 @@ const FeatureEntry::Choice& FeatureEntry::ChoiceForOption(int index) const { FeatureEntry::FeatureState FeatureEntry::StateForOption(int index) const { DCHECK(type == FeatureEntry::FEATURE_VALUE || type == FeatureEntry::FEATURE_WITH_PARAMS_VALUE); - DCHECK_LT(index, num_options); + DCHECK_LT(index, NumOptions()); if (index == 0) return FeatureEntry::FeatureState::DEFAULT; - if (index == num_options - 1) + if (index == NumOptions() - 1) return FeatureEntry::FeatureState::DISABLED; return FeatureEntry::FeatureState::ENABLED; } @@ -118,14 +132,14 @@ const FeatureEntry::FeatureVariation* FeatureEntry::VariationForOption( int index) const { DCHECK(type == FeatureEntry::FEATURE_VALUE || type == FeatureEntry::FEATURE_WITH_PARAMS_VALUE); - DCHECK_LT(index, num_options); + DCHECK_LT(index, NumOptions()); if (type == FeatureEntry::FEATURE_WITH_PARAMS_VALUE && index > 1 && - index < num_options - 1) { + index < NumOptions() - 1) { // We have no variations for FEATURE_VALUE type. Option at |index| // corresponds to variation at |index| - 2 as the list starts with "Default" // and "Enabled" (with default parameters). - return &feature_variations[index - 2]; + return &feature.feature_variations[index - 2]; } return nullptr; } |