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

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: Build deps #2 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
« no previous file with comments | « components/flags_ui/feature_entry.h ('k') | components/flags_ui/feature_entry_macros.h » ('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 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 variation => "Enabled".
45 description_id = IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED;
46 } else if (index < num_options - 1) {
47 // Variations 2 .. n => "Enabled <description_text>".
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 DCHECK_EQ(num_options - 1, index);
55 description_id = IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED;
56 }
37 } else { 57 } else {
38 description_id = choices[index].description_id; 58 description_id = choices[index].description_id;
39 } 59 }
40 return l10n_util::GetStringUTF16(description_id); 60 return l10n_util::GetStringUTF16(description_id);
41 } 61 }
42 62
63 const FeatureEntry::Choice& FeatureEntry::ChoiceForOption(int index) const {
64 DCHECK_EQ(FeatureEntry::MULTI_VALUE, type);
65 DCHECK_LT(index, num_options);
66
67 return choices[index];
68 }
69
70 FeatureEntry::FeatureState FeatureEntry::StateForOption(int index) const {
71 DCHECK(type == FeatureEntry::FEATURE_VALUE ||
72 type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE);
73 DCHECK_LT(index, num_options);
74
75 if (index == 0)
76 return FeatureEntry::FeatureState::DEFAULT;
77 else if (index == num_options - 1)
78 return FeatureEntry::FeatureState::DISABLED;
79 else
80 return FeatureEntry::FeatureState::ENABLED;
81 }
82
83 const FeatureEntry::FeatureVariation* FeatureEntry::VariationForOption(
84 int index) const {
85 DCHECK(type == FeatureEntry::FEATURE_VALUE ||
86 type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE);
87 DCHECK_LT(index, num_options);
88
89 if (type == FeatureEntry::FEATURE_WITH_VARIATIONS_VALUE && index > 0 &&
90 index < num_options - 1) {
91 // We have no variations for FEATURE_VALUE type. Option at |index|
92 // corresponds to variation at |index| - 1 as the first option is "Default".
93 return &feature_variations[index - 1];
94 }
95 return nullptr;
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
OLDNEW
« no previous file with comments | « components/flags_ui/feature_entry.h ('k') | components/flags_ui/feature_entry_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698