OLD | NEW |
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 Loading... |
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 Loading... |
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 2318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2445 value->SetString("internal_name", name); | 2423 value->SetString("internal_name", name); |
2446 value->SetString("description", entry.DescriptionForChoice(i)); | 2424 value->SetString("description", entry.DescriptionForChoice(i)); |
2447 value->SetBoolean("selected", enabled_entries.count(name) > 0); | 2425 value->SetBoolean("selected", enabled_entries.count(name) > 0); |
2448 result->Append(value); | 2426 result->Append(value); |
2449 } | 2427 } |
2450 return result; | 2428 return result; |
2451 } | 2429 } |
2452 | 2430 |
2453 } // namespace | 2431 } // namespace |
2454 | 2432 |
2455 std::string FeatureEntry::NameForChoice(int index) const { | |
2456 DCHECK(type == FeatureEntry::MULTI_VALUE || | |
2457 type == FeatureEntry::ENABLE_DISABLE_VALUE || | |
2458 type == FeatureEntry::FEATURE_VALUE); | |
2459 DCHECK_LT(index, num_choices); | |
2460 return std::string(internal_name) + testing::kMultiSeparator + | |
2461 base::IntToString(index); | |
2462 } | |
2463 | |
2464 base::string16 FeatureEntry::DescriptionForChoice(int index) const { | |
2465 DCHECK(type == FeatureEntry::MULTI_VALUE || | |
2466 type == FeatureEntry::ENABLE_DISABLE_VALUE || | |
2467 type == FeatureEntry::FEATURE_VALUE); | |
2468 DCHECK_LT(index, num_choices); | |
2469 int description_id; | |
2470 if (type == FeatureEntry::ENABLE_DISABLE_VALUE || | |
2471 type == FeatureEntry::FEATURE_VALUE) { | |
2472 const int kEnableDisableDescriptionIds[] = { | |
2473 IDS_GENERIC_EXPERIMENT_CHOICE_DEFAULT, | |
2474 IDS_GENERIC_EXPERIMENT_CHOICE_ENABLED, | |
2475 IDS_GENERIC_EXPERIMENT_CHOICE_DISABLED, | |
2476 }; | |
2477 description_id = kEnableDisableDescriptionIds[index]; | |
2478 } else { | |
2479 description_id = choices[index].description_id; | |
2480 } | |
2481 return l10n_util::GetStringUTF16(description_id); | |
2482 } | |
2483 | |
2484 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, | 2433 void ConvertFlagsToSwitches(flags_ui::FlagsStorage* flags_storage, |
2485 base::CommandLine* command_line, | 2434 base::CommandLine* command_line, |
2486 SentinelsMode sentinels) { | 2435 SentinelsMode sentinels) { |
2487 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage, | 2436 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage, |
2488 command_line, | 2437 command_line, |
2489 sentinels); | 2438 sentinels); |
2490 } | 2439 } |
2491 | 2440 |
2492 bool AreSwitchesIdenticalToCurrentCommandLine( | 2441 bool AreSwitchesIdenticalToCurrentCommandLine( |
2493 const base::CommandLine& new_cmdline, | 2442 const base::CommandLine& new_cmdline, |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2722 command_line); | 2671 command_line); |
2723 } | 2672 } |
2724 | 2673 |
2725 bool FlagsState::IsRestartNeededToCommitChanges() { | 2674 bool FlagsState::IsRestartNeededToCommitChanges() { |
2726 return needs_restart_; | 2675 return needs_restart_; |
2727 } | 2676 } |
2728 | 2677 |
2729 void FlagsState::SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage, | 2678 void FlagsState::SetFeatureEntryEnabled(flags_ui::FlagsStorage* flags_storage, |
2730 const std::string& internal_name, | 2679 const std::string& internal_name, |
2731 bool enable) { | 2680 bool enable) { |
2732 size_t at_index = internal_name.find(testing::kMultiSeparator); | 2681 size_t at_index = internal_name.find(flags_ui::testing::kMultiSeparator); |
2733 if (at_index != std::string::npos) { | 2682 if (at_index != std::string::npos) { |
2734 DCHECK(enable); | 2683 DCHECK(enable); |
2735 // We're being asked to enable a multi-choice entry. Disable the | 2684 // We're being asked to enable a multi-choice entry. Disable the |
2736 // currently selected choice. | 2685 // currently selected choice. |
2737 DCHECK_NE(at_index, 0u); | 2686 DCHECK_NE(at_index, 0u); |
2738 const std::string entry_name = internal_name.substr(0, at_index); | 2687 const std::string entry_name = internal_name.substr(0, at_index); |
2739 SetFeatureEntryEnabled(flags_storage, entry_name, false); | 2688 SetFeatureEntryEnabled(flags_storage, entry_name, false); |
2740 | 2689 |
2741 // And enable the new choice, if it is not the default first choice. | 2690 // And enable the new choice, if it is not the default first choice. |
2742 if (internal_name != entry_name + "@0") { | 2691 if (internal_name != entry_name + "@0") { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2949 // switch to the end but doesn't remove previous ones). | 2898 // switch to the end but doesn't remove previous ones). |
2950 std::string switch_value = base::JoinString(features, ","); | 2899 std::string switch_value = base::JoinString(features, ","); |
2951 if (switch_value != original_switch_value) | 2900 if (switch_value != original_switch_value) |
2952 command_line->AppendSwitchASCII(switch_name, switch_value); | 2901 command_line->AppendSwitchASCII(switch_name, switch_value); |
2953 } | 2902 } |
2954 | 2903 |
2955 } // namespace | 2904 } // namespace |
2956 | 2905 |
2957 namespace testing { | 2906 namespace testing { |
2958 | 2907 |
2959 // WARNING: '@' is also used in the html file. If you update this constant you | |
2960 // also need to update the html file. | |
2961 const char kMultiSeparator[] = "@"; | |
2962 | |
2963 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0; | 2908 const base::HistogramBase::Sample kBadSwitchFormatHistogramId = 0; |
2964 | 2909 |
2965 void ClearState() { | 2910 void ClearState() { |
2966 FlagsState::GetInstance()->Reset(); | 2911 FlagsState::GetInstance()->Reset(); |
2967 } | 2912 } |
2968 | 2913 |
2969 void SetFeatureEntries(const FeatureEntry* entries, size_t count) { | 2914 void SetFeatureEntries(const FeatureEntry* entries, size_t count) { |
2970 if (!entries) { | 2915 if (!entries) { |
2971 entries = kFeatureEntries; | 2916 entries = kFeatureEntries; |
2972 count = arraysize(kFeatureEntries); | 2917 count = arraysize(kFeatureEntries); |
2973 } | 2918 } |
2974 FlagsState::GetInstance()->SetFeatureEntries(entries, count); | 2919 FlagsState::GetInstance()->SetFeatureEntries(entries, count); |
2975 } | 2920 } |
2976 | 2921 |
2977 const FeatureEntry* GetFeatureEntries(size_t* count) { | 2922 const FeatureEntry* GetFeatureEntries(size_t* count) { |
2978 return FlagsState::GetInstance()->GetFeatureEntries(count); | 2923 return FlagsState::GetInstance()->GetFeatureEntries(count); |
2979 } | 2924 } |
2980 | 2925 |
2981 } // namespace testing | 2926 } // namespace testing |
2982 | 2927 |
2983 } // namespace about_flags | 2928 } // namespace about_flags |
OLD | NEW |