chromium/components/gwp_asan/client/feature_map.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/android/feature_map.h"

#include <jni.h>

#include "base/feature_list.h"
#include "base/no_destructor.h"
#include "components/gwp_asan/client/android/gwp_asan_headers/GwpAsanFeatureMap_jni.h"
#include "components/gwp_asan/client/gwp_asan_features.h"

// This source-only file is boilerplate generated by following
// `android_accessing_cpp_features_in_java.md`.

namespace gwp_asan::android {
namespace {

const base::Feature* const kFeaturesExposedToJava[] = {
    &internal::kGwpAsanMalloc,
    &internal::kGwpAsanPartitionAlloc,
};

// static
base::android::FeatureMap* GetFeatureMap() {
  static base::NoDestructor<base::android::FeatureMap> kFeatureMap(std::vector(
      std::begin(kFeaturesExposedToJava), std::end(kFeaturesExposedToJava)));
  return kFeatureMap.get();
}

}  // namespace

static jlong JNI_GwpAsanFeatureMap_GetNativeMap(JNIEnv* env) {
  return reinterpret_cast<jlong>(GetFeatureMap());
}

}  // namespace gwp_asan::android