flags: treat expired flags as default state
Currently, when a flag expires, it is hidden from chrome://flags but still
stored inside the backend flags store, so that if the user un-expires flags
their settings are not lost. However, the code for applying flag values by
turning them into features/switches was not aware of flag expiration, so flags
that were persisted this way would continue to apply, despite the user having no
way to undo them.
This change:
1) Adds an exclusion predicate to FlagsState, to allow client classes of
FlagsState to prevent flags from having their values applied as features or
switches;
2) Adds an implementation of that predicate in the //chrome FlagsStateSingleton
that checks the flag expiration state;
3) Adds unit tests to cover the new behavior added in (1);
4) Adds a new AboutFlagsBrowserTest test to validate the end-to-end behavior
described in this commit message by:
a) Setting an expired flag to a non-default value
b) Restarting (simulated via separate PRE_ vs regular tests here)
c) Checking that the flag's switch isn't in the browser command line
[email protected]
Bug: 1009729
Change-Id: I7d0ee2e7660fa378b9ecec3b663cc794f7e776fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879431
Reviewed-by: Elly Fong-Jones <[email protected]>
Reviewed-by: Alexei Svitkine <[email protected]>
Commit-Queue: Elly Fong-Jones <[email protected]>
Cr-Commit-Position: refs/heads/master@{#709169}
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index d2407c1..c703f46 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -4725,9 +4725,14 @@
FlagsStateSingleton()
: flags_state_(std::make_unique<flags_ui::FlagsState>(
kFeatureEntries,
- base::size(kFeatureEntries))) {}
+ base::size(kFeatureEntries),
+ base::Bind(&FlagsStateSingleton::IsFlagExpired))) {}
~FlagsStateSingleton() {}
+ static bool IsFlagExpired(const flags_ui::FeatureEntry& entry) {
+ return flags::IsFlagExpired(entry.internal_name);
+ }
+
static FlagsStateSingleton* GetInstance() {
return base::Singleton<FlagsStateSingleton>::get();
}
@@ -4737,8 +4742,9 @@
}
void RebuildState(const std::vector<flags_ui::FeatureEntry>& entries) {
- flags_state_ =
- std::make_unique<flags_ui::FlagsState>(entries.data(), entries.size());
+ flags_state_ = std::make_unique<flags_ui::FlagsState>(
+ entries.data(), entries.size(),
+ base::Bind(&FlagsStateSingleton::IsFlagExpired));
}
private: