Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

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

Issue 19520007: Migrate users from "WebKit" flag to "Web Platform". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: less ugly. Created 7 years, 5 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
« no previous file with comments | « chrome/browser/about_flags.h ('k') | chrome/browser/about_flags_unittest.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) 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // To add a new experiment add to the end of kExperiments. There are two 302 // To add a new experiment add to the end of kExperiments. There are two
303 // distinct types of experiments: 303 // distinct types of experiments:
304 // . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE 304 // . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE
305 // macro for this type supplying the command line to the macro. 305 // macro for this type supplying the command line to the macro.
306 // . MULTI_VALUE: a list of choices, the first of which should correspond to a 306 // . MULTI_VALUE: a list of choices, the first of which should correspond to a
307 // deactivated state for this lab (i.e. no command line option). To specify 307 // deactivated state for this lab (i.e. no command line option). To specify
308 // this type of experiment use the macro MULTI_VALUE_TYPE supplying it the 308 // this type of experiment use the macro MULTI_VALUE_TYPE supplying it the
309 // array of choices. 309 // array of choices.
310 // See the documentation of Experiment for details on the fields. 310 // See the documentation of Experiment for details on the fields.
311 // 311 //
312
312 // When adding a new choice, add it to the end of the list. 313 // When adding a new choice, add it to the end of the list.
313 const Experiment kExperiments[] = { 314 const Experiment kExperiments[] = {
314 { 315 {
315 "expose-for-tabs", // FLAGS:RECORD_UMA 316 "expose-for-tabs", // FLAGS:RECORD_UMA
316 IDS_FLAGS_TABPOSE_NAME, 317 IDS_FLAGS_TABPOSE_NAME,
317 IDS_FLAGS_TABPOSE_DESCRIPTION, 318 IDS_FLAGS_TABPOSE_DESCRIPTION,
318 kOsMac, 319 kOsMac,
319 #if defined(OS_MACOSX) 320 #if defined(OS_MACOSX)
320 // The switch exists only on OS X. 321 // The switch exists only on OS X.
321 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs) 322 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs)
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 IDS_FLAGS_ENABLE_DEVICE_MOTION_NAME, 1630 IDS_FLAGS_ENABLE_DEVICE_MOTION_NAME,
1630 IDS_FLAGS_ENABLE_DEVICE_MOTION_DESCRIPTION, 1631 IDS_FLAGS_ENABLE_DEVICE_MOTION_DESCRIPTION,
1631 kOsAndroid, 1632 kOsAndroid,
1632 SINGLE_VALUE_TYPE(switches::kEnableDeviceMotion) 1633 SINGLE_VALUE_TYPE(switches::kEnableDeviceMotion)
1633 }, 1634 },
1634 }; 1635 };
1635 1636
1636 const Experiment* experiments = kExperiments; 1637 const Experiment* experiments = kExperiments;
1637 size_t num_experiments = arraysize(kExperiments); 1638 size_t num_experiments = arraysize(kExperiments);
1638 1639
1640 const Migration kMigrations[] = {
1641 // TODO(mkwst): Remove this once some reasonable amount of time has passed.
1642 {"enable-experimental-webkit-features",
Nico 2013/07/20 18:35:23 If you wanted to not have users to reset this, cou
1643 "enable-experimental-web-platform-features"}
1644 };
1645
1646 const Migration* migrations = kMigrations;
1647 size_t num_migrations = arraysize(kMigrations);
1648
1639 // Stores and encapsulates the little state that about:flags has. 1649 // Stores and encapsulates the little state that about:flags has.
1640 class FlagsState { 1650 class FlagsState {
1641 public: 1651 public:
1642 FlagsState() : needs_restart_(false) {} 1652 FlagsState() : needs_restart_(false) {}
1643 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, 1653 void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
1644 CommandLine* command_line); 1654 CommandLine* command_line);
1645 bool IsRestartNeededToCommitChanges(); 1655 bool IsRestartNeededToCommitChanges();
1646 void SetExperimentEnabled( 1656 void SetExperimentEnabled(
1647 FlagsStorage* flags_storage, 1657 FlagsStorage* flags_storage,
1648 const std::string& internal_name, 1658 const std::string& internal_name,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 DCHECK(e.command_line_value); 1707 DCHECK(e.command_line_value);
1698 DCHECK(e.disable_command_line_switch); 1708 DCHECK(e.disable_command_line_switch);
1699 DCHECK(e.disable_command_line_value); 1709 DCHECK(e.disable_command_line_value);
1700 break; 1710 break;
1701 default: 1711 default:
1702 NOTREACHED(); 1712 NOTREACHED();
1703 } 1713 }
1704 return true; 1714 return true;
1705 } 1715 }
1706 1716
1717 // Given the set of currently active experiments, migrate deprecated experiments
1718 // to their shiny new counterparts.
1719 void MigrateExperiments(std::set<std::string>* experimentList) {
1720 for (size_t i = 0; i < num_migrations; ++i) {
1721 if (experimentList->count(migrations[i].from)) {
1722 experimentList->erase(experimentList->find(migrations[i].from));
jochen (gone - plz use gerrit) 2013/07/19 13:50:41 nit. if you're using find() anyway, you can just s
1723 experimentList->insert(migrations[i].to);
1724 }
1725 }
1726 }
1727
1707 // Removes all experiments from prefs::kEnabledLabsExperiments that are 1728 // Removes all experiments from prefs::kEnabledLabsExperiments that are
1708 // unknown, to prevent this list to become very long as experiments are added 1729 // unknown, to prevent this list to become very long as experiments are added
1709 // and removed. 1730 // and removed.
1710 void SanitizeList(FlagsStorage* flags_storage) { 1731 void SanitizeList(FlagsStorage* flags_storage) {
1711 std::set<std::string> known_experiments; 1732 std::set<std::string> known_experiments;
1712 for (size_t i = 0; i < num_experiments; ++i) { 1733 for (size_t i = 0; i < num_experiments; ++i) {
1713 DCHECK(ValidateExperiment(experiments[i])); 1734 DCHECK(ValidateExperiment(experiments[i]));
1714 AddInternalName(experiments[i], &known_experiments); 1735 AddInternalName(experiments[i], &known_experiments);
1715 } 1736 }
1716 1737
1717 std::set<std::string> enabled_experiments = flags_storage->GetFlags(); 1738 // Store the original list of Experiments, then copy it for processing.
1739 std::set<std::string> unsanitized_experiments = flags_storage->GetFlags();
1740 std::set<std::string> enabled_experiments = unsanitized_experiments;
1741
1742 MigrateExperiments(&enabled_experiments);
1718 1743
1719 std::set<std::string> new_enabled_experiments; 1744 std::set<std::string> new_enabled_experiments;
1720 std::set_intersection( 1745 std::set_intersection(
1721 known_experiments.begin(), known_experiments.end(), 1746 known_experiments.begin(), known_experiments.end(),
1722 enabled_experiments.begin(), enabled_experiments.end(), 1747 enabled_experiments.begin(), enabled_experiments.end(),
1723 std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); 1748 std::inserter(new_enabled_experiments, new_enabled_experiments.begin()));
1724 1749
1725 if (new_enabled_experiments != enabled_experiments) 1750 if (new_enabled_experiments != unsanitized_experiments)
1726 flags_storage->SetFlags(new_enabled_experiments); 1751 flags_storage->SetFlags(new_enabled_experiments);
1727 } 1752 }
1728 1753
1729 void GetSanitizedEnabledFlags( 1754 void GetSanitizedEnabledFlags(
1730 FlagsStorage* flags_storage, std::set<std::string>* result) { 1755 FlagsStorage* flags_storage, std::set<std::string>* result) {
1731 SanitizeList(flags_storage); 1756 SanitizeList(flags_storage);
1732 *result = flags_storage->GetFlags(); 1757 *result = flags_storage->GetFlags();
1733 } 1758 }
1734 1759
1735 // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't 1760 // Variant of GetSanitizedEnabledFlags that also removes any flags that aren't
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 void SetExperiments(const Experiment* e, size_t count) { 2132 void SetExperiments(const Experiment* e, size_t count) {
2108 if (!e) { 2133 if (!e) {
2109 experiments = kExperiments; 2134 experiments = kExperiments;
2110 num_experiments = arraysize(kExperiments); 2135 num_experiments = arraysize(kExperiments);
2111 } else { 2136 } else {
2112 experiments = e; 2137 experiments = e;
2113 num_experiments = count; 2138 num_experiments = count;
2114 } 2139 }
2115 } 2140 }
2116 2141
2142 void SetMigrations(const Migration* e, size_t count) {
2143 if (!e) {
2144 migrations = kMigrations;
2145 num_migrations = arraysize(kMigrations);
2146 } else {
2147 migrations = e;
2148 num_migrations = count;
2149 }
2150 }
2151
2117 const Experiment* GetExperiments(size_t* count) { 2152 const Experiment* GetExperiments(size_t* count) {
2118 *count = num_experiments; 2153 *count = num_experiments;
2119 return experiments; 2154 return experiments;
2120 } 2155 }
2121 2156
2122 } // namespace testing 2157 } // namespace testing
2123 2158
2124 } // namespace about_flags 2159 } // namespace about_flags
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.h ('k') | chrome/browser/about_flags_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698