Index: chrome/browser/about_flags.cc |
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc |
index 10c25401118f20caa5740153e07fe44c2e6e0904..cf2d56f53d24fedafe094e12740dd2de367e4c5f 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; |
+} |
+ |
+// 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); |
Mattias Nissler (ping if slow)
2013/06/13 16:55:57
if you pass the delimiters as parameters, you can
pastarmovj
2013/06/13 17:29:36
I decided that it was not worth it, because it wil
|
+#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,26 @@ 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); |
+ |
+ // Don't even bother comparing if the sizes differ. |
Mattias Nissler (ping if slow)
2013/06/13 16:55:57
can't you just do this?
std::equal(new_flags.firs
pastarmovj
2013/06/13 17:29:36
True, dunno why I got the heavier version here :)
|
+ if (new_flags.size() != active_flags.size()) |
+ return false; |
+ |
+ CommandLine::StringVector flags_difference(new_flags.size() + |
+ active_flags.size()); |
+ CommandLine::StringVector::iterator last_difference = |
+ std::set_symmetric_difference(new_flags.begin(), new_flags.end(), |
+ active_flags.begin(), active_flags.end(), |
+ flags_difference.begin()); |
+ return last_difference == flags_difference.begin(); |
+} |
+ |
void GetFlagsExperimentsData(PrefService* prefs, |
FlagAccess access, |
base::ListValue* supported_experiments, |