Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/flags_ui/feature_entry.h" | 5 #include "components/flags_ui/feature_entry.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "grit/components_strings.h" | 10 #include "grit/components_strings.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
| 11 | 12 |
| 12 namespace flags_ui { | 13 namespace flags_ui { |
| 13 | 14 |
| 14 std::string FeatureEntry::NameForChoice(int index) const { | 15 std::string FeatureEntry::NameForOption(int index) const { |
| 15 DCHECK(type == FeatureEntry::MULTI_VALUE || | 16 DCHECK(type == FeatureEntry::MULTI_VALUE || |
| 16 type == FeatureEntry::ENABLE_DISABLE_VALUE || | 17 type == FeatureEntry::ENABLE_DISABLE_VALUE || |
| 17 type == FeatureEntry::FEATURE_VALUE); | 18 type == FeatureEntry::FEATURE_VALUE || |
| 18 DCHECK_LT(index, num_choices); | 19 type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE); |
| 20 DCHECK_LT(index, num_options); | |
| 19 return std::string(internal_name) + testing::kMultiSeparator + | 21 return std::string(internal_name) + testing::kMultiSeparator + |
| 20 base::IntToString(index); | 22 base::IntToString(index); |
| 21 } | 23 } |
| 22 | 24 |
| 23 base::string16 FeatureEntry::DescriptionForChoice(int index) const { | 25 base::string16 FeatureEntry::DescriptionForOption(int index) const { |
| 24 DCHECK(type == FeatureEntry::MULTI_VALUE || | 26 DCHECK(type == FeatureEntry::MULTI_VALUE || |
| 25 type == FeatureEntry::ENABLE_DISABLE_VALUE || | 27 type == FeatureEntry::ENABLE_DISABLE_VALUE || |
| 26 type == FeatureEntry::FEATURE_VALUE); | 28 type == FeatureEntry::FEATURE_VALUE || |
| 27 DCHECK_LT(index, num_choices); | 29 type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE); |
| 30 DCHECK_LT(index, num_options); | |
| 28 int description_id; | 31 int description_id; |
| 29 if (type == FeatureEntry::ENABLE_DISABLE_VALUE || | 32 if (type == FeatureEntry::ENABLE_DISABLE_VALUE || |
| 30 type == FeatureEntry::FEATURE_VALUE) { | 33 type == FeatureEntry::FEATURE_VALUE) { |
| 31 const int kEnableDisableDescriptionIds[] = { | 34 const int kEnableDisableDescriptionIds[] = { |
| 32 IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, | 35 IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, |
| 33 IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED, | 36 IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED, |
| 34 IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED, | 37 IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED, |
| 35 }; | 38 }; |
| 36 description_id = kEnableDisableDescriptionIds[index]; | 39 description_id = kEnableDisableDescriptionIds[index]; |
| 40 } else if (type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE) { | |
| 41 if (index == 0) { | |
| 42 description_id = IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT; | |
| 43 } else if (index == 1) { | |
| 44 // Variation 1: the default Enabled (disregarding its description_id). | |
| 45 description_id = IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED; | |
| 46 } else if (index < num_options - 1) { | |
| 47 // Variations 2 .. n | |
| 48 int variation_index = index - 1; | |
| 49 return l10n_util::GetStringUTF16(IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED) + | |
|
Alexei Svitkine (slow)
2016/06/10 15:46:48
So the syntax here is: "Enabled <description_text>
jkrcal
2016/06/14 10:04:21
Done.
| |
| 50 base::ASCIIToUTF16(" ") + | |
| 51 base::ASCIIToUTF16( | |
| 52 feature_variations[variation_index].description_text); | |
| 53 } else { | |
| 54 description_id = IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED; | |
|
Alexei Svitkine (slow)
2016/06/10 15:46:48
Nit: Add a comment: // |index| == |num_options - 1
jkrcal
2016/06/14 10:04:21
Done.
| |
| 55 } | |
| 37 } else { | 56 } else { |
| 38 description_id = choices[index].description_id; | 57 description_id = choices[index].description_id; |
| 39 } | 58 } |
| 40 return l10n_util::GetStringUTF16(description_id); | 59 return l10n_util::GetStringUTF16(description_id); |
| 41 } | 60 } |
| 42 | 61 |
| 62 const FeatureEntry::Choice& FeatureEntry::ChoiceForOption(int index) const { | |
| 63 DCHECK(type == FeatureEntry::MULTI_VALUE); | |
|
Alexei Svitkine (slow)
2016/06/10 15:46:48
DCHECK_EQ() when it's just one option.
jkrcal
2016/06/14 10:04:21
Done.
| |
| 64 DCHECK_LT(index, num_options); | |
| 65 | |
| 66 return choices[index]; | |
| 67 } | |
| 68 | |
| 69 FeatureEntry::State FeatureEntry::StateForOption(int index) const { | |
| 70 DCHECK(type == FeatureEntry::FEATURE_VALUE || | |
| 71 type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE); | |
| 72 DCHECK_LT(index, num_options); | |
| 73 | |
| 74 if (index == 0) | |
| 75 return FeatureEntry::State::DEFAULT; | |
| 76 else if (index == num_options - 1) | |
| 77 return FeatureEntry::State::DISABLED; | |
| 78 else | |
| 79 return FeatureEntry::State::ENABLED; | |
| 80 } | |
| 81 | |
| 82 const FeatureEntry::FeatureVariation* FeatureEntry::VariationForOption( | |
| 83 int index) const { | |
| 84 DCHECK(type == FeatureEntry::FEATURE_VALUE || | |
| 85 type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE); | |
| 86 DCHECK_LT(index, num_options); | |
| 87 | |
| 88 if (type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE && index > 0 && | |
| 89 index < num_options - 1) { | |
| 90 // We have no variations for FEATURE_VALUE type. Option at |index| | |
| 91 // corresponds to variation at |index| - 1 as the first option is "Default". | |
| 92 return &feature_variations[index - 1]; | |
| 93 } else { | |
|
Alexei Svitkine (slow)
2016/06/10 15:46:49
Nit: No } else { if the above if has a return.
(B
jkrcal
2016/06/14 10:04:21
Done.
| |
| 94 return nullptr; | |
| 95 } | |
| 96 } | |
| 97 | |
| 43 namespace testing { | 98 namespace testing { |
| 44 | 99 |
| 45 // WARNING: '@' is also used in the html file. If you update this constant you | 100 // WARNING: '@' is also used in the html file. If you update this constant you |
| 46 // also need to update the html file. | 101 // also need to update the html file. |
| 47 const char kMultiSeparator[] = "@"; | 102 const char kMultiSeparator[] = "@"; |
| 48 | 103 |
| 49 } // namespace testing | 104 } // namespace testing |
| 50 | 105 |
| 51 } // namespace flags_ui | 106 } // namespace flags_ui |
| OLD | NEW |