// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // This file is autogenerated by // base/android/jni_generator/jni_generator.py // For // org/chromium/foo/Foo #ifndef org_chromium_foo_Foo_JNI #define org_chromium_foo_Foo_JNI #include #include "base/android/jni_generator/jni_generator_helper.h" #include "base/android/jni_int_wrapper.h" // Step 1: forward declarations. namespace { const char kFooClassPath[] = "org/chromium/foo/Foo"; // Leaking this jclass as we cannot use LazyInstance from some threads. jclass g_Foo_clazz = NULL; #define Foo_clazz(env) g_Foo_clazz } // namespace // Step 2: method stubs. static void DoSomething(JNIEnv* env, const JavaParamRef& jcaller, const JavaParamRef& callback1, const JavaParamRef& callback2); static void Java_org_chromium_foo_Foo_nativeDoSomething(JNIEnv* env, jclass jcaller, jobject callback1, jobject callback2) { return DoSomething(env, JavaParamRef(env, jcaller), JavaParamRef(env, callback1), JavaParamRef(env, callback2)); } static base::subtle::AtomicWord g_Foo_calledByNative = 0; static void Java_Foo_calledByNative(JNIEnv* env, jobject callback1, jobject callback2) { /* Must call RegisterNativesImpl() */ CHECK_CLAZZ(env, Foo_clazz(env), Foo_clazz(env)); jmethodID method_id = base::android::MethodID::LazyGet< base::android::MethodID::TYPE_STATIC>( env, Foo_clazz(env), "calledByNative", "(" "Lorg/chromium/foo/Bar1$Callback;" "Lorg/chromium/foo/Bar2$Callback;" ")" "V", &g_Foo_calledByNative); env->CallStaticVoidMethod(Foo_clazz(env), method_id, callback1, callback2); jni_generator::CheckException(env); } // Step 3: RegisterNatives. static const JNINativeMethod kMethodsFoo[] = { { "nativeDoSomething", "(" "Lorg/chromium/foo/Bar1$Callback;" "Lorg/chromium/foo/Bar2$Callback;" ")" "V", reinterpret_cast(Java_org_chromium_foo_Foo_nativeDoSomething) }, }; static bool RegisterNativesImpl(JNIEnv* env) { g_Foo_clazz = reinterpret_cast(env->NewGlobalRef( base::android::GetClass(env, kFooClassPath).obj())); const int kMethodsFooSize = arraysize(kMethodsFoo); if (env->RegisterNatives(Foo_clazz(env), kMethodsFoo, kMethodsFooSize) < 0) { jni_generator::HandleRegistrationError( env, Foo_clazz(env), __FILE__); return false; } return true; } #endif // org_chromium_foo_Foo_JNI