OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_FLAGS_UI_FLAGS_STATE_H_ | |
6 #define COMPONENTS_FLAGS_UI_FLAGS_STATE_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 #include <string> | |
11 | |
12 #include "base/callback_forward.h" | |
13 #include "base/command_line.h" | |
14 #include "base/macros.h" | |
15 | |
16 namespace base { | |
17 class ListValue; | |
18 } | |
19 | |
20 namespace flags_ui { | |
21 | |
22 struct FeatureEntry; | |
23 class FlagsStorage; | |
24 struct SwitchEntry; | |
25 | |
26 // Enumeration of OSs. | |
27 enum { | |
28 kOsMac = 1 << 0, | |
29 kOsWin = 1 << 1, | |
30 kOsLinux = 1 << 2, | |
31 kOsCrOS = 1 << 3, | |
32 kOsAndroid = 1 << 4, | |
33 kOsCrOSOwnerOnly = 1 << 5 | |
34 }; | |
35 | |
36 // A flag controlling the behavior of the |ConvertFlagsToSwitches| function - | |
37 // whether it should add the sentinel switches around flags. | |
38 enum SentinelsMode { kNoSentinels, kAddSentinels }; | |
39 | |
40 // Differentiate between generic flags available on a per session base and flags | |
41 // that influence the whole machine and can be said by the admin only. This flag | |
42 // is relevant for ChromeOS for now only and dictates whether entries marked | |
43 // with the |kOsCrOSOwnerOnly| label should be enabled in the UI or not. | |
44 enum FlagAccess { kGeneralAccessFlagsOnly, kOwnerAccessToFlags }; | |
45 | |
46 // Stores and encapsulates the little state that about:flags has. | |
47 class FlagsState { | |
48 public: | |
49 FlagsState(const FeatureEntry* feature_entries, size_t num_feature_entries); | |
50 ~FlagsState(); | |
51 | |
52 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, | |
53 base::CommandLine* command_line, | |
54 SentinelsMode sentinels, | |
55 const char* enable_features_flag_name, | |
56 const char* disable_features_flag_name); | |
57 bool IsRestartNeededToCommitChanges(); | |
58 void SetFeatureEntryEnabled(FlagsStorage* flags_storage, | |
59 const std::string& internal_name, | |
60 bool enable); | |
61 void RemoveFlagsSwitches( | |
62 std::map<std::string, base::CommandLine::StringType>* switch_list); | |
63 void ResetAllFlags(FlagsStorage* flags_storage); | |
64 void Reset(); | |
65 | |
66 // Gets the list of feature entries. Entries that are available for the | |
67 // current platform are appended to |supported_entries|; all other entries are | |
68 // appended to |unsupported_entries|. | |
69 void GetFlagFeatureEntries( | |
70 FlagsStorage* flags_storage, | |
71 FlagAccess access, | |
72 base::ListValue* supported_entries, | |
73 base::ListValue* unsupported_entries, | |
74 base::Callback<bool(const FeatureEntry&)> skip_feature_entry); | |
75 | |
76 // Returns the value for the current platform. This is one of the values | |
77 // defined by the OS enum above. | |
78 // This is exposed only for testing. | |
79 static int GetCurrentPlatform(); | |
80 | |
81 // Compares a set of switches of the two provided command line objects and | |
82 // returns true if they are the same and false otherwise. | |
83 // If |out_difference| is not NULL, it's filled with set_symmetric_difference | |
84 // between sets. | |
85 static bool AreSwitchesIdenticalToCurrentCommandLine( | |
86 const base::CommandLine& new_cmdline, | |
87 const base::CommandLine& active_cmdline, | |
88 std::set<base::CommandLine::StringType>* out_difference, | |
89 const char* extra_flag_sentinel_begin_flag_name, | |
Alexei Svitkine (slow)
2015/11/16 21:52:54
Nit: Document the new params.
sdefresne
2015/11/17 16:28:56
Done.
| |
90 const char* extra_flag_sentinel_end_flag_name); | |
91 | |
92 private: | |
93 // Adds mapping to |name_to_switch_map| to set the given switch name/value. | |
94 void AddSwitchMapping(const std::string& key, | |
95 const std::string& switch_name, | |
96 const std::string& switch_value, | |
97 std::map<std::string, SwitchEntry>* name_to_switch_map); | |
98 | |
99 // Adds mapping to |name_to_switch_map| to toggle base::Feature |feature_name| | |
100 // to state |feature_state|. | |
101 void AddFeatureMapping( | |
102 const std::string& key, | |
103 const std::string& feature_name, | |
104 bool feature_state, | |
105 std::map<std::string, SwitchEntry>* name_to_switch_map); | |
106 | |
107 // Updates the switches in |command_line| by applying the modifications | |
108 // specified in |name_to_switch_map| for each entry in |enabled_entries|. | |
109 void AddSwitchesToCommandLine( | |
110 const std::set<std::string>& enabled_entries, | |
111 const std::map<std::string, SwitchEntry>& name_to_switch_map, | |
112 SentinelsMode sentinels, | |
113 base::CommandLine* command_line, | |
114 const char* enable_features_flag_name, | |
115 const char* disable_features_flag_name); | |
116 | |
117 // Updates |command_line| by merging the value of the --enable-features= or | |
118 // --disable-features= list (per the |switch_name| param) with corresponding | |
119 // entries in |feature_switches| that have value |feature_state|. Keeps track | |
120 // of the changes by updating |appended_switches|. | |
121 void MergeFeatureCommandLineSwitch( | |
122 const std::map<std::string, bool>& feature_switches, | |
123 const char* switch_name, | |
124 bool feature_state, | |
125 base::CommandLine* command_line); | |
126 | |
127 // Removes all entries from prefs::kEnabledLabsExperiments that are unknown, | |
128 // to prevent this list to become very long as entries are added and removed. | |
129 void SanitizeList(FlagsStorage* flags_storage); | |
130 | |
131 void GetSanitizedEnabledFlags(FlagsStorage* flags_storage, | |
132 std::set<std::string>* result); | |
133 | |
134 // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't | |
135 // enabled on the current platform. | |
136 void GetSanitizedEnabledFlagsForCurrentPlatform( | |
137 FlagsStorage* flags_storage, | |
138 std::set<std::string>* result); | |
139 | |
140 const FeatureEntry* feature_entries_; | |
141 size_t num_feature_entries_; | |
142 | |
143 bool needs_restart_; | |
144 std::map<std::string, std::string> flags_switches_; | |
145 | |
146 // Map from switch name to a set of string, that keeps track which strings | |
147 // were appended to existing (list value) switches. | |
148 std::map<std::string, std::set<std::string>> appended_switches_; | |
149 | |
150 DISALLOW_COPY_AND_ASSIGN(FlagsState); | |
151 }; | |
152 | |
153 } // namespace flags_ui | |
154 | |
155 #endif // COMPONENTS_FLAGS_UI_FLAGS_STATE_H_ | |
OLD | NEW |