ui_base_feature_list_android.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/android/jni_string.h"
  5. #include "base/feature_list.h"
  6. #include "base/notreached.h"
  7. #include "ui/base/ui_base_features.h"
  8. #include "ui/base/ui_base_jni_headers/UiBaseFeatureList_jni.h"
  9. using base::android::ConvertJavaStringToUTF8;
  10. using base::android::JavaParamRef;
  11. namespace features {
  12. namespace {
  13. // Array of features exposed through the Java UiBaseFeatureList API. Entries in
  14. // this array may either refer to features defined in the header of this file or
  15. // in other locations in the code base (e.g. ui_base_features.h).
  16. const base::Feature* const kFeaturesExposedToJava[] = {
  17. &features::kAndroidPermissionsCache,
  18. }; // namespace
  19. const base::Feature* FindFeatureExposedToJava(const std::string& feature_name) {
  20. for (const base::Feature* feature : kFeaturesExposedToJava) {
  21. if (feature->name == feature_name)
  22. return feature;
  23. }
  24. NOTREACHED() << "Queried feature cannot be found in BaseFeatureList: "
  25. << feature_name;
  26. return nullptr;
  27. }
  28. } // namespace
  29. static jboolean JNI_UiBaseFeatureList_IsEnabled(
  30. JNIEnv* env,
  31. const JavaParamRef<jstring>& jfeature_name) {
  32. const base::Feature* feature =
  33. FindFeatureExposedToJava(ConvertJavaStringToUTF8(env, jfeature_name));
  34. return base::FeatureList::IsEnabled(*feature);
  35. }
  36. } // namespace features