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