OLD | NEW |
---|---|
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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 // To add a new experiment add to the end of kExperiments. There are two | 301 // To add a new experiment add to the end of kExperiments. There are two |
302 // distinct types of experiments: | 302 // distinct types of experiments: |
303 // . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE | 303 // . SINGLE_VALUE: experiment is either on or off. Use the SINGLE_VALUE_TYPE |
304 // macro for this type supplying the command line to the macro. | 304 // macro for this type supplying the command line to the macro. |
305 // . MULTI_VALUE: a list of choices, the first of which should correspond to a | 305 // . MULTI_VALUE: a list of choices, the first of which should correspond to a |
306 // deactivated state for this lab (i.e. no command line option). To specify | 306 // deactivated state for this lab (i.e. no command line option). To specify |
307 // this type of experiment use the macro MULTI_VALUE_TYPE supplying it the | 307 // this type of experiment use the macro MULTI_VALUE_TYPE supplying it the |
308 // array of choices. | 308 // array of choices. |
309 // See the documentation of Experiment for details on the fields. | 309 // See the documentation of Experiment for details on the fields. |
310 // | 310 // |
311 | |
jochen (gone - plz use gerrit)
2013/07/18 14:51:57
why the empty line?
| |
311 // When adding a new choice, add it to the end of the list. | 312 // When adding a new choice, add it to the end of the list. |
312 const Experiment kExperiments[] = { | 313 const Experiment kExperiments[] = { |
313 { | 314 { |
314 "expose-for-tabs", // FLAGS:RECORD_UMA | 315 "expose-for-tabs", // FLAGS:RECORD_UMA |
315 IDS_FLAGS_TABPOSE_NAME, | 316 IDS_FLAGS_TABPOSE_NAME, |
316 IDS_FLAGS_TABPOSE_DESCRIPTION, | 317 IDS_FLAGS_TABPOSE_DESCRIPTION, |
317 kOsMac, | 318 kOsMac, |
318 #if defined(OS_MACOSX) | 319 #if defined(OS_MACOSX) |
319 // The switch exists only on OS X. | 320 // The switch exists only on OS X. |
320 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs) | 321 SINGLE_VALUE_TYPE(switches::kEnableExposeForTabs) |
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1617 #endif | 1618 #endif |
1618 { | 1619 { |
1619 "enable-device-motion", | 1620 "enable-device-motion", |
1620 IDS_FLAGS_ENABLE_DEVICE_MOTION_NAME, | 1621 IDS_FLAGS_ENABLE_DEVICE_MOTION_NAME, |
1621 IDS_FLAGS_ENABLE_DEVICE_MOTION_DESCRIPTION, | 1622 IDS_FLAGS_ENABLE_DEVICE_MOTION_DESCRIPTION, |
1622 kOsAndroid, | 1623 kOsAndroid, |
1623 SINGLE_VALUE_TYPE(switches::kEnableDeviceMotion) | 1624 SINGLE_VALUE_TYPE(switches::kEnableDeviceMotion) |
1624 }, | 1625 }, |
1625 }; | 1626 }; |
1626 | 1627 |
1628 const Experiment kDeprecatedExperiments[] = { | |
jochen (gone - plz use gerrit)
2013/07/18 14:51:57
can you add a comment describing how to add deprec
| |
1629 { | |
1630 "enable-experimental-webkit-features", | |
1631 0, | |
1632 0, | |
1633 kOsAll, | |
1634 SINGLE_VALUE_TYPE("enable-experimental-webkit-features") | |
1635 }, | |
1636 }; | |
1637 | |
1638 | |
1627 const Experiment* experiments = kExperiments; | 1639 const Experiment* experiments = kExperiments; |
1628 size_t num_experiments = arraysize(kExperiments); | 1640 size_t num_experiments = arraysize(kExperiments); |
1629 | 1641 |
1630 // Stores and encapsulates the little state that about:flags has. | 1642 // Stores and encapsulates the little state that about:flags has. |
1631 class FlagsState { | 1643 class FlagsState { |
1632 public: | 1644 public: |
1633 FlagsState() : needs_restart_(false) {} | 1645 FlagsState() : needs_restart_(false) {} |
1634 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, | 1646 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, |
1635 CommandLine* command_line); | 1647 CommandLine* command_line); |
1636 bool IsRestartNeededToCommitChanges(); | 1648 bool IsRestartNeededToCommitChanges(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1688 DCHECK(e.command_line_value); | 1700 DCHECK(e.command_line_value); |
1689 DCHECK(e.disable_command_line_switch); | 1701 DCHECK(e.disable_command_line_switch); |
1690 DCHECK(e.disable_command_line_value); | 1702 DCHECK(e.disable_command_line_value); |
1691 break; | 1703 break; |
1692 default: | 1704 default: |
1693 NOTREACHED(); | 1705 NOTREACHED(); |
1694 } | 1706 } |
1695 return true; | 1707 return true; |
1696 } | 1708 } |
1697 | 1709 |
1710 // Given the set of currently active experiments, migrate deprecated experiments | |
1711 // to their shiny new counterparts. | |
1712 void MigrateExperiments(std::set<std::string>* experiments) { | |
1713 struct { | |
1714 const char* const from; | |
1715 const char* const to; | |
1716 } migrations[] = { | |
1717 // TODO(mkwst): Remove this once some reasonable amount of time has passed. | |
1718 {"enable-experimental-webkit-features", | |
1719 "enable-experimental-web-platform-features"} | |
1720 }; | |
1721 | |
1722 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(migrations); ++i) { | |
1723 if (experiments->count(migrations[i].from)) | |
1724 experiments->insert(migrations[i].to); | |
1725 } | |
1726 } | |
1727 | |
1698 // Removes all experiments from prefs::kEnabledLabsExperiments that are | 1728 // Removes all experiments from prefs::kEnabledLabsExperiments that are |
1699 // 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 |
1700 // and removed. | 1730 // and removed. |
1701 void SanitizeList(FlagsStorage* flags_storage) { | 1731 void SanitizeList(FlagsStorage* flags_storage) { |
1702 std::set<std::string> known_experiments; | 1732 std::set<std::string> known_experiments; |
1703 for (size_t i = 0; i < num_experiments; ++i) { | 1733 for (size_t i = 0; i < num_experiments; ++i) { |
1704 DCHECK(ValidateExperiment(experiments[i])); | 1734 DCHECK(ValidateExperiment(experiments[i])); |
1735 printf("Known Experiments: %s\n", experiments[i].internal_name); | |
jochen (gone - plz use gerrit)
2013/07/18 14:51:57
?
| |
1705 AddInternalName(experiments[i], &known_experiments); | 1736 AddInternalName(experiments[i], &known_experiments); |
1706 } | 1737 } |
1707 | 1738 |
1708 std::set<std::string> enabled_experiments = flags_storage->GetFlags(); | 1739 std::set<std::string> enabled_experiments = flags_storage->GetFlags(); |
1740 MigrateExperiments(&enabled_experiments); | |
1709 | 1741 |
1710 std::set<std::string> new_enabled_experiments; | 1742 std::set<std::string> new_enabled_experiments; |
1711 std::set_intersection( | 1743 std::set_intersection( |
1712 known_experiments.begin(), known_experiments.end(), | 1744 known_experiments.begin(), known_experiments.end(), |
1713 enabled_experiments.begin(), enabled_experiments.end(), | 1745 enabled_experiments.begin(), enabled_experiments.end(), |
1714 std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); | 1746 std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); |
1715 | 1747 |
1748 if (enabled_experiments.count("enable-experimental-web-platform-features")) | |
jochen (gone - plz use gerrit)
2013/07/18 14:51:57
?
| |
1749 printf("OLD: WebPlatform is enabled!\n"); | |
1750 if (new_enabled_experiments.count("enable-experimental-web-platform-features") ) | |
1751 printf("New: WebPlatform is enabled!\n"); | |
1752 | |
1716 if (new_enabled_experiments != enabled_experiments) | 1753 if (new_enabled_experiments != enabled_experiments) |
1717 flags_storage->SetFlags(new_enabled_experiments); | 1754 flags_storage->SetFlags(new_enabled_experiments); |
1718 } | 1755 } |
1719 | 1756 |
1720 void GetSanitizedEnabledFlags( | 1757 void GetSanitizedEnabledFlags( |
1721 FlagsStorage* flags_storage, std::set<std::string>* result) { | 1758 FlagsStorage* flags_storage, std::set<std::string>* result) { |
1722 SanitizeList(flags_storage); | 1759 SanitizeList(flags_storage); |
1723 *result = flags_storage->GetFlags(); | 1760 *result = flags_storage->GetFlags(); |
1724 } | 1761 } |
1725 | 1762 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2027 std::set<std::string> enabled_experiments; | 2064 std::set<std::string> enabled_experiments; |
2028 GetSanitizedEnabledFlags(flags_storage, &enabled_experiments); | 2065 GetSanitizedEnabledFlags(flags_storage, &enabled_experiments); |
2029 | 2066 |
2030 const Experiment* e = NULL; | 2067 const Experiment* e = NULL; |
2031 for (size_t i = 0; i < num_experiments; ++i) { | 2068 for (size_t i = 0; i < num_experiments; ++i) { |
2032 if (experiments[i].internal_name == internal_name) { | 2069 if (experiments[i].internal_name == internal_name) { |
2033 e = experiments + i; | 2070 e = experiments + i; |
2034 break; | 2071 break; |
2035 } | 2072 } |
2036 } | 2073 } |
2074 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDeprecatedExperiments); ++i) { | |
jochen (gone - plz use gerrit)
2013/07/18 14:51:57
why is this needed?
| |
2075 if (kDeprecatedExperiments[i].internal_name == internal_name) { | |
2076 e = kDeprecatedExperiments + i; | |
2077 break; | |
2078 } | |
2079 } | |
2037 DCHECK(e); | 2080 DCHECK(e); |
2038 | 2081 |
2039 if (e->type == Experiment::SINGLE_VALUE) { | 2082 if (e->type == Experiment::SINGLE_VALUE) { |
2040 if (enable) | 2083 if (enable) |
2041 needs_restart_ |= enabled_experiments.insert(internal_name).second; | 2084 needs_restart_ |= enabled_experiments.insert(internal_name).second; |
2042 else | 2085 else |
2043 needs_restart_ |= (enabled_experiments.erase(internal_name) > 0); | 2086 needs_restart_ |= (enabled_experiments.erase(internal_name) > 0); |
2044 } else { | 2087 } else { |
2045 if (enable) { | 2088 if (enable) { |
2046 // Enable the first choice. | 2089 // Enable the first choice. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2106 } | 2149 } |
2107 | 2150 |
2108 const Experiment* GetExperiments(size_t* count) { | 2151 const Experiment* GetExperiments(size_t* count) { |
2109 *count = num_experiments; | 2152 *count = num_experiments; |
2110 return experiments; | 2153 return experiments; |
2111 } | 2154 } |
2112 | 2155 |
2113 } // namespace testing | 2156 } // namespace testing |
2114 | 2157 |
2115 } // namespace about_flags | 2158 } // namespace about_flags |
OLD | NEW |