OLD | NEW |
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/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> |
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/singleton.h" | 14 #include "base/singleton.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
20 | 20 |
21 namespace about_flags { | 21 namespace about_flags { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS; | 25 const unsigned kOsAll = kOsMac | kOsWin | kOsLinux | kOsCrOS; |
26 | 26 |
| 27 // Names for former Chrome OS Labs experiments, shared with prefs migration |
| 28 // code. |
| 29 const char kMediaPlayerExperimentName[] = "media-player"; |
| 30 const char kAdvancedFileSystemExperimentName[] = "advanced-file-system"; |
| 31 const char kVerticalTabsExperimentName[] = "vertical-tabs"; |
| 32 |
27 const Experiment kExperiments[] = { | 33 const Experiment kExperiments[] = { |
28 { | 34 { |
29 "expose-for-tabs", // Do not change; see above. | 35 "expose-for-tabs", // Do not change; see above. |
30 IDS_FLAGS_TABPOSE_NAME, | 36 IDS_FLAGS_TABPOSE_NAME, |
31 IDS_FLAGS_TABPOSE_DESCRIPTION, | 37 IDS_FLAGS_TABPOSE_DESCRIPTION, |
32 kOsMac, | 38 kOsMac, |
33 #if defined(OS_MACOSX) | 39 #if defined(OS_MACOSX) |
34 // The switch exists only on OS X. | 40 // The switch exists only on OS X. |
35 switches::kEnableExposeForTabs | 41 switches::kEnableExposeForTabs |
36 #else | 42 #else |
37 "" | 43 "" |
38 #endif | 44 #endif |
39 }, | 45 }, |
40 { | 46 { |
41 "vertical-tabs", // Do not change; see above. | 47 kMediaPlayerExperimentName, |
| 48 IDS_FLAGS_MEDIA_PLAYER_NAME, |
| 49 IDS_FLAGS_MEDIA_PLAYER_DESCRIPTION, |
| 50 kOsCrOS, |
| 51 #if defined(OS_CHROMEOS) |
| 52 // The switch exists only on Chrome OS. |
| 53 switches::kEnableMediaPlayer |
| 54 #else |
| 55 "" |
| 56 #endif |
| 57 }, |
| 58 { |
| 59 kAdvancedFileSystemExperimentName, |
| 60 IDS_FLAGS_ADVANCED_FS_NAME, |
| 61 IDS_FLAGS_ADVANCED_FS_DESCRIPTION, |
| 62 kOsCrOS, |
| 63 #if defined(OS_CHROMEOS) |
| 64 // The switch exists only on Chrome OS. |
| 65 switches::kEnableAdvancedFileSystem |
| 66 #else |
| 67 "" |
| 68 #endif |
| 69 }, |
| 70 { |
| 71 kVerticalTabsExperimentName, |
42 IDS_FLAGS_SIDE_TABS_NAME, | 72 IDS_FLAGS_SIDE_TABS_NAME, |
43 IDS_FLAGS_SIDE_TABS_DESCRIPTION, | 73 IDS_FLAGS_SIDE_TABS_DESCRIPTION, |
44 // TODO(thakis): Move sidetabs to about:flags on ChromeOS | 74 kOsWin | kOsCrOS, |
45 // http://crbug.com/57634 | |
46 kOsWin, | |
47 switches::kEnableVerticalTabs | 75 switches::kEnableVerticalTabs |
48 }, | 76 }, |
49 { | 77 { |
50 "tabbed-options", // Do not change; see above. | 78 "tabbed-options", // Do not change; see above. |
51 IDS_FLAGS_TABBED_OPTIONS_NAME, | 79 IDS_FLAGS_TABBED_OPTIONS_NAME, |
52 IDS_FLAGS_TABBED_OPTIONS_DESCRIPTION, | 80 IDS_FLAGS_TABBED_OPTIONS_DESCRIPTION, |
53 kOsWin | kOsLinux | kOsMac, // Enabled by default on CrOS. | 81 kOsWin | kOsLinux | kOsMac, // Enabled by default on CrOS. |
54 switches::kEnableTabbedOptions | 82 switches::kEnableTabbedOptions |
55 }, | 83 }, |
56 { | 84 { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 return Singleton<FlagsState>::get(); | 249 return Singleton<FlagsState>::get(); |
222 } | 250 } |
223 | 251 |
224 private: | 252 private: |
225 bool needs_restart_; | 253 bool needs_restart_; |
226 std::set<std::string> flags_switches_; | 254 std::set<std::string> flags_switches_; |
227 | 255 |
228 DISALLOW_COPY_AND_ASSIGN(FlagsState); | 256 DISALLOW_COPY_AND_ASSIGN(FlagsState); |
229 }; | 257 }; |
230 | 258 |
| 259 #if defined(OS_CHROMEOS) |
| 260 // Migrates Chrome OS Labs settings to experiments adding flags to enabled |
| 261 // experiment list if the corresponding pref is on. |
| 262 void MigrateChromeOSLabsPrefs(PrefService* prefs, |
| 263 std::set<std::string>* result) { |
| 264 DCHECK(prefs); |
| 265 DCHECK(result); |
| 266 if (prefs->GetBoolean(prefs::kLabsMediaplayerEnabled)) |
| 267 result->insert(kMediaPlayerExperimentName); |
| 268 if (prefs->GetBoolean(prefs::kLabsAdvancedFilesystemEnabled)) |
| 269 result->insert(kAdvancedFileSystemExperimentName); |
| 270 if (prefs->GetBoolean(prefs::kUseVerticalTabs)) |
| 271 result->insert(kVerticalTabsExperimentName); |
| 272 prefs->SetBoolean(prefs::kLabsMediaplayerEnabled, false); |
| 273 prefs->SetBoolean(prefs::kLabsAdvancedFilesystemEnabled, false); |
| 274 prefs->SetBoolean(prefs::kUseVerticalTabs, false); |
| 275 } |
| 276 #endif |
| 277 |
231 // Extracts the list of enabled lab experiments from preferences and stores them | 278 // Extracts the list of enabled lab experiments from preferences and stores them |
232 // in a set. | 279 // in a set. |
233 void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { | 280 void GetEnabledFlags(const PrefService* prefs, std::set<std::string>* result) { |
234 const ListValue* enabled_experiments = prefs->GetList( | 281 const ListValue* enabled_experiments = prefs->GetList( |
235 prefs::kEnabledLabsExperiments); | 282 prefs::kEnabledLabsExperiments); |
236 if (!enabled_experiments) | 283 if (!enabled_experiments) |
237 return; | 284 return; |
238 | 285 |
239 for (ListValue::const_iterator it = enabled_experiments->begin(); | 286 for (ListValue::const_iterator it = enabled_experiments->begin(); |
240 it != enabled_experiments->end(); | 287 it != enabled_experiments->end(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // FlagsState implementation. | 427 // FlagsState implementation. |
381 | 428 |
382 namespace { | 429 namespace { |
383 | 430 |
384 void FlagsState::ConvertFlagsToSwitches( | 431 void FlagsState::ConvertFlagsToSwitches( |
385 PrefService* prefs, CommandLine* command_line) { | 432 PrefService* prefs, CommandLine* command_line) { |
386 if (command_line->HasSwitch(switches::kNoExperiments)) | 433 if (command_line->HasSwitch(switches::kNoExperiments)) |
387 return; | 434 return; |
388 | 435 |
389 std::set<std::string> enabled_experiments; | 436 std::set<std::string> enabled_experiments; |
| 437 |
| 438 #if defined(OS_CHROMEOS) |
| 439 // Some experiments were implemented via prefs on Chrome OS and we want to |
| 440 // seamlessly migrate these prefs to about:flags for updated users. |
| 441 MigrateChromeOSLabsPrefs(prefs, &enabled_experiments); |
| 442 #endif |
| 443 |
390 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments); | 444 GetSanitizedEnabledFlagsForCurrentPlatform(prefs, &enabled_experiments); |
391 | 445 |
392 std::map<std::string, const Experiment*> experiment_map; | 446 std::map<std::string, const Experiment*> experiment_map; |
393 for (size_t i = 0; i < num_experiments; ++i) | 447 for (size_t i = 0; i < num_experiments; ++i) |
394 experiment_map[experiments[i].internal_name] = &experiments[i]; | 448 experiment_map[experiments[i].internal_name] = &experiments[i]; |
395 | 449 |
396 command_line->AppendSwitch(switches::kFlagSwitchesBegin); | 450 command_line->AppendSwitch(switches::kFlagSwitchesBegin); |
397 flags_switches_.insert(switches::kFlagSwitchesBegin); | 451 flags_switches_.insert(switches::kFlagSwitchesBegin); |
398 for (std::set<std::string>::iterator it = enabled_experiments.begin(); | 452 for (std::set<std::string>::iterator it = enabled_experiments.begin(); |
399 it != enabled_experiments.end(); | 453 it != enabled_experiments.end(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 num_experiments = arraysize(kExperiments); | 512 num_experiments = arraysize(kExperiments); |
459 } else { | 513 } else { |
460 experiments = e; | 514 experiments = e; |
461 num_experiments = count; | 515 num_experiments = count; |
462 } | 516 } |
463 } | 517 } |
464 | 518 |
465 } // namespace testing | 519 } // namespace testing |
466 | 520 |
467 } // namespace about_flags | 521 } // namespace about_flags |
OLD | NEW |