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

Side by Side Diff: chrome/browser/about_flags.cc

Issue 1415953005: Componentize about_flags::FeatureEntry in flags_ui component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/about_flags.h" 5 #include "chrome/browser/about_flags.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 13 matching lines...) Expand all
24 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
25 #include "chrome/grit/chromium_strings.h" 25 #include "chrome/grit/chromium_strings.h"
26 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
27 #include "chrome/grit/google_chrome_strings.h" 27 #include "chrome/grit/google_chrome_strings.h"
28 #include "components/autofill/core/common/autofill_switches.h" 28 #include "components/autofill/core/common/autofill_switches.h"
29 #include "components/browser_sync/common/browser_sync_switches.h" 29 #include "components/browser_sync/common/browser_sync_switches.h"
30 #include "components/cloud_devices/common/cloud_devices_switches.h" 30 #include "components/cloud_devices/common/cloud_devices_switches.h"
31 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" 31 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h"
32 #include "components/dom_distiller/core/dom_distiller_switches.h" 32 #include "components/dom_distiller/core/dom_distiller_switches.h"
33 #include "components/enhanced_bookmarks/enhanced_bookmark_switches.h" 33 #include "components/enhanced_bookmarks/enhanced_bookmark_switches.h"
34 #include "components/flags_ui/feature_entry_macros.h"
34 #include "components/flags_ui/flags_storage.h" 35 #include "components/flags_ui/flags_storage.h"
35 #include "components/metrics/metrics_hashes.h" 36 #include "components/metrics/metrics_hashes.h"
36 #include "components/nacl/common/nacl_switches.h" 37 #include "components/nacl/common/nacl_switches.h"
37 #include "components/offline_pages/offline_page_switches.h" 38 #include "components/offline_pages/offline_page_switches.h"
38 #include "components/omnibox/browser/omnibox_switches.h" 39 #include "components/omnibox/browser/omnibox_switches.h"
39 #include "components/password_manager/core/common/password_manager_switches.h" 40 #include "components/password_manager/core/common/password_manager_switches.h"
40 #include "components/plugins/common/plugins_switches.h" 41 #include "components/plugins/common/plugins_switches.h"
41 #include "components/proximity_auth/switches.h" 42 #include "components/proximity_auth/switches.h"
42 #include "components/search/search_switches.h" 43 #include "components/search/search_switches.h"
43 #include "components/signin/core/common/signin_switches.h" 44 #include "components/signin/core/common/signin_switches.h"
44 #include "components/sync_driver/sync_driver_switches.h" 45 #include "components/sync_driver/sync_driver_switches.h"
45 #include "components/tracing/tracing_switches.h" 46 #include "components/tracing/tracing_switches.h"
46 #include "components/version_info/version_info.h" 47 #include "components/version_info/version_info.h"
47 #include "content/public/browser/user_metrics.h" 48 #include "content/public/browser/user_metrics.h"
48 #include "content/public/common/content_switches.h" 49 #include "content/public/common/content_switches.h"
50 #include "grit/components_strings.h"
49 #include "media/base/media_switches.h" 51 #include "media/base/media_switches.h"
50 #include "media/midi/midi_switches.h" 52 #include "media/midi/midi_switches.h"
51 #include "ui/base/l10n/l10n_util.h" 53 #include "ui/base/l10n/l10n_util.h"
52 #include "ui/base/ui_base_switches.h" 54 #include "ui/base/ui_base_switches.h"
53 #include "ui/display/display_switches.h" 55 #include "ui/display/display_switches.h"
54 #include "ui/events/event_switches.h" 56 #include "ui/events/event_switches.h"
55 #include "ui/gfx/switches.h" 57 #include "ui/gfx/switches.h"
56 #include "ui/gl/gl_switches.h" 58 #include "ui/gl/gl_switches.h"
57 #include "ui/keyboard/keyboard_switches.h" 59 #include "ui/keyboard/keyboard_switches.h"
58 #include "ui/native_theme/native_theme_switches.h" 60 #include "ui/native_theme/native_theme_switches.h"
(...skipping 17 matching lines...) Expand all
76 #endif 78 #endif
77 79
78 #if defined(ENABLE_EXTENSIONS) 80 #if defined(ENABLE_EXTENSIONS)
79 #include "extensions/common/switches.h" 81 #include "extensions/common/switches.h"
80 #endif 82 #endif
81 83
82 #if defined(USE_OZONE) 84 #if defined(USE_OZONE)
83 #include "ui/ozone/public/ozone_switches.h" 85 #include "ui/ozone/public/ozone_switches.h"
84 #endif 86 #endif
85 87
88 using flags_ui::FeatureEntry;
89
86 namespace about_flags { 90 namespace about_flags {
87 91
88 // Macros to simplify specifying the type. Please refer to the comments on
89 // FeatureEntry::Type in the header file, which explain the different entry
90 // types and when they should be used.
91 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
92 FeatureEntry::SINGLE_VALUE, command_line_switch, switch_value, nullptr, \
93 nullptr, nullptr, nullptr, 0
94 #define SINGLE_VALUE_TYPE(command_line_switch) \
95 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
96 #define SINGLE_DISABLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
97 FeatureEntry::SINGLE_DISABLE_VALUE, command_line_switch, switch_value, \
98 nullptr, nullptr, nullptr, nullptr, 0
99 #define SINGLE_DISABLE_VALUE_TYPE(command_line_switch) \
100 SINGLE_DISABLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
101 #define ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(enable_switch, enable_value, \
102 disable_switch, disable_value) \
103 FeatureEntry::ENABLE_DISABLE_VALUE, enable_switch, enable_value, \
104 disable_switch, disable_value, nullptr, nullptr, 3
105 #define ENABLE_DISABLE_VALUE_TYPE(enable_switch, disable_switch) \
106 ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(enable_switch, "", disable_switch, "")
107 #define MULTI_VALUE_TYPE(choices) \
108 FeatureEntry::MULTI_VALUE, nullptr, nullptr, nullptr, nullptr, nullptr, \
109 choices, arraysize(choices)
110 #define FEATURE_VALUE_TYPE(feature) \
111 FeatureEntry::FEATURE_VALUE, nullptr, nullptr, nullptr, nullptr, \
112 feature.name, nullptr, 3
113
114 namespace { 92 namespace {
115 93
116 // Enumeration of OSs. 94 // Enumeration of OSs.
117 enum { 95 enum {
118 kOsMac = 1 << 0, 96 kOsMac = 1 << 0,
119 kOsWin = 1 << 1, 97 kOsWin = 1 << 1,
120 kOsLinux = 1 << 2, 98 kOsLinux = 1 << 2,
121 kOsCrOS = 1 << 3, 99 kOsCrOS = 1 << 3,
122 kOsAndroid = 1 << 4, 100 kOsAndroid = 1 << 4,
123 kOsCrOSOwnerOnly = 1 << 5 101 kOsCrOSOwnerOnly = 1 << 5
(...skipping 2324 matching lines...) Expand 10 before | Expand all | Expand 10 after
2448 value->SetString("internal_name", name); 2426 value->SetString("internal_name", name);
2449 value->SetString("description", entry.DescriptionForChoice(i)); 2427 value->SetString("description", entry.DescriptionForChoice(i));
2450 value->SetBoolean("selected", enabled_entries.count(name) > 0); 2428 value->SetBoolean("selected", enabled_entries.count(name) > 0);
2451 result->Append(value); 2429 result->Append(value);
2452 } 2430 }
2453 return result; 2431 return result;
2454 } 2432 }
2455 2433
2456 } // namespace 2434 } // namespace
2457 2435
2458 std::string FeatureEntry::NameForChoice(int index) const {
2459 DCHECK(type == FeatureEntry::MULTI_VALUE ||
2460 type == FeatureEntry::ENABLE_DISABLE_VALUE ||
2461 type == FeatureEntry::FEATURE_VALUE);
2462 DCHECK_LT(index, num_choices);
2463 return std::string(internal_name) + testing::kMultiSeparator +
2464 base::IntToString(index);
2465 }
2466
2467 base::string16 FeatureEntry::DescriptionForChoice(int index) const {
2468 DCHECK(type == FeatureEntry::MULTI_VALUE ||
2469 type == FeatureEntry::ENABLE_DISABLE_VALUE ||
2470 type == FeatureEntry::FEATURE_VALUE);
2471 DCHECK_LT(index, num_choices);
2472 int description_id;
2473 if (type == FeatureEntry::ENABLE_DISABLE_VALUE ||
2474 type == FeatureEntry::FEATURE_VALUE) {
2475 const int kEnableDisableDescriptionIds[] = {
2476 IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT,
2477 IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
2478 IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
2479 };
2480 description_id = kEnableDisableDescriptionIds[index];
2481 } else {
2482 description_id = choices[index].description_id;
2483 }
2484 return l10n_util::GetStringUTF16(description_id);
2485 }
2486
2487 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, 2436 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage,
2488 base::CommandLine* command_line, 2437 base::CommandLine* command_line,
2489 SentinelsMode sentinels) { 2438 SentinelsMode sentinels) {
2490 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage, 2439 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage,
2491 command_line, 2440 command_line,
2492 sentinels); 2441 sentinels);
2493 } 2442 }
2494 2443
2495 bool AreSwitchesIdenticalToCurrentCommandLine( 2444 bool AreSwitchesIdenticalToCurrentCommandLine(
2496 const base::CommandLine& new_cmdline, 2445 const base::CommandLine& new_cmdline,
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2726 command_line); 2675 command_line);
2727 } 2676 }
2728 2677
2729 bool FlagsState::IsRestartNeededToCommitChanges() { 2678 bool FlagsState::IsRestartNeededToCommitChanges() {
2730 return needs_restart_; 2679 return needs_restart_;
2731 } 2680 }
2732 2681
2733 void FlagsState::SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage, 2682 void FlagsState::SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage,
2734 const std::string& internal_name, 2683 const std::string& internal_name,
2735 bool enable) { 2684 bool enable) {
2736 size_t at_index = internal_name.find(testing::kMultiSeparator); 2685 size_t at_index = internal_name.find(flags_ui::testing::kMultiSeparator);
2737 if (at_index != std::string::npos) { 2686 if (at_index != std::string::npos) {
2738 DCHECK(enable); 2687 DCHECK(enable);
2739 // We're being asked to enable a multi-choice entry. Disable the 2688 // We're being asked to enable a multi-choice entry. Disable the
2740 // currently selected choice. 2689 // currently selected choice.
2741 DCHECK_NE(at_index, 0u); 2690 DCHECK_NE(at_index, 0u);
2742 const std::string entry_name = internal_name.substr(0, at_index); 2691 const std::string entry_name = internal_name.substr(0, at_index);
2743 SetFeatureEntryEnabled(flags_storage, entry_name, false); 2692 SetFeatureEntryEnabled(flags_storage, entry_name, false);
2744 2693
2745 // And enable the new choice, if it is not the default first choice. 2694 // And enable the new choice, if it is not the default first choice.
2746 if (internal_name != entry_name + "@0") { 2695 if (internal_name != entry_name + "@0") {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2953 // switch to the end but doesn't remove previous ones). 2902 // switch to the end but doesn't remove previous ones).
2954 std::string switch_value = base::JoinString(features, ","); 2903 std::string switch_value = base::JoinString(features, ",");
2955 if (switch_value != original_switch_value) 2904 if (switch_value != original_switch_value)
2956 command_line->AppendSwitchASCII(switch_name, switch_value); 2905 command_line->AppendSwitchASCII(switch_name, switch_value);
2957 } 2906 }
2958 2907
2959 } // namespace 2908 } // namespace
2960 2909
2961 namespace testing { 2910 namespace testing {
2962 2911
2963 // WARNING: '@' is also used in the html file. If you update this constant you
2964 // also need to update the html file.
2965 const char kMultiSeparator[] = "@";
2966
2967 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0; 2912 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0;
2968 2913
2969 void ClearState() { 2914 void ClearState() {
2970 FlagsState::GetInstance()->Reset(); 2915 FlagsState::GetInstance()->Reset();
2971 } 2916 }
2972 2917
2973 void SetFeatureEntries(const FeatureEntry* entries, size_t count) { 2918 void SetFeatureEntries(const FeatureEntry* entries, size_t count) {
2974 if (!entries) { 2919 if (!entries) {
2975 entries = kFeatureEntries; 2920 entries = kFeatureEntries;
2976 count = arraysize(kFeatureEntries); 2921 count = arraysize(kFeatureEntries);
2977 } 2922 }
2978 FlagsState::GetInstance()->SetFeatureEntries(entries, count); 2923 FlagsState::GetInstance()->SetFeatureEntries(entries, count);
2979 } 2924 }
2980 2925
2981 const FeatureEntry* GetFeatureEntries(size_t* count) { 2926 const FeatureEntry* GetFeatureEntries(size_t* count) {
2982 return FlagsState::GetInstance()->GetFeatureEntries(count); 2927 return FlagsState::GetInstance()->GetFeatureEntries(count);
2983 } 2928 }
2984 2929
2985 } // namespace testing 2930 } // namespace testing
2986 2931
2987 } // namespace about_flags 2932 } // namespace about_flags
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698