Chromium Code Reviews| Index: chrome/browser/about_flags.cc |
| diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc |
| index 7c2771921b0e6b2908d3b6a8b4d8f92a70950cd3..b032b1df8c2389f1f2d18aff13157a2139212453 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,18 @@ 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; |
| +} |
| + |
| const Experiment::Choice |
| kOmniboxHistoryQuickProviderReorderForInliningChoices[] = { |
| { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_AUTOMATIC, |
| @@ -1751,6 +1764,56 @@ void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { |
| FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line); |
| } |
| +bool CompareSwitchesToCurrentCommandLine(const CommandLine& new_cmdline, |
|
Mattias Nissler (ping if slow)
2013/06/12 14:53:03
Not using this here? Maybe move to where the funct
pastarmovj
2013/06/12 16:19:33
Yet this function is used specifically for flags t
Mattias Nissler (ping if slow)
2013/06/13 16:55:57
You are right, it depends on flags knowledge (i.e.
|
| + const CommandLine& active_cmdline) { |
| + CommandLine::StringVector new_flags; |
| + CommandLine::StringVector active_flags; |
| + // Scoop the flags from the new command line. |
|
Mattias Nissler (ping if slow)
2013/06/12 14:53:03
Seems like you could make a helper function for do
pastarmovj
2013/06/12 16:19:33
Done.
|
| + CommandLine::StringVector::const_iterator first = |
| + std::find(new_cmdline.argv().begin(), new_cmdline.argv().end(), |
| + GetSwitchString(switches::kFlagSwitchesBegin)); |
| + CommandLine::StringVector::const_iterator last = |
| + std::find(new_cmdline.argv().begin(), new_cmdline.argv().end(), |
| + GetSwitchString(switches::kFlagSwitchesEnd)); |
| + if (first != new_cmdline.argv().end() && last != new_cmdline.argv().end()) |
| + new_flags.assign(first + 1, last); |
| + // Scoop the flags set on the current command line. |
| + // First do the ones between --flag-switches-begin and --flag-switches-end. |
| + first = std::find(active_cmdline.argv().begin(), active_cmdline.argv().end(), |
| + GetSwitchString(switches::kFlagSwitchesBegin)); |
| + last = std::find(active_cmdline.argv().begin(), active_cmdline.argv().end(), |
| + GetSwitchString(switches::kFlagSwitchesEnd)); |
| + if (first != active_cmdline.argv().end() && |
| + last != active_cmdline.argv().end()) { |
| + active_flags.assign(first + 1, last); |
| + } |
| +#if defined(OS_CHROMEOS) |
| + // Then add those between --policy-switches-begin and --policy-switches-end. |
|
Mattias Nissler (ping if slow)
2013/06/12 14:53:03
Oh, and bonus points for the helper to handle this
pastarmovj
2013/06/12 16:19:33
Well I can do this for both CommandLine's therefor
|
| + first = std::find(active_cmdline.argv().begin(), active_cmdline.argv().end(), |
| + GetSwitchString(chromeos::switches::kPolicySwitchesBegin)); |
| + last = std::find(active_cmdline.argv().begin(), active_cmdline.argv().end(), |
| + GetSwitchString(chromeos::switches::kPolicySwitchesEnd)); |
| + if (first != active_cmdline.argv().end() && |
| + last != active_cmdline.argv().end()) { |
| + active_flags.insert(active_flags.end(), first + 1, last); |
| + } |
| +#endif |
| + // Don't even bother sorting and comparing if the sizes differ. |
|
Mattias Nissler (ping if slow)
2013/06/12 14:53:03
If you were to insert into a std::set directly, th
pastarmovj
2013/06/12 16:19:33
Done.
|
| + if (new_flags.size() != active_flags.size()) |
| + return false; |
| + |
| + // Sort and compare. |
| + std::sort(new_flags.begin(), new_flags.end()); |
| + std::sort(active_flags.begin(), active_flags.end()); |
| + CommandLine::StringVector::const_iterator new_it = new_flags.begin(); |
| + CommandLine::StringVector::const_iterator active_it = active_flags.begin(); |
| + for (; new_it != new_flags.end(); ++new_it, ++active_it) { |
| + if (*new_it != *active_it) |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| void GetFlagsExperimentsData(PrefService* prefs, |
| FlagAccess access, |
| base::ListValue* supported_experiments, |