diff options
author | mkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-20 18:14:40 +0000 |
---|---|---|
committer | mkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-20 18:14:40 +0000 |
commit | 64eaa91efcaf016f85acfe29f1f051732e82e8ef (patch) | |
tree | 9abfeef9bd76f83d2f605444d1a3729eb2f02317 | |
parent | 825826d81f97a5b971d7817daa8a8deb3788a400 (diff) | |
download | chromium_src-64eaa91efcaf016f85acfe29f1f051732e82e8ef.zip chromium_src-64eaa91efcaf016f85acfe29f1f051732e82e8ef.tar.gz chromium_src-64eaa91efcaf016f85acfe29f1f051732e82e8ef.tar.bz2 |
Migrate users from "WebKit" flag to "Web Platform".
We changed the name of the "Experimental WebKit Features" flag, and changed
the actual flag at the same time[1]. I decided at the time to simply throw away
the old flag; I've been reliably informed that developers aren't particularly
thrilled with that decision. "Why have my experimental features stopped
working?" they ask. "Didn't you read my G+ post?" isn't a particularly helpful
answer, especially since most people (unbelievably!) don't follow me on
The Internets™.
This patch hacks a migration system into about:flags, which I hope we never
ever have to use again, and can safely throw away after a release cycle or two.
[1]: https://codereview.chromium.org/14940009/
R=jochen@chromium.org,thakis@chromium.org
Review URL: https://chromiumcodereview.appspot.com/19520007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212794 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/about_flags.cc | 39 | ||||
-rw-r--r-- | chrome/browser/about_flags.h | 11 | ||||
-rw-r--r-- | chrome/browser/about_flags_unittest.cc | 22 |
3 files changed, 70 insertions, 2 deletions
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 6ca3032..e239a43 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -309,6 +309,7 @@ const Experiment::Choice kTabCaptureDownscaleQualityChoices[] = { // array of choices. // See the documentation of Experiment for details on the fields. // + // When adding a new choice, add it to the end of the list. const Experiment kExperiments[] = { { @@ -1636,6 +1637,15 @@ const Experiment kExperiments[] = { const Experiment* experiments = kExperiments; size_t num_experiments = arraysize(kExperiments); +const Migration kMigrations[] = { + // TODO(mkwst): Remove this once some reasonable amount of time has passed. + {"enable-experimental-webkit-features", + "enable-experimental-web-platform-features"} +}; + +const Migration* migrations = kMigrations; +size_t num_migrations = arraysize(kMigrations); + // Stores and encapsulates the little state that about:flags has. class FlagsState { public: @@ -1704,6 +1714,17 @@ bool ValidateExperiment(const Experiment& e) { return true; } +// Given the set of currently active experiments, migrate deprecated experiments +// to their shiny new counterparts. +void MigrateExperiments(std::set<std::string>* experimentList) { + for (size_t i = 0; i < num_migrations; ++i) { + if (experimentList->count(migrations[i].from)) { + experimentList->erase(experimentList->find(migrations[i].from)); + experimentList->insert(migrations[i].to); + } + } +} + // Removes all experiments from prefs::kEnabledLabsExperiments that are // unknown, to prevent this list to become very long as experiments are added // and removed. @@ -1714,7 +1735,11 @@ void SanitizeList(FlagsStorage* flags_storage) { AddInternalName(experiments[i], &known_experiments); } - std::set<std::string> enabled_experiments = flags_storage->GetFlags(); + // Store the original list of Experiments, then copy it for processing. + std::set<std::string> unsanitized_experiments = flags_storage->GetFlags(); + std::set<std::string> enabled_experiments = unsanitized_experiments; + + MigrateExperiments(&enabled_experiments); std::set<std::string> new_enabled_experiments; std::set_intersection( @@ -1722,7 +1747,7 @@ void SanitizeList(FlagsStorage* flags_storage) { enabled_experiments.begin(), enabled_experiments.end(), std::inserter(new_enabled_experiments, new_enabled_experiments.begin())); - if (new_enabled_experiments != enabled_experiments) + if (new_enabled_experiments != unsanitized_experiments) flags_storage->SetFlags(new_enabled_experiments); } @@ -2114,6 +2139,16 @@ void SetExperiments(const Experiment* e, size_t count) { } } +void SetMigrations(const Migration* e, size_t count) { + if (!e) { + migrations = kMigrations; + num_migrations = arraysize(kMigrations); + } else { + migrations = e; + num_migrations = count; + } +} + const Experiment* GetExperiments(size_t* count) { *count = num_experiments; return experiments; diff --git a/chrome/browser/about_flags.h b/chrome/browser/about_flags.h index 5d67e97..c7fdc53 100644 --- a/chrome/browser/about_flags.h +++ b/chrome/browser/about_flags.h @@ -105,6 +105,13 @@ struct Experiment { string16 DescriptionForChoice(int index) const; }; +// Migration is used internally by about_flags to move users from old, +// busted flags to the new hotness. This is exposed only for testing. +struct Migration { + const char* const from; + const char* const to; +}; + // Reads the Labs |prefs| (called "Labs" for historical reasons) and adds the // commandline flags belonging to the active experiments to |command_line|. void ConvertFlagsToSwitches(FlagsStorage* flags_storage, @@ -163,6 +170,10 @@ void ClearState(); // NOT take ownership of the supplied Experiments. void SetExperiments(const Experiment* e, size_t count); +// Sets the list of migrations. Pass in NULL to use the default set. This does +// NOT take ownership of the supplied Migrations. +void SetMigrations(const Migration* e, size_t count); + // Returns the current set of experiments. const Experiment* GetExperiments(size_t* count); diff --git a/chrome/browser/about_flags_unittest.cc b/chrome/browser/about_flags_unittest.cc index 34219c3..3d9fbd2 100644 --- a/chrome/browser/about_flags_unittest.cc +++ b/chrome/browser/about_flags_unittest.cc @@ -110,6 +110,13 @@ static Experiment kExperiments[] = { }, }; +static Migration kMigrations[] = { + { + kFlags1, + kFlags2 + } +}; + class AboutFlagsTest : public ::testing::Test { protected: AboutFlagsTest() : flags_storage_(&prefs_) { @@ -223,6 +230,21 @@ TEST_F(AboutFlagsTest, ConvertFlagsToSwitches) { EXPECT_TRUE(command_line.HasSwitch(kSwitch1)); } +TEST_F(AboutFlagsTest, ConvertFlagsToSwitchesMigration) { + testing::SetMigrations(kMigrations, arraysize(kMigrations)); + SetExperimentEnabled(&flags_storage_,kFlags1, true); + + CommandLine command_line(CommandLine::NO_PROGRAM); + + EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); + EXPECT_FALSE(command_line.HasSwitch(kSwitch2)); + + ConvertFlagsToSwitches(&flags_storage_, &command_line); + + EXPECT_FALSE(command_line.HasSwitch(kSwitch1)); + EXPECT_TRUE(command_line.HasSwitch(kSwitch2)); +} + TEST_F(AboutFlagsTest, CompareSwitchesToCurrentCommandLine) { SetExperimentEnabled(&flags_storage_, kFlags1, true); |