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