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 13 namespace variations::cros_early_boot::evaluate_seed { 14 class EarlyBootFeatureVisitor; 15 } 16 17 namespace gin { 18 class V8FeatureVisitor; 19 } 20 21 namespace base { 22 23 class TestFeatureVisitor; 24 25 // An interface for FeatureList that provides a method to iterate over a 26 // feature's name, override state, parameters, and associated 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 gin::V8FeatureVisitor; 49 friend TestFeatureVisitor; 50 51 // The constructor is private so only friend classes can inherit from this 52 // class. This limits access to who can iterate over features in 53 // FeatureList::VisitFeaturesAndParams(). 54 FeatureVisitor() = default; 55 }; 56 57 } // namespace base 58 59 #endif // BASE_FEATURE_VISITOR_H_ 60