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

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

Issue 3777005: Rename about:labs to about:flags, part 3/3 (Closed)
Patch Set: comments Created 10 years, 2 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
« no previous file with comments | « chrome/browser/about_flags.h ('k') | chrome/browser/browser_about_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/labs.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>
11 11
12 #include "app/l10n_util.h" 12 #include "app/l10n_util.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
19 19
20 namespace about_labs { 20 namespace about_flags {
21 21
22 enum { kOsMac = 1 << 0, kOsWin = 1 << 1, kOsLinux = 1 << 2 }; 22 enum { kOsMac = 1 << 0, kOsWin = 1 << 1, kOsLinux = 1 << 2 };
23 23
24 unsigned kOsAll = kOsMac | kOsWin | kOsLinux; 24 unsigned kOsAll = kOsMac | kOsWin | kOsLinux;
25 25
26 struct Experiment { 26 struct Experiment {
27 // The internal name of the experiment. This is never shown to the user. 27 // The internal name of the experiment. This is never shown to the user.
28 // It _is_ however stored in the prefs file, so you shouldn't change the 28 // It _is_ however stored in the prefs file, so you shouldn't change the
29 // name of existing labs. 29 // name of existing flags.
30 const char* internal_name; 30 const char* internal_name;
31 31
32 // String id of the message containing the experiment's name. 32 // String id of the message containing the experiment's name.
33 int visible_name_id; 33 int visible_name_id;
34 34
35 // String id of the message containing the experiment's description. 35 // String id of the message containing the experiment's description.
36 int visible_description_id; 36 int visible_description_id;
37 37
38 // The platforms the experiment is available on 38 // The platforms the experiment is available on
39 // Needs to be more than a compile-time #ifdef because of profile sync. 39 // Needs to be more than a compile-time #ifdef because of profile sync.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 #endif 124 #endif
125 switches::kEnableCloudPrintProxy 125 switches::kEnableCloudPrintProxy
126 }, 126 },
127 { 127 {
128 "match-preview", // Do not change; see above. 128 "match-preview", // Do not change; see above.
129 IDS_FLAGS_INSTANT_NAME, 129 IDS_FLAGS_INSTANT_NAME,
130 IDS_FLAGS_INSTANT_DESCRIPTION, 130 IDS_FLAGS_INSTANT_DESCRIPTION,
131 kOsMac, 131 kOsMac,
132 switches::kEnableMatchPreview 132 switches::kEnableMatchPreview
133 }, 133 },
134 // FIXME(scheib): Add Labs entry for accelerated Compositing, 134 // FIXME(scheib): Add Flags entry for accelerated Compositing,
135 // or pull it and the strings in generated_resources.grd by Dec 2010 135 // or pull it and the strings in generated_resources.grd by Dec 2010
136 //{ 136 //{
137 // "gpu-compositing", // Do not change; see above 137 // "gpu-compositing", // Do not change; see above
138 // IDS_FLAGS_ACCELERATED_COMPOSITING_NAME, 138 // IDS_FLAGS_ACCELERATED_COMPOSITING_NAME,
139 // IDS_FLAGS_ACCELERATED_COMPOSITING_DESCRIPTION, 139 // IDS_FLAGS_ACCELERATED_COMPOSITING_DESCRIPTION,
140 // kOsAll, 140 // kOsAll,
141 // switches::kDisableAcceleratedCompositing 141 // switches::kDisableAcceleratedCompositing
142 //}, 142 //},
143 { 143 {
144 "gpu-canvas-2d", // Do not change; see above 144 "gpu-canvas-2d", // Do not change; see above
145 IDS_FLAGS_ACCELERATED_CANVAS_2D_NAME, 145 IDS_FLAGS_ACCELERATED_CANVAS_2D_NAME,
146 IDS_FLAGS_ACCELERATED_CANVAS_2D_DESCRIPTION, 146 IDS_FLAGS_ACCELERATED_CANVAS_2D_DESCRIPTION,
147 kOsWin | kOsLinux, 147 kOsWin | kOsLinux,
148 switches::kEnableAccelerated2dCanvas 148 switches::kEnableAccelerated2dCanvas
149 }, 149 },
150 // FIXME(scheib): Add Labs entry for WebGL, 150 // FIXME(scheib): Add Flags entry for WebGL,
151 // or pull it and the strings in generated_resources.grd by Dec 2010 151 // or pull it and the strings in generated_resources.grd by Dec 2010
152 //{ 152 //{
153 // "webgl", // Do not change; see above 153 // "webgl", // Do not change; see above
154 // IDS_FLAGS_WEBGL_NAME, 154 // IDS_FLAGS_WEBGL_NAME,
155 // IDS_FLAGS_WEBGL_DESCRIPTION, 155 // IDS_FLAGS_WEBGL_DESCRIPTION,
156 // kOsAll, 156 // kOsAll,
157 // switches::kDisableExperimentalWebGL 157 // switches::kDisableExperimentalWebGL
158 //} 158 //}
159 { 159 {
160 "print-preview", // Do not change; see above 160 "print-preview", // Do not change; see above
161 IDS_FLAGS_PRINT_PREVIEW_NAME, 161 IDS_FLAGS_PRINT_PREVIEW_NAME,
162 IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION, 162 IDS_FLAGS_PRINT_PREVIEW_DESCRIPTION,
163 kOsAll, 163 kOsAll,
164 switches::kEnablePrintPreview 164 switches::kEnablePrintPreview
165 } 165 }
166 }; 166 };
167 167
168 // Extracts the list of enabled lab experiments from preferences and stores them 168 // Extracts the list of enabled lab experiments from preferences and stores them
169 // in a set. 169 // in a set.
170 void GetEnabledLabs(const PrefService* prefs, std::set<std::string>* result) { 170 void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) {
171 const ListValue* enabled_experiments = prefs->GetList( 171 const ListValue* enabled_experiments = prefs->GetList(
172 prefs::kEnabledLabsExperiments); 172 prefs::kEnabledLabsExperiments);
173 if (!enabled_experiments) 173 if (!enabled_experiments)
174 return; 174 return;
175 175
176 for (ListValue::const_iterator it = enabled_experiments->begin(); 176 for (ListValue::const_iterator it = enabled_experiments->begin();
177 it != enabled_experiments->end(); 177 it != enabled_experiments->end();
178 ++it) { 178 ++it) {
179 std::string experiment_name; 179 std::string experiment_name;
180 if (!(*it)->GetAsString(&experiment_name)) { 180 if (!(*it)->GetAsString(&experiment_name)) {
181 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments; 181 LOG(WARNING) << "Invalid entry in " << prefs::kEnabledLabsExperiments;
182 continue; 182 continue;
183 } 183 }
184 result->insert(experiment_name); 184 result->insert(experiment_name);
185 } 185 }
186 } 186 }
187 187
188 // Takes a set of enabled lab experiments 188 // Takes a set of enabled lab experiments
189 void SetEnabledLabs( 189 void SetEnabledFlags(
190 PrefService* prefs, const std::set<std::string>& enabled_experiments) { 190 PrefService* prefs, const std::set<std::string>& enabled_experiments) {
191 ListValue* experiments_list = prefs->GetMutableList( 191 ListValue* experiments_list = prefs->GetMutableList(
192 prefs::kEnabledLabsExperiments); 192 prefs::kEnabledLabsExperiments);
193 if (!experiments_list) 193 if (!experiments_list)
194 return; 194 return;
195 195
196 experiments_list->Clear(); 196 experiments_list->Clear();
197 for (std::set<std::string>::const_iterator it = enabled_experiments.begin(); 197 for (std::set<std::string>::const_iterator it = enabled_experiments.begin();
198 it != enabled_experiments.end(); 198 it != enabled_experiments.end();
199 ++it) { 199 ++it) {
200 experiments_list->Append(new StringValue(*it)); 200 experiments_list->Append(new StringValue(*it));
201 } 201 }
202 } 202 }
203 203
204 // Removes all experiments from prefs::kEnabledLabsExperiments that are 204 // Removes all experiments from prefs::kEnabledLabsExperiments that are
205 // unknown, to prevent this list to become very long as experiments are added 205 // unknown, to prevent this list to become very long as experiments are added
206 // and removed. 206 // and removed.
207 void SanitizeList(PrefService* prefs) { 207 void SanitizeList(PrefService* prefs) {
208 std::set<std::string> known_experiments; 208 std::set<std::string> known_experiments;
209 for (size_t i = 0; i < arraysize(kExperiments); ++i) 209 for (size_t i = 0; i < arraysize(kExperiments); ++i)
210 known_experiments.insert(kExperiments[i].internal_name); 210 known_experiments.insert(kExperiments[i].internal_name);
211 211
212 std::set<std::string> enabled_experiments; 212 std::set<std::string> enabled_experiments;
213 GetEnabledLabs(prefs, &enabled_experiments); 213 GetEnabledFlags(prefs, &enabled_experiments);
214 214
215 std::set<std::string> new_enabled_experiments; 215 std::set<std::string> new_enabled_experiments;
216 std::set_intersection( 216 std::set_intersection(
217 known_experiments.begin(), known_experiments.end(), 217 known_experiments.begin(), known_experiments.end(),
218 enabled_experiments.begin(), enabled_experiments.end(), 218 enabled_experiments.begin(), enabled_experiments.end(),
219 std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); 219 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
220 220
221 SetEnabledLabs(prefs, new_enabled_experiments); 221 SetEnabledFlags(prefs, new_enabled_experiments);
222 } 222 }
223 223
224 void GetSanitizedEnabledLabs( 224 void GetSanitizedEnabledFlags(
225 PrefService* prefs, std::set<std::string>* result) { 225 PrefService* prefs, std::set<std::string>* result) {
226 SanitizeList(prefs); 226 SanitizeList(prefs);
227 GetEnabledLabs(prefs, result); 227 GetEnabledFlags(prefs, result);
228 } 228 }
229 229
230 int GetCurrentPlatform() { 230 int GetCurrentPlatform() {
231 #if defined(OS_MACOSX) 231 #if defined(OS_MACOSX)
232 return kOsMac; 232 return kOsMac;
233 #elif defined(OS_WIN) 233 #elif defined(OS_WIN)
234 return kOsWin; 234 return kOsWin;
235 #elif defined(OS_LINUX) 235 #elif defined(OS_LINUX)
236 return kOsLinux; 236 return kOsLinux;
237 #else 237 #else
238 #error Unknown platform 238 #error Unknown platform
239 #endif 239 #endif
240 } 240 }
241 241
242 bool IsEnabled() { 242 bool IsEnabled() {
243 #if defined(OS_CHROMEOS) 243 #if defined(OS_CHROMEOS)
244 // ChromeOS uses a different mechanism for about:labs; integrated with their 244 // TODO(thakis): Port about:flags to chromeos -- http://crbug.com/57634
245 // dom ui options.
246 // TODO(thakis): Port about:labs to chromeos -- http://crbug.com/57634
247 return false; 245 return false;
248 #else 246 #else
249 return true; 247 return true;
250 #endif 248 #endif
251 } 249 }
252 250
253 void ConvertLabsToSwitches(PrefService* prefs, CommandLine* command_line) { 251 void ConvertFlagsToSwitches(PrefService* prefs, CommandLine* command_line) {
254 if (!IsEnabled()) 252 if (!IsEnabled())
255 return; 253 return;
256 254
257 if (command_line->HasSwitch(switches::kNoLabs)) 255 if (command_line->HasSwitch(switches::kNoExperiments))
258 return; 256 return;
259 257
260 std::set<std::string> enabled_experiments; 258 std::set<std::string> enabled_experiments;
261 GetSanitizedEnabledLabs(prefs, &enabled_experiments); 259 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
262 260
263 std::map<std::string, const Experiment*> experiments; 261 std::map<std::string, const Experiment*> experiments;
264 for (size_t i = 0; i < arraysize(kExperiments); ++i) 262 for (size_t i = 0; i < arraysize(kExperiments); ++i)
265 experiments[kExperiments[i].internal_name] = &kExperiments[i]; 263 experiments[kExperiments[i].internal_name] = &kExperiments[i];
266 264
267 for (std::set<std::string>::iterator it = enabled_experiments.begin(); 265 for (std::set<std::string>::iterator it = enabled_experiments.begin();
268 it != enabled_experiments.end(); 266 it != enabled_experiments.end();
269 ++it) { 267 ++it) {
270 const std::string& experiment_name = *it; 268 const std::string& experiment_name = *it;
271 std::map<std::string, const Experiment*>::iterator experiment = 269 std::map<std::string, const Experiment*>::iterator experiment =
272 experiments.find(experiment_name); 270 experiments.find(experiment_name);
273 DCHECK(experiment != experiments.end()); 271 DCHECK(experiment != experiments.end());
274 if (experiment == experiments.end()) 272 if (experiment == experiments.end())
275 continue; 273 continue;
276 274
277 command_line->AppendSwitch(experiment->second->command_line); 275 command_line->AppendSwitch(experiment->second->command_line);
278 } 276 }
279 } 277 }
280 278
281 ListValue* GetLabsExperimentsData(PrefService* prefs) { 279 ListValue* GetFlagsExperimentsData(PrefService* prefs) {
282 std::set<std::string> enabled_experiments; 280 std::set<std::string> enabled_experiments;
283 GetSanitizedEnabledLabs(prefs, &enabled_experiments); 281 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
284 282
285 int current_platform = GetCurrentPlatform(); 283 int current_platform = GetCurrentPlatform();
286 284
287 ListValue* experiments_data = new ListValue(); 285 ListValue* experiments_data = new ListValue();
288 for (size_t i = 0; i < arraysize(kExperiments); ++i) { 286 for (size_t i = 0; i < arraysize(kExperiments); ++i) {
289 const Experiment& experiment = kExperiments[i]; 287 const Experiment& experiment = kExperiments[i];
290 if (!(experiment.supported_platforms & current_platform)) 288 if (!(experiment.supported_platforms & current_platform))
291 continue; 289 continue;
292 290
293 DictionaryValue* data = new DictionaryValue(); 291 DictionaryValue* data = new DictionaryValue();
(...skipping 15 matching lines...) Expand all
309 307
310 bool IsRestartNeededToCommitChanges() { 308 bool IsRestartNeededToCommitChanges() {
311 return needs_restart_; 309 return needs_restart_;
312 } 310 }
313 311
314 void SetExperimentEnabled( 312 void SetExperimentEnabled(
315 PrefService* prefs, const std::string& internal_name, bool enable) { 313 PrefService* prefs, const std::string& internal_name, bool enable) {
316 needs_restart_ = true; 314 needs_restart_ = true;
317 315
318 std::set<std::string> enabled_experiments; 316 std::set<std::string> enabled_experiments;
319 GetSanitizedEnabledLabs(prefs, &enabled_experiments); 317 GetSanitizedEnabledFlags(prefs, &enabled_experiments);
320 318
321 if (enable) 319 if (enable)
322 enabled_experiments.insert(internal_name); 320 enabled_experiments.insert(internal_name);
323 else 321 else
324 enabled_experiments.erase(internal_name); 322 enabled_experiments.erase(internal_name);
325 323
326 SetEnabledLabs(prefs, enabled_experiments); 324 SetEnabledFlags(prefs, enabled_experiments);
327 } 325 }
328 326
329 } // namespace Labs 327 } // namespace about_flags
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.h ('k') | chrome/browser/browser_about_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698