flags: refactor FlagsState interface

This change:
1) has FlagsState take (and internally store) its set of FeatureEntry as
   a base::span<FeatureEntry> rather than a (FeatureEntry*, size_t) pair,
   and rewrites all iterations over the set of FeatureEntry to use
   new-style for loops.
2) introduces FlagsState::Delegate for users of the component to
   customize the behavior of FlagsState, and replaces existing uses of
   the exclude predicate with uses of this delegate.

This is a preparatory refactor for the work to show flag expiration
milestones within the flags UI. As that work proceeds
FlagsState::Delegate will gain new methods.

Bug: 1020637
Change-Id: Ia61abb4ba7fe42df874a9089531be69f5b076fc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1912419
Reviewed-by: Rohit Rao <[email protected]>
Reviewed-by: Alexei Svitkine <[email protected]>
Commit-Queue: Elly Fong-Jones <[email protected]>
Cr-Commit-Position: refs/heads/master@{#714622}
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index 62e8141..8440596 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -4774,18 +4774,12 @@
     // AboutFlagsHistogramTest unit test to verify this process).
 };
 
-class FlagsStateSingleton {
+class FlagsStateSingleton : public flags_ui::FlagsState::Delegate {
  public:
   FlagsStateSingleton()
-      : flags_state_(std::make_unique<flags_ui::FlagsState>(
-            kFeatureEntries,
-            base::size(kFeatureEntries),
-            base::Bind(&FlagsStateSingleton::IsFlagExpired))) {}
-  ~FlagsStateSingleton() {}
-
-  static bool IsFlagExpired(const flags_ui::FeatureEntry& entry) {
-    return flags::IsFlagExpired(entry.internal_name);
-  }
+      : flags_state_(
+            std::make_unique<flags_ui::FlagsState>(kFeatureEntries, this)) {}
+  ~FlagsStateSingleton() override = default;
 
   static FlagsStateSingleton* GetInstance() {
     return base::Singleton<FlagsStateSingleton>::get();
@@ -4796,12 +4790,15 @@
   }
 
   void RebuildState(const std::vector<flags_ui::FeatureEntry>& entries) {
-    flags_state_ = std::make_unique<flags_ui::FlagsState>(
-        entries.data(), entries.size(),
-        base::Bind(&FlagsStateSingleton::IsFlagExpired));
+    flags_state_ = std::make_unique<flags_ui::FlagsState>(entries, this);
   }
 
  private:
+  // flags_ui::FlagsState::Delegate:
+  bool ShouldExcludeFlag(const FeatureEntry& entry) override {
+    return flags::IsFlagExpired(entry.internal_name);
+  }
+
   std::unique_ptr<flags_ui::FlagsState> flags_state_;
 
   DISALLOW_COPY_AND_ASSIGN(FlagsStateSingleton);