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

Side by Side Diff: components/flags_ui/feature_entry.cc

Issue 2036193002: Allow overriding variation parameter via chrome://flags. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor polish #3 + Adding a unittest Created 4 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
OLDNEW
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) +
50 base::ASCIIToUTF16(" ") +
51 base::ASCIIToUTF16(
52 feature_variations[variation_index].description_text);
53 } else {
54 description_id = IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED;
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 FeatureEntry::State FeatureEntry::StateForOption(int index) const {
63 DCHECK(type == FeatureEntry::FEATURE_VALUE ||
64 type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE);
65 DCHECK_LT(index, num_options);
66
67 if (index == 0)
68 return FeatureEntry::State::DEFAULT;
69 else if (index == num_options - 1)
70 return FeatureEntry::State::DISABLED;
71 else
72 return FeatureEntry::State::ENABLED;
73 }
74
75 const FeatureEntry::FeatureVariation* FeatureEntry::VariationForOption(
76 int index) const {
77 DCHECK(type == FeatureEntry::FEATURE_VALUE ||
78 type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE);
79 DCHECK_LT(index, num_options);
80
81 if (type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE && index > 0 &&
82 index < num_options - 1) {
83 // We have no variations for FEATURE_VALUE type. Option at |index|
84 // corresponds to variation at |index| - 1 as the first option is "Default".
85 return &feature_variations[index - 1];
86 } else {
87 return nullptr;
88 }
89 }
90
43 namespace testing { 91 namespace testing {
44 92
45 // WARNING: '@' is also used in the html file. If you update this constant you 93 // WARNING: '@' is also used in the html file. If you update this constant you
46 // also need to update the html file. 94 // also need to update the html file.
47 const char kMultiSeparator[] = "@"; 95 const char kMultiSeparator[] = "@";
48 96
49 } // namespace testing 97 } // namespace testing
50 98
51 } // namespace flags_ui 99 } // namespace flags_ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698