#include "chrome/android/modules/stack_unwinder/public/module.h"
#include "base/android/jni_android.h"
#include "base/memory/ptr_util.h"
#include "chrome/android/modules/stack_unwinder/provider/jni_headers/StackUnwinderModuleProvider_jni.h"
namespace stack_unwinder {
bool Module::IsInstalled() {
if (base::android::IsJavaAvailable()) {
JNIEnv* env = base::android::AttachCurrentThread();
return Java_StackUnwinderModuleProvider_isModuleInstalled(env);
} else {
return false;
}
}
void Module::RequestInstallation() {
JNIEnv* env = base::android::AttachCurrentThread();
Java_StackUnwinderModuleProvider_installModule(env);
}
std::unique_ptr<Module> Module::Load() {
CHECK(IsInstalled());
JNIEnv* env = base::android::AttachCurrentThread();
Java_StackUnwinderModuleProvider_ensureNativeLoaded(env);
DoNothingFunction do_nothing = reinterpret_cast<DoNothingFunction>(
Java_StackUnwinderModuleProvider_getDoNothingFunction(env));
return base::WrapUnique(new Module(do_nothing));
}
void Module::DoNothing() {
return do_nothing_();
}
Module::Module(DoNothingFunction do_nothing) : do_nothing_(do_nothing) {
DCHECK(do_nothing);
}
}
DEFINE_JNI(StackUnwinderModuleProvider)