1 // Copyright 2024 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_FEATURE_VISITOR_H_ 6 #define BASE_FEATURE_VISITOR_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/feature_list.h" 12 #include "build/chromeos_buildflags.h" 13 14 static_assert(BUILDFLAG(IS_CHROMEOS_ASH), "For ChromeOS ash-chrome only"); 15 16 namespace variations::cros_early_boot::evaluate_seed { 17 class EarlyBootFeatureVisitor; 18 } 19 20 namespace base { 21 22 class TestFeatureVisitor; 23 24 // An interface for EarlyBootFeatureVisitor that provides a method to 25 // iterate over a feature's name, override state, parameters, and associated 26 // field trial. 27 // 28 // NOTE: This is intended only for the special case of needing to get all 29 // feature overrides. Most users should call FeatureList::IsEnabled() to query 30 // a feature's state. 31 class FeatureVisitor { 32 public: 33 FeatureVisitor(const FeatureVisitor&) = delete; 34 FeatureVisitor& operator=(const FeatureVisitor&) = delete; 35 36 virtual ~FeatureVisitor() = default; 37 38 // Intended to be called in FeatureList::VisitFeaturesAndParams(). This method 39 // is called once per feature. 40 virtual void Visit(const std::string& feature_name, 41 FeatureList::OverrideState override_state, 42 const std::map<std::string, std::string>& params, 43 const std::string& trial_name, 44 const std::string& group_name) = 0; 45 46 private: 47 friend variations::cros_early_boot::evaluate_seed::EarlyBootFeatureVisitor; 48 friend TestFeatureVisitor; 49 50 // The constructor is private so only friend classes can inherit from this 51 // class. This limits access to who can iterate over features in 52 // FeatureList::VisitFeaturesAndParams(). 53 FeatureVisitor() = default; 54 }; 55 56 } // namespace base 57 58 #endif // BASE_FEATURE_VISITOR_H_ 59