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 <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 22 matching lines...) Expand all Loading... | |
33 #include "ui/keyboard/keyboard_switches.h" | 33 #include "ui/keyboard/keyboard_switches.h" |
34 #include "ui/message_center/message_center_switches.h" | 34 #include "ui/message_center/message_center_switches.h" |
35 #include "ui/surface/surface_switches.h" | 35 #include "ui/surface/surface_switches.h" |
36 | 36 |
37 #if defined(USE_ASH) | 37 #if defined(USE_ASH) |
38 #include "ash/ash_switches.h" | 38 #include "ash/ash_switches.h" |
39 #endif | 39 #endif |
40 | 40 |
41 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
42 #include "chromeos/chromeos_switches.h" | 42 #include "chromeos/chromeos_switches.h" |
43 #include "third_party/cros_system_api/switches/chrome_switches.h" | |
43 #endif | 44 #endif |
44 | 45 |
45 using content::UserMetricsAction; | 46 using content::UserMetricsAction; |
46 | 47 |
47 namespace about_flags { | 48 namespace about_flags { |
48 | 49 |
49 // Macros to simplify specifying the type. | 50 // Macros to simplify specifying the type. |
50 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ | 51 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ |
51 Experiment::SINGLE_VALUE, \ | 52 Experiment::SINGLE_VALUE, \ |
52 command_line_switch, switch_value, NULL, NULL, NULL, 0 | 53 command_line_switch, switch_value, NULL, NULL, NULL, 0 |
(...skipping 25 matching lines...) Expand all Loading... | |
78 {kOsLinux, "Linux"}, | 79 {kOsLinux, "Linux"}, |
79 {kOsCrOS, "Chrome OS"}, | 80 {kOsCrOS, "Chrome OS"}, |
80 {kOsAndroid, "Android"}, | 81 {kOsAndroid, "Android"}, |
81 {kOsCrOSOwnerOnly, "Chrome OS (owner only)"}, | 82 {kOsCrOSOwnerOnly, "Chrome OS (owner only)"}, |
82 }; | 83 }; |
83 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i) | 84 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i) |
84 if (bitmask & kBitsToOs[i].bit) | 85 if (bitmask & kBitsToOs[i].bit) |
85 list->Append(new StringValue(kBitsToOs[i].name)); | 86 list->Append(new StringValue(kBitsToOs[i].name)); |
86 } | 87 } |
87 | 88 |
89 // Convert switch constants to proper CommandLine::StringType strings. | |
90 CommandLine::StringType GetSwitchString(const std::string& flag) { | |
91 #if defined(OS_WIN) | |
92 CommandLine::StringType result(L"--"); | |
93 result.append(ASCIIToWide(flag)); | |
94 #else | |
95 CommandLine::StringType result("--"); | |
96 result.append(flag); | |
97 #endif | |
98 return result; | |
Nico
2013/06/13 17:59:57
Hm, can you do this by building a temporary Comman
pastarmovj
2013/06/14 11:40:38
Done.
| |
99 } | |
100 | |
101 // Scoops flags from a command line. | |
102 std::set<CommandLine::StringType> ExtractFlagsFromCommandLine( | |
103 const CommandLine& cmdline) { | |
104 std::set<CommandLine::StringType> flags; | |
105 // First do the ones between --flag-switches-begin and --flag-switches-end. | |
106 CommandLine::StringVector::const_iterator first = | |
107 std::find(cmdline.argv().begin(), cmdline.argv().end(), | |
108 GetSwitchString(switches::kFlagSwitchesBegin)); | |
109 CommandLine::StringVector::const_iterator last = | |
110 std::find(cmdline.argv().begin(), cmdline.argv().end(), | |
111 GetSwitchString(switches::kFlagSwitchesEnd)); | |
112 if (first != cmdline.argv().end() && last != cmdline.argv().end()) | |
113 flags.insert(first + 1, last); | |
114 #if defined(OS_CHROMEOS) | |
115 // Then add those between --policy-switches-begin and --policy-switches-end. | |
116 first = std::find(cmdline.argv().begin(), cmdline.argv().end(), | |
117 GetSwitchString(chromeos::switches::kPolicySwitchesBegin)); | |
118 last = std::find(cmdline.argv().begin(), cmdline.argv().end(), | |
119 GetSwitchString(chromeos::switches::kPolicySwitchesEnd)); | |
120 if (first != cmdline.argv().end() && last != cmdline.argv().end()) | |
121 flags.insert(first + 1, last); | |
122 #endif | |
123 return flags; | |
124 } | |
125 | |
88 const Experiment::Choice | 126 const Experiment::Choice |
89 kOmniboxHistoryQuickProviderReorderForInliningChoices[] = { | 127 kOmniboxHistoryQuickProviderReorderForInliningChoices[] = { |
90 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_AUTOMATIC, | 128 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_AUTOMATIC, |
91 "", | 129 "", |
92 "" }, | 130 "" }, |
93 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_ENABLED, | 131 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_ENABLED, |
94 switches::kOmniboxHistoryQuickProviderReorderForInlining, | 132 switches::kOmniboxHistoryQuickProviderReorderForInlining, |
95 switches::kOmniboxHistoryQuickProviderReorderForInliningEnabled }, | 133 switches::kOmniboxHistoryQuickProviderReorderForInliningEnabled }, |
96 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_DISABLED, | 134 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_DISABLED, |
97 switches::kOmniboxHistoryQuickProviderReorderForInlining, | 135 switches::kOmniboxHistoryQuickProviderReorderForInlining, |
(...skipping 1653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1751 } else { | 1789 } else { |
1752 description_id = choices[index].description_id; | 1790 description_id = choices[index].description_id; |
1753 } | 1791 } |
1754 return l10n_util::GetStringUTF16(description_id); | 1792 return l10n_util::GetStringUTF16(description_id); |
1755 } | 1793 } |
1756 | 1794 |
1757 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { | 1795 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { |
1758 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line); | 1796 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line); |
1759 } | 1797 } |
1760 | 1798 |
1799 bool CompareSwitchesToCurrentCommandLine(const CommandLine& new_cmdline, | |
1800 const CommandLine& active_cmdline) { | |
1801 std::set<CommandLine::StringType> new_flags = | |
1802 ExtractFlagsFromCommandLine(new_cmdline); | |
1803 std::set<CommandLine::StringType> active_flags = | |
1804 ExtractFlagsFromCommandLine(active_cmdline); | |
1805 | |
1806 // Needed because std::equal doesn't check if the 2nd set is empty. | |
1807 if (new_flags.size() != active_flags.size()) | |
1808 return false; | |
1809 | |
1810 return std::equal(new_flags.begin(), new_flags.end(), active_flags.begin()); | |
1811 } | |
1812 | |
1761 void GetFlagsExperimentsData(PrefService* prefs, | 1813 void GetFlagsExperimentsData(PrefService* prefs, |
1762 FlagAccess access, | 1814 FlagAccess access, |
1763 base::ListValue* supported_experiments, | 1815 base::ListValue* supported_experiments, |
1764 base::ListValue* unsupported_experiments) { | 1816 base::ListValue* unsupported_experiments) { |
1765 std::set<std::string> enabled_experiments; | 1817 std::set<std::string> enabled_experiments; |
1766 GetSanitizedEnabledFlags(prefs, &enabled_experiments); | 1818 GetSanitizedEnabledFlags(prefs, &enabled_experiments); |
1767 | 1819 |
1768 int current_platform = GetCurrentPlatform(); | 1820 int current_platform = GetCurrentPlatform(); |
1769 | 1821 |
1770 for (size_t i = 0; i < num_experiments; ++i) { | 1822 for (size_t i = 0; i < num_experiments; ++i) { |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2044 } | 2096 } |
2045 | 2097 |
2046 const Experiment* GetExperiments(size_t* count) { | 2098 const Experiment* GetExperiments(size_t* count) { |
2047 *count = num_experiments; | 2099 *count = num_experiments; |
2048 return experiments; | 2100 return experiments; |
2049 } | 2101 } |
2050 | 2102 |
2051 } // namespace testing | 2103 } // namespace testing |
2052 | 2104 |
2053 } // namespace about_flags | 2105 } // namespace about_flags |
OLD | NEW |