1 // Copyright 2023 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_ANDROID_FEATURE_MAP_H_ 6 #define BASE_ANDROID_FEATURE_MAP_H_ 7 8 #include <string> 9 10 #include "base/base_export.h" 11 #include "base/containers/flat_map.h" 12 #include "base/feature_list.h" 13 #include "base/memory/raw_ptr.h" 14 15 namespace base::android { 16 17 // A FeatureMap is a mapping from base:Feature's names to a pointer to the 18 // base:Feature. 19 // This is necessary because in Java, features flags are identified by the 20 // feature name, a string, so calls from Java to (for example) check the state 21 // of a feature flag need to convert the string to a non-owning Feature*. 22 // Each component should have its own FeatureMap. 23 class BASE_EXPORT FeatureMap { 24 public: 25 explicit FeatureMap(std::vector<const Feature*> featuresExposedToJava); 26 ~FeatureMap(); 27 28 // Map a |feature_name| to a Feature*. 29 const Feature* FindFeatureExposedToJava(const std::string& feature_name); 30 31 private: 32 flat_map<std::string_view, raw_ptr<const Feature, CtnExperimental>> mapping_; 33 }; 34 35 } // namespace base::android 36 37 #endif // BASE_ANDROID_FEATURE_MAP_H_ 38