Index: chrome/browser/about_flags.cc |
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc |
index 10c25401118f20caa5740153e07fe44c2e6e0904..498635a0172126627808ff69d2f14d6f7fda9a38 100644 |
--- a/chrome/browser/about_flags.cc |
+++ b/chrome/browser/about_flags.cc |
@@ -40,6 +40,7 @@ |
#if defined(OS_CHROMEOS) |
#include "chromeos/chromeos_switches.h" |
+#include "third_party/cros_system_api/switches/chrome_switches.h" |
#endif |
using content::UserMetricsAction; |
@@ -85,6 +86,43 @@ void AddOsStrings(unsigned bitmask, ListValue* list) { |
list->Append(new StringValue(kBitsToOs[i].name)); |
} |
+// Convert switch constants to proper CommandLine::StringType strings. |
+CommandLine::StringType GetSwitchString(const std::string& flag) { |
+#if defined(OS_WIN) |
+ CommandLine::StringType result(L"--"); |
+ result.append(ASCIIToWide(flag)); |
+#else |
+ CommandLine::StringType result("--"); |
+ result.append(flag); |
+#endif |
+ 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.
|
+} |
+ |
+// Scoops flags from a command line. |
+std::set<CommandLine::StringType> ExtractFlagsFromCommandLine( |
+ const CommandLine& cmdline) { |
+ std::set<CommandLine::StringType> flags; |
+ // First do the ones between --flag-switches-begin and --flag-switches-end. |
+ CommandLine::StringVector::const_iterator first = |
+ std::find(cmdline.argv().begin(), cmdline.argv().end(), |
+ GetSwitchString(switches::kFlagSwitchesBegin)); |
+ CommandLine::StringVector::const_iterator last = |
+ std::find(cmdline.argv().begin(), cmdline.argv().end(), |
+ GetSwitchString(switches::kFlagSwitchesEnd)); |
+ if (first != cmdline.argv().end() && last != cmdline.argv().end()) |
+ flags.insert(first + 1, last); |
+#if defined(OS_CHROMEOS) |
+ // Then add those between --policy-switches-begin and --policy-switches-end. |
+ first = std::find(cmdline.argv().begin(), cmdline.argv().end(), |
+ GetSwitchString(chromeos::switches::kPolicySwitchesBegin)); |
+ last = std::find(cmdline.argv().begin(), cmdline.argv().end(), |
+ GetSwitchString(chromeos::switches::kPolicySwitchesEnd)); |
+ if (first != cmdline.argv().end() && last != cmdline.argv().end()) |
+ flags.insert(first + 1, last); |
+#endif |
+ return flags; |
+} |
+ |
const Experiment::Choice |
kOmniboxHistoryQuickProviderReorderForInliningChoices[] = { |
{ IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_AUTOMATIC, |
@@ -1758,6 +1796,20 @@ void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { |
FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line); |
} |
+bool CompareSwitchesToCurrentCommandLine(const CommandLine& new_cmdline, |
+ const CommandLine& active_cmdline) { |
+ std::set<CommandLine::StringType> new_flags = |
+ ExtractFlagsFromCommandLine(new_cmdline); |
+ std::set<CommandLine::StringType> active_flags = |
+ ExtractFlagsFromCommandLine(active_cmdline); |
+ |
+ // Needed because std::equal doesn't check if the 2nd set is empty. |
+ if (new_flags.size() != active_flags.size()) |
+ return false; |
+ |
+ return std::equal(new_flags.begin(), new_flags.end(), active_flags.begin()); |
+} |
+ |
void GetFlagsExperimentsData(PrefService* prefs, |
FlagAccess access, |
base::ListValue* supported_experiments, |