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

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: Rebased to ToT and addressed Nico's comments. 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 20 matching lines...) Expand all
31 #include "ui/keyboard/keyboard_switches.h" 31 #include "ui/keyboard/keyboard_switches.h"
32 #include "ui/message_center/message_center_switches.h" 32 #include "ui/message_center/message_center_switches.h"
33 #include "ui/surface/surface_switches.h" 33 #include "ui/surface/surface_switches.h"
34 34
35 #if defined(USE_ASH) 35 #if defined(USE_ASH)
36 #include "ash/ash_switches.h" 36 #include "ash/ash_switches.h"
37 #endif 37 #endif
38 38
39 #if defined(OS_CHROMEOS) 39 #if defined(OS_CHROMEOS)
40 #include "chromeos/chromeos_switches.h" 40 #include "chromeos/chromeos_switches.h"
41 #include "third_party/cros_system_api/switches/chrome_switches.h"
41 #endif 42 #endif
42 43
43 using content::UserMetricsAction; 44 using content::UserMetricsAction;
44 45
45 namespace about_flags { 46 namespace about_flags {
46 47
47 // Macros to simplify specifying the type. 48 // Macros to simplify specifying the type.
48 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ 49 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
49 Experiment::SINGLE_VALUE, \ 50 Experiment::SINGLE_VALUE, \
50 command_line_switch, switch_value, NULL, NULL, NULL, 0 51 command_line_switch, switch_value, NULL, NULL, NULL, 0
(...skipping 25 matching lines...) Expand all
76 {kOsLinux, "Linux"}, 77 {kOsLinux, "Linux"},
77 {kOsCrOS, "Chrome OS"}, 78 {kOsCrOS, "Chrome OS"},
78 {kOsAndroid, "Android"}, 79 {kOsAndroid, "Android"},
79 {kOsCrOSOwnerOnly, "Chrome OS (owner only)"}, 80 {kOsCrOSOwnerOnly, "Chrome OS (owner only)"},
80 }; 81 };
81 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i) 82 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kBitsToOs); ++i)
82 if (bitmask & kBitsToOs[i].bit) 83 if (bitmask & kBitsToOs[i].bit)
83 list->Append(new StringValue(kBitsToOs[i].name)); 84 list->Append(new StringValue(kBitsToOs[i].name));
84 } 85 }
85 86
87 // Convert switch constants to proper CommandLine::StringType strings.
88 CommandLine::StringType GetSwitchString(const std::string& flag) {
89 CommandLine cmd_line(CommandLine::NO_PROGRAM);
90 cmd_line.AppendSwitch(flag);
91 DCHECK(cmd_line.argv().size() == 2);
92 return cmd_line.argv()[1];
93 }
94
95 // Scoops flags from a command line.
96 std::set<CommandLine::StringType> ExtractFlagsFromCommandLine(
97 const CommandLine& cmdline) {
98 std::set<CommandLine::StringType> flags;
99 // First do the ones between --flag-switches-begin and --flag-switches-end.
100 CommandLine::StringVector::const_iterator first =
101 std::find(cmdline.argv().begin(), cmdline.argv().end(),
102 GetSwitchString(switches::kFlagSwitchesBegin));
103 CommandLine::StringVector::const_iterator last =
104 std::find(cmdline.argv().begin(), cmdline.argv().end(),
105 GetSwitchString(switches::kFlagSwitchesEnd));
106 if (first != cmdline.argv().end() && last != cmdline.argv().end())
107 flags.insert(first + 1, last);
108 #if defined(OS_CHROMEOS)
109 // Then add those between --policy-switches-begin and --policy-switches-end.
110 first = std::find(cmdline.argv().begin(), cmdline.argv().end(),
111 GetSwitchString(chromeos::switches::kPolicySwitchesBegin));
112 last = std::find(cmdline.argv().begin(), cmdline.argv().end(),
113 GetSwitchString(chromeos::switches::kPolicySwitchesEnd));
114 if (first != cmdline.argv().end() && last != cmdline.argv().end())
115 flags.insert(first + 1, last);
116 #endif
117 return flags;
118 }
119
86 const Experiment::Choice 120 const Experiment::Choice
87 kOmniboxHistoryQuickProviderReorderForInliningChoices[] = { 121 kOmniboxHistoryQuickProviderReorderForInliningChoices[] = {
88 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_AUTOMATIC, 122 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_AUTOMATIC,
89 "", 123 "",
90 "" }, 124 "" },
91 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_ENABLED, 125 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_ENABLED,
92 switches::kOmniboxHistoryQuickProviderReorderForInlining, 126 switches::kOmniboxHistoryQuickProviderReorderForInlining,
93 switches::kOmniboxHistoryQuickProviderReorderForInliningEnabled }, 127 switches::kOmniboxHistoryQuickProviderReorderForInliningEnabled },
94 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_DISABLED, 128 { IDS_FLAGS_OMNIBOX_HISTORY_QUICK_PROVIDER_REORDER_FOR_INLINING_DISABLED,
95 switches::kOmniboxHistoryQuickProviderReorderForInlining, 129 switches::kOmniboxHistoryQuickProviderReorderForInlining,
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 } 1753 }
1720 return l10n_util::GetStringUTF16(description_id); 1754 return l10n_util::GetStringUTF16(description_id);
1721 } 1755 }
1722 1756
1723 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, 1757 void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
1724 CommandLine* command_line) { 1758 CommandLine* command_line) {
1725 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage, 1759 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage,
1726 command_line); 1760 command_line);
1727 } 1761 }
1728 1762
1763 bool AreSwitchesIdenticalToCurrentCommandLine(
1764 const CommandLine& new_cmdline, const CommandLine& active_cmdline) {
1765 std::set<CommandLine::StringType> new_flags =
1766 ExtractFlagsFromCommandLine(new_cmdline);
1767 std::set<CommandLine::StringType> active_flags =
1768 ExtractFlagsFromCommandLine(active_cmdline);
1769
1770 // Needed because std::equal doesn't check if the 2nd set is empty.
1771 if (new_flags.size() != active_flags.size())
1772 return false;
1773
1774 return std::equal(new_flags.begin(), new_flags.end(), active_flags.begin());
1775 }
1776
1729 void GetFlagsExperimentsData(FlagsStorage* flags_storage, 1777 void GetFlagsExperimentsData(FlagsStorage* flags_storage,
1730 FlagAccess access, 1778 FlagAccess access,
1731 base::ListValue* supported_experiments, 1779 base::ListValue* supported_experiments,
1732 base::ListValue* unsupported_experiments) { 1780 base::ListValue* unsupported_experiments) {
1733 std::set<std::string> enabled_experiments; 1781 std::set<std::string> enabled_experiments;
1734 GetSanitizedEnabledFlags(flags_storage, &enabled_experiments); 1782 GetSanitizedEnabledFlags(flags_storage, &enabled_experiments);
1735 1783
1736 int current_platform = GetCurrentPlatform(); 1784 int current_platform = GetCurrentPlatform();
1737 1785
1738 for (size_t i = 0; i < num_experiments; ++i) { 1786 for (size_t i = 0; i < num_experiments; ++i) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 } 2063 }
2016 2064
2017 const Experiment* GetExperiments(size_t* count) { 2065 const Experiment* GetExperiments(size_t* count) {
2018 *count = num_experiments; 2066 *count = num_experiments;
2019 return experiments; 2067 return experiments;
2020 } 2068 }
2021 2069
2022 } // namespace testing 2070 } // namespace testing
2023 2071
2024 } // namespace about_flags 2072 } // namespace about_flags
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698