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

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: Address comment and rebase 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/proximity_auth/switches.h" 41 #include "components/proximity_auth/switches.h"
41 #include "components/search/search_switches.h" 42 #include "components/search/search_switches.h"
42 #include "components/signin/core/common/signin_switches.h" 43 #include "components/signin/core/common/signin_switches.h"
43 #include "components/sync_driver/sync_driver_switches.h" 44 #include "components/sync_driver/sync_driver_switches.h"
44 #include "components/tracing/tracing_switches.h" 45 #include "components/tracing/tracing_switches.h"
45 #include "components/version_info/version_info.h" 46 #include "components/version_info/version_info.h"
46 #include "content/public/browser/user_metrics.h" 47 #include "content/public/browser/user_metrics.h"
47 #include "content/public/common/content_switches.h" 48 #include "content/public/common/content_switches.h"
49 #include "grit/components_strings.h"
48 #include "media/base/media_switches.h" 50 #include "media/base/media_switches.h"
49 #include "media/midi/midi_switches.h" 51 #include "media/midi/midi_switches.h"
50 #include "ui/base/l10n/l10n_util.h" 52 #include "ui/base/l10n/l10n_util.h"
51 #include "ui/base/ui_base_switches.h" 53 #include "ui/base/ui_base_switches.h"
52 #include "ui/display/display_switches.h" 54 #include "ui/display/display_switches.h"
53 #include "ui/events/event_switches.h" 55 #include "ui/events/event_switches.h"
54 #include "ui/gfx/switches.h" 56 #include "ui/gfx/switches.h"
55 #include "ui/gl/gl_switches.h" 57 #include "ui/gl/gl_switches.h"
56 #include "ui/keyboard/keyboard_switches.h" 58 #include "ui/keyboard/keyboard_switches.h"
57 #include "ui/native_theme/native_theme_switches.h" 59 #include "ui/native_theme/native_theme_switches.h"
(...skipping 21 matching lines...) Expand all
79 #endif 81 #endif
80 82
81 #if defined(ENABLE_PRINT_PREVIEW) 83 #if defined(ENABLE_PRINT_PREVIEW)
82 #include "chrome/browser/ui/webui/print_preview/print_preview_distiller.h" 84 #include "chrome/browser/ui/webui/print_preview/print_preview_distiller.h"
83 #endif 85 #endif
84 86
85 #if defined(USE_OZONE) 87 #if defined(USE_OZONE)
86 #include "ui/ozone/public/ozone_switches.h" 88 #include "ui/ozone/public/ozone_switches.h"
87 #endif 89 #endif
88 90
91 using flags_ui::FeatureEntry;
92
89 namespace about_flags { 93 namespace about_flags {
90 94
91 // Macros to simplify specifying the type. Please refer to the comments on
92 // FeatureEntry::Type in the header file, which explain the different entry
93 // types and when they should be used.
94 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
95 FeatureEntry::SINGLE_VALUE, command_line_switch, switch_value, nullptr, \
96 nullptr, nullptr, nullptr, 0
97 #define SINGLE_VALUE_TYPE(command_line_switch) \
98 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
99 #define SINGLE_DISABLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
100 FeatureEntry::SINGLE_DISABLE_VALUE, command_line_switch, switch_value, \
101 nullptr, nullptr, nullptr, nullptr, 0
102 #define SINGLE_DISABLE_VALUE_TYPE(command_line_switch) \
103 SINGLE_DISABLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
104 #define ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(enable_switch, enable_value, \
105 disable_switch, disable_value) \
106 FeatureEntry::ENABLE_DISABLE_VALUE, enable_switch, enable_value, \
107 disable_switch, disable_value, nullptr, nullptr, 3
108 #define ENABLE_DISABLE_VALUE_TYPE(enable_switch, disable_switch) \
109 ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(enable_switch, "", disable_switch, "")
110 #define MULTI_VALUE_TYPE(choices) \
111 FeatureEntry::MULTI_VALUE, nullptr, nullptr, nullptr, nullptr, nullptr, \
112 choices, arraysize(choices)
113 #define FEATURE_VALUE_TYPE(feature) \
114 FeatureEntry::FEATURE_VALUE, nullptr, nullptr, nullptr, nullptr, \
115 &feature, nullptr, 3
116
117 namespace { 95 namespace {
118 96
119 // Enumeration of OSs. 97 // Enumeration of OSs.
120 enum { 98 enum {
121 kOsMac = 1 << 0, 99 kOsMac = 1 << 0,
122 kOsWin = 1 << 1, 100 kOsWin = 1 << 1,
123 kOsLinux = 1 << 2, 101 kOsLinux = 1 << 2,
124 kOsCrOS = 1 << 3, 102 kOsCrOS = 1 << 3,
125 kOsAndroid = 1 << 4, 103 kOsAndroid = 1 << 4,
126 kOsCrOSOwnerOnly = 1 << 5 104 kOsCrOSOwnerOnly = 1 << 5
(...skipping 2311 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 value->SetString("internal_name", name); 2416 value->SetString("internal_name", name);
2439 value->SetString("description", entry.DescriptionForChoice(i)); 2417 value->SetString("description", entry.DescriptionForChoice(i));
2440 value->SetBoolean("selected", enabled_entries.count(name) > 0); 2418 value->SetBoolean("selected", enabled_entries.count(name) > 0);
2441 result->Append(value); 2419 result->Append(value);
2442 } 2420 }
2443 return result; 2421 return result;
2444 } 2422 }
2445 2423
2446 } // namespace 2424 } // namespace
2447 2425
2448 std::string FeatureEntry::NameForChoice(int index) const {
2449 DCHECK(type == FeatureEntry::MULTI_VALUE ||
2450 type == FeatureEntry::ENABLE_DISABLE_VALUE ||
2451 type == FeatureEntry::FEATURE_VALUE);
2452 DCHECK_LT(index, num_choices);
2453 return std::string(internal_name) + testing::kMultiSeparator +
2454 base::IntToString(index);
2455 }
2456
2457 base::string16 FeatureEntry::DescriptionForChoice(int index) const {
2458 DCHECK(type == FeatureEntry::MULTI_VALUE ||
2459 type == FeatureEntry::ENABLE_DISABLE_VALUE ||
2460 type == FeatureEntry::FEATURE_VALUE);
2461 DCHECK_LT(index, num_choices);
2462 int description_id;
2463 if (type == FeatureEntry::ENABLE_DISABLE_VALUE ||
2464 type == FeatureEntry::FEATURE_VALUE) {
2465 const int kEnableDisableDescriptionIds[] = {
2466 IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT,
2467 IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED,
2468 IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED,
2469 };
2470 description_id = kEnableDisableDescriptionIds[index];
2471 } else {
2472 description_id = choices[index].description_id;
2473 }
2474 return l10n_util::GetStringUTF16(description_id);
2475 }
2476
2477 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, 2426 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage,
2478 base::CommandLine* command_line, 2427 base::CommandLine* command_line,
2479 SentinelsMode sentinels) { 2428 SentinelsMode sentinels) {
2480 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage, 2429 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage,
2481 command_line, 2430 command_line,
2482 sentinels); 2431 sentinels);
2483 } 2432 }
2484 2433
2485 bool AreSwitchesIdenticalToCurrentCommandLine( 2434 bool AreSwitchesIdenticalToCurrentCommandLine(
2486 const base::CommandLine& new_cmdline, 2435 const base::CommandLine& new_cmdline,
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
2715 command_line); 2664 command_line);
2716 } 2665 }
2717 2666
2718 bool FlagsState::IsRestartNeededToCommitChanges() { 2667 bool FlagsState::IsRestartNeededToCommitChanges() {
2719 return needs_restart_; 2668 return needs_restart_;
2720 } 2669 }
2721 2670
2722 void FlagsState::SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage, 2671 void FlagsState::SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage,
2723 const std::string& internal_name, 2672 const std::string& internal_name,
2724 bool enable) { 2673 bool enable) {
2725 size_t at_index = internal_name.find(testing::kMultiSeparator); 2674 size_t at_index = internal_name.find(flags_ui::testing::kMultiSeparator);
2726 if (at_index != std::string::npos) { 2675 if (at_index != std::string::npos) {
2727 DCHECK(enable); 2676 DCHECK(enable);
2728 // We're being asked to enable a multi-choice entry. Disable the 2677 // We're being asked to enable a multi-choice entry. Disable the
2729 // currently selected choice. 2678 // currently selected choice.
2730 DCHECK_NE(at_index, 0u); 2679 DCHECK_NE(at_index, 0u);
2731 const std::string entry_name = internal_name.substr(0, at_index); 2680 const std::string entry_name = internal_name.substr(0, at_index);
2732 SetFeatureEntryEnabled(flags_storage, entry_name, false); 2681 SetFeatureEntryEnabled(flags_storage, entry_name, false);
2733 2682
2734 // And enable the new choice, if it is not the default first choice. 2683 // And enable the new choice, if it is not the default first choice.
2735 if (internal_name != entry_name + "@0") { 2684 if (internal_name != entry_name + "@0") {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2942 // switch to the end but doesn't remove previous ones). 2891 // switch to the end but doesn't remove previous ones).
2943 std::string switch_value = base::JoinString(features, ","); 2892 std::string switch_value = base::JoinString(features, ",");
2944 if (switch_value != original_switch_value) 2893 if (switch_value != original_switch_value)
2945 command_line->AppendSwitchASCII(switch_name, switch_value); 2894 command_line->AppendSwitchASCII(switch_name, switch_value);
2946 } 2895 }
2947 2896
2948 } // namespace 2897 } // namespace
2949 2898
2950 namespace testing { 2899 namespace testing {
2951 2900
2952 // WARNING: '@' is also used in the html file. If you update this constant you
2953 // also need to update the html file.
2954 const char kMultiSeparator[] = "@";
2955
2956 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0; 2901 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0;
2957 2902
2958 void ClearState() { 2903 void ClearState() {
2959 FlagsState::GetInstance()->Reset(); 2904 FlagsState::GetInstance()->Reset();
2960 } 2905 }
2961 2906
2962 void SetFeatureEntries(const FeatureEntry* entries, size_t count) { 2907 void SetFeatureEntries(const FeatureEntry* entries, size_t count) {
2963 if (!entries) { 2908 if (!entries) {
2964 entries = kFeatureEntries; 2909 entries = kFeatureEntries;
2965 count = arraysize(kFeatureEntries); 2910 count = arraysize(kFeatureEntries);
2966 } 2911 }
2967 FlagsState::GetInstance()->SetFeatureEntries(entries, count); 2912 FlagsState::GetInstance()->SetFeatureEntries(entries, count);
2968 } 2913 }
2969 2914
2970 const FeatureEntry* GetFeatureEntries(size_t* count) { 2915 const FeatureEntry* GetFeatureEntries(size_t* count) {
2971 return FlagsState::GetInstance()->GetFeatureEntries(count); 2916 return FlagsState::GetInstance()->GetFeatureEntries(count);
2972 } 2917 }
2973 2918
2974 } // namespace testing 2919 } // namespace testing
2975 2920
2976 } // namespace about_flags 2921 } // namespace about_flags
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698