Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/about_flags.cc

Issue 16770002: Restart Chrome if per session flags have been specified on ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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;
99 }
100
88 const Experiment::Choice 101 const Experiment::Choice
89 kOmniboxHistoryQuickProviderReorderForInliningChoices[] = { 102 kOmniboxHistoryQuickProviderReorderForInliningChoices[] = {
90 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_AUTOMATIC, 103 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_AUTOMATIC,
91 "", 104 "",
92 "" }, 105 "" },
93 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_ENABLED, 106 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_ENABLED,
94 switches::kOmniboxHistoryQuickProviderReorderForInlining, 107 switches::kOmniboxHistoryQuickProviderReorderForInlining,
95 switches::kOmniboxHistoryQuickProviderReorderForInliningEnabled }, 108 switches::kOmniboxHistoryQuickProviderReorderForInliningEnabled },
96 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_DISABLED, 109 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_DISABLED,
97 switches::kOmniboxHistoryQuickProviderReorderForInlining, 110 switches::kOmniboxHistoryQuickProviderReorderForInlining,
(...skipping 1646 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 } else { 1757 } else {
1745 description_id = choices[index].description_id; 1758 description_id = choices[index].description_id;
1746 } 1759 }
1747 return l10n_util::GetStringUTF16(description_id); 1760 return l10n_util::GetStringUTF16(description_id);
1748 } 1761 }
1749 1762
1750 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) { 1763 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
1751 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line); 1764 FlagsState::GetInstance()->ConvertFlagsToSwitches(prefs, command_line);
1752 } 1765 }
1753 1766
1767 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.
1768 const CommandLine& active_cmdline) {
1769 CommandLine::StringVector new_flags;
1770 CommandLine::StringVector active_flags;
1771 // 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.
1772 CommandLine::StringVector::const_iterator first =
1773 std::find(new_cmdline.argv().begin(), new_cmdline.argv().end(),
1774 GetSwitchString(switches::kFlagSwitchesBegin));
1775 CommandLine::StringVector::const_iterator last =
1776 std::find(new_cmdline.argv().begin(), new_cmdline.argv().end(),
1777 GetSwitchString(switches::kFlagSwitchesEnd));
1778 if (first != new_cmdline.argv().end() && last != new_cmdline.argv().end())
1779 new_flags.assign(first + 1, last);
1780 // Scoop the flags set on the current command line.
1781 // First do the ones between --flag-switches-begin and --flag-switches-end.
1782 first = std::find(active_cmdline.argv().begin(), active_cmdline.argv().end(),
1783 GetSwitchString(switches::kFlagSwitchesBegin));
1784 last = std::find(active_cmdline.argv().begin(), active_cmdline.argv().end(),
1785 GetSwitchString(switches::kFlagSwitchesEnd));
1786 if (first != active_cmdline.argv().end() &&
1787 last != active_cmdline.argv().end()) {
1788 active_flags.assign(first + 1, last);
1789 }
1790 #if defined(OS_CHROMEOS)
1791 // 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
1792 first = std::find(active_cmdline.argv().begin(), active_cmdline.argv().end(),
1793 GetSwitchString(chromeos::switches::kPolicySwitchesBegin));
1794 last = std::find(active_cmdline.argv().begin(), active_cmdline.argv().end(),
1795 GetSwitchString(chromeos::switches::kPolicySwitchesEnd));
1796 if (first != active_cmdline.argv().end() &&
1797 last != active_cmdline.argv().end()) {
1798 active_flags.insert(active_flags.end(), first + 1, last);
1799 }
1800 #endif
1801 // 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.
1802 if (new_flags.size() != active_flags.size())
1803 return false;
1804
1805 // Sort and compare.
1806 std::sort(new_flags.begin(), new_flags.end());
1807 std::sort(active_flags.begin(), active_flags.end());
1808 CommandLine::StringVector::const_iterator new_it = new_flags.begin();
1809 CommandLine::StringVector::const_iterator active_it = active_flags.begin();
1810 for (; new_it != new_flags.end(); ++new_it, ++active_it) {
1811 if (*new_it != *active_it)
1812 return false;
1813 }
1814 return true;
1815 }
1816
1754 void GetFlagsExperimentsData(PrefService* prefs, 1817 void GetFlagsExperimentsData(PrefService* prefs,
1755 FlagAccess access, 1818 FlagAccess access,
1756 base::ListValue* supported_experiments, 1819 base::ListValue* supported_experiments,
1757 base::ListValue* unsupported_experiments) { 1820 base::ListValue* unsupported_experiments) {
1758 std::set<std::string> enabled_experiments; 1821 std::set<std::string> enabled_experiments;
1759 GetSanitizedEnabledFlags(prefs, &enabled_experiments); 1822 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
1760 1823
1761 int current_platform = GetCurrentPlatform(); 1824 int current_platform = GetCurrentPlatform();
1762 1825
1763 for (size_t i = 0; i < num_experiments; ++i) { 1826 for (size_t i = 0; i < num_experiments; ++i) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 } 2100 }
2038 2101
2039 const Experiment* GetExperiments(size_t* count) { 2102 const Experiment* GetExperiments(size_t* count) {
2040 *count = num_experiments; 2103 *count = num_experiments;
2041 return experiments; 2104 return experiments;
2042 } 2105 }
2043 2106
2044 } // namespace testing 2107 } // namespace testing
2045 2108
2046 } // namespace about_flags 2109 } // namespace about_flags
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698