Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_FLAGS_UI_FLAGS_STATE_H_ | 5 #ifndef COMPONENTS_FLAGS_UI_FLAGS_STATE_H_ |
| 6 #define COMPONENTS_FLAGS_UI_FLAGS_STATE_H_ | 6 #define COMPONENTS_FLAGS_UI_FLAGS_STATE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 ~FlagsState(); | 66 ~FlagsState(); |
| 67 | 67 |
| 68 // Reads the state from |flags_storage| and adds the command line flags | 68 // Reads the state from |flags_storage| and adds the command line flags |
| 69 // belonging to the active feature entries to |command_line|. Features are | 69 // belonging to the active feature entries to |command_line|. Features are |
| 70 // appended via |enable_features_flag_name| and |disable_features_flag_name|. | 70 // appended via |enable_features_flag_name| and |disable_features_flag_name|. |
| 71 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, | 71 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, |
| 72 base::CommandLine* command_line, | 72 base::CommandLine* command_line, |
| 73 SentinelsMode sentinels, | 73 SentinelsMode sentinels, |
| 74 const char* enable_features_flag_name, | 74 const char* enable_features_flag_name, |
| 75 const char* disable_features_flag_name); | 75 const char* disable_features_flag_name); |
| 76 | |
| 77 // Reads the state from |flags_storage| and adds the command line flags that | |
| 78 // correspond to enabled entries to |switches|. Does not populate any | |
| 79 // information about entries that enable/disable base::Feature states. | |
|
Ilya Sherman
2016/08/31 19:06:31
Hmm. I would expect that over time, the majority
Alexei Svitkine (slow)
2016/08/31 19:46:22
Agreed. Filed a bug for it here: crbug.com/642858
| |
| 80 void GetSwitchesFromFlags(FlagsStorage* flags_storage, | |
|
Ilya Sherman
2016/08/31 19:06:31
nit: Could this be passed by const-ref?
Alexei Svitkine (slow)
2016/08/31 19:46:22
I checked, but it's not possible because it eventu
| |
| 81 std::set<std::string>* switches); | |
|
Ilya Sherman
2016/08/31 19:06:31
nit: Please return the set, rather than writing to
Alexei Svitkine (slow)
2016/08/31 19:46:22
Done.
| |
| 82 | |
| 76 bool IsRestartNeededToCommitChanges(); | 83 bool IsRestartNeededToCommitChanges(); |
| 77 void SetFeatureEntryEnabled(FlagsStorage* flags_storage, | 84 void SetFeatureEntryEnabled(FlagsStorage* flags_storage, |
| 78 const std::string& internal_name, | 85 const std::string& internal_name, |
| 79 bool enable); | 86 bool enable); |
| 80 void RemoveFlagsSwitches( | 87 void RemoveFlagsSwitches( |
| 81 std::map<std::string, base::CommandLine::StringType>* switch_list); | 88 std::map<std::string, base::CommandLine::StringType>* switch_list); |
| 82 void ResetAllFlags(FlagsStorage* flags_storage); | 89 void ResetAllFlags(FlagsStorage* flags_storage); |
| 83 void Reset(); | 90 void Reset(); |
| 84 | 91 |
| 85 // Registers variations parameter values selected for features in about:flags. | 92 // Registers variations parameter values selected for features in about:flags. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 115 // compared. The embedder may use |extra_flag_sentinel_begin_flag_name| and | 122 // compared. The embedder may use |extra_flag_sentinel_begin_flag_name| and |
| 116 // |extra_sentinel_end_flag_name| to specify other delimiters, if supported. | 123 // |extra_sentinel_end_flag_name| to specify other delimiters, if supported. |
| 117 static bool AreSwitchesIdenticalToCurrentCommandLine( | 124 static bool AreSwitchesIdenticalToCurrentCommandLine( |
| 118 const base::CommandLine& new_cmdline, | 125 const base::CommandLine& new_cmdline, |
| 119 const base::CommandLine& active_cmdline, | 126 const base::CommandLine& active_cmdline, |
| 120 std::set<base::CommandLine::StringType>* out_difference, | 127 std::set<base::CommandLine::StringType>* out_difference, |
| 121 const char* extra_flag_sentinel_begin_flag_name, | 128 const char* extra_flag_sentinel_begin_flag_name, |
| 122 const char* extra_flag_sentinel_end_flag_name); | 129 const char* extra_flag_sentinel_end_flag_name); |
| 123 | 130 |
| 124 private: | 131 private: |
| 132 // Keeps track of affected switches for each FeatureEntry, based on which | |
| 133 // choice is selected for it. | |
| 134 struct SwitchEntry { | |
| 135 // Corresponding base::Feature to toggle. | |
| 136 std::string feature_name; | |
| 137 | |
| 138 // If |feature_name| is not empty, the state (enable/disabled) to set. | |
| 139 bool feature_state; | |
| 140 | |
| 141 // The name of the switch to add. | |
| 142 std::string switch_name; | |
| 143 | |
| 144 // If |switch_name| is not empty, the value of the switch to set. | |
| 145 std::string switch_value; | |
| 146 | |
| 147 SwitchEntry(); | |
| 148 ~SwitchEntry(); | |
| 149 }; | |
|
Ilya Sherman
2016/08/31 19:06:31
Optional nit: FWIW, you could probably just declar
Alexei Svitkine (slow)
2016/08/31 19:46:22
Done. Interestingly, I could keep the order of dec
| |
| 150 | |
| 125 // Adds mapping to |name_to_switch_map| to set the given switch name/value. | 151 // Adds mapping to |name_to_switch_map| to set the given switch name/value. |
| 126 void AddSwitchMapping(const std::string& key, | 152 void AddSwitchMapping(const std::string& key, |
| 127 const std::string& switch_name, | 153 const std::string& switch_name, |
| 128 const std::string& switch_value, | 154 const std::string& switch_value, |
| 129 std::map<std::string, SwitchEntry>* name_to_switch_map); | 155 std::map<std::string, SwitchEntry>* name_to_switch_map); |
| 130 | 156 |
| 131 // Adds mapping to |name_to_switch_map| to toggle base::Feature |feature_name| | 157 // Adds mapping to |name_to_switch_map| to toggle base::Feature |feature_name| |
| 132 // to state |feature_state|. | 158 // to state |feature_state|. |
| 133 void AddFeatureMapping( | 159 void AddFeatureMapping( |
| 134 const std::string& key, | 160 const std::string& key, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 164 | 190 |
| 165 void GetSanitizedEnabledFlags(FlagsStorage* flags_storage, | 191 void GetSanitizedEnabledFlags(FlagsStorage* flags_storage, |
| 166 std::set<std::string>* result); | 192 std::set<std::string>* result); |
| 167 | 193 |
| 168 // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't | 194 // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't |
| 169 // enabled on the current platform. | 195 // enabled on the current platform. |
| 170 void GetSanitizedEnabledFlagsForCurrentPlatform( | 196 void GetSanitizedEnabledFlagsForCurrentPlatform( |
| 171 FlagsStorage* flags_storage, | 197 FlagsStorage* flags_storage, |
| 172 std::set<std::string>* result); | 198 std::set<std::string>* result); |
| 173 | 199 |
| 200 // Generates a flags to switches mapping based on the set of enabled flags | |
| 201 // from |flags_storage|. On output, |enable_entries| will contain the internal | |
|
Ilya Sherman
2016/08/31 19:06:31
nit: s/enable_entries/enabled_entries
Alexei Svitkine (slow)
2016/08/31 19:46:22
Done.
| |
| 202 // names of enabled flags and |name_to_switch_map| will contain information | |
| 203 // on how they map to command-line flags or features. | |
| 204 void GenerateFlagsToSwitchesMapping( | |
| 205 FlagsStorage* flags_storage, | |
| 206 std::set<std::string>* enabled_entries, | |
| 207 std::map<std::string, SwitchEntry>* name_to_switch_map); | |
| 208 | |
| 174 const FeatureEntry* feature_entries_; | 209 const FeatureEntry* feature_entries_; |
| 175 size_t num_feature_entries_; | 210 size_t num_feature_entries_; |
| 176 | 211 |
| 177 bool needs_restart_; | 212 bool needs_restart_; |
| 178 std::map<std::string, std::string> flags_switches_; | 213 std::map<std::string, std::string> flags_switches_; |
| 179 | 214 |
| 180 // Map from switch name to a set of string, that keeps track which strings | 215 // Map from switch name to a set of string, that keeps track which strings |
| 181 // were appended to existing (list value) switches. | 216 // were appended to existing (list value) switches. |
| 182 std::map<std::string, std::set<std::string>> appended_switches_; | 217 std::map<std::string, std::set<std::string>> appended_switches_; |
| 183 | 218 |
| 184 DISALLOW_COPY_AND_ASSIGN(FlagsState); | 219 DISALLOW_COPY_AND_ASSIGN(FlagsState); |
| 185 }; | 220 }; |
| 186 | 221 |
| 187 } // namespace flags_ui | 222 } // namespace flags_ui |
| 188 | 223 |
| 189 #endif // COMPONENTS_FLAGS_UI_FLAGS_STATE_H_ | 224 #endif // COMPONENTS_FLAGS_UI_FLAGS_STATE_H_ |
| OLD | NEW |