| OLD | NEW | 
|   1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |   1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
|   2 // Use of this source code is governed by a BSD-style license that can be |   2 // Use of this source code is governed by a BSD-style license that can be | 
|   3 // found in the LICENSE file. |   3 // found in the LICENSE file. | 
|   4  |   4  | 
|   5 // This file is autogenerated by |   5 // This file is autogenerated by | 
|   6 //     base/android/jni_generator/jni_generator.py |   6 //     base/android/jni_generator/jni_generator.py | 
|   7 // For |   7 // For | 
|   8 //     org/chromium/foo/Foo |   8 //     org/chromium/foo/Foo | 
|   9  |   9  | 
|  10 #ifndef org_chromium_foo_Foo_JNI |  10 #ifndef org_chromium_foo_Foo_JNI | 
|  11 #define org_chromium_foo_Foo_JNI |  11 #define org_chromium_foo_Foo_JNI | 
|  12  |  12  | 
|  13 #include <jni.h> |  13 #include <jni.h> | 
|  14  |  14  | 
|  15 #include "base/android/jni_generator/jni_generator_helper.h" |  15 #include "base/android/jni_generator/jni_generator_helper.h" | 
|  16  |  16  | 
|  17 #include "base/android/jni_int_wrapper.h" |  17 #include "base/android/jni_int_wrapper.h" | 
|  18  |  18  | 
|  19 // Step 1: forward declarations. |  19 // Step 1: forward declarations. | 
|  20 namespace { |  20 namespace { | 
|  21 const char kFooClassPath[] = "org/chromium/foo/Foo"; |  21 const char kFooClassPath[] = "org/chromium/foo/Foo"; | 
|  22 // Leaking this jclass as we cannot use LazyInstance from some threads. |  22 // Leaking this jclass as we cannot use LazyInstance from some threads. | 
|  23 jclass g_Foo_clazz = NULL; |  23 jclass g_Foo_clazz = NULL; | 
|  24  |  24  | 
|  25 }  // namespace |  25 }  // namespace | 
|  26  |  26  | 
|  27 static void DoSomething(JNIEnv* env, jclass jcaller, |  27 static void DoSomething(JNIEnv* env, jclass jcaller, | 
|  28     jobject callback); |  28     jobject callback1, | 
 |  29     jobject callback2); | 
|  29  |  30  | 
|  30 // Step 2: method stubs. |  31 // Step 2: method stubs. | 
|  31  |  32  | 
|  32 static base::subtle::AtomicWord g_Foo_calledByNative = 0; |  33 static base::subtle::AtomicWord g_Foo_calledByNative = 0; | 
|  33 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback) { |  34 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback1, | 
 |  35     jobject callback2) { | 
|  34   /* Must call RegisterNativesImpl()  */ |  36   /* Must call RegisterNativesImpl()  */ | 
|  35   CHECK_CLAZZ(env, g_Foo_clazz, |  37   CHECK_CLAZZ(env, g_Foo_clazz, | 
|  36       g_Foo_clazz); |  38       g_Foo_clazz); | 
|  37   jmethodID method_id = |  39   jmethodID method_id = | 
|  38       base::android::MethodID::LazyGet< |  40       base::android::MethodID::LazyGet< | 
|  39       base::android::MethodID::TYPE_STATIC>( |  41       base::android::MethodID::TYPE_STATIC>( | 
|  40       env, g_Foo_clazz, |  42       env, g_Foo_clazz, | 
|  41       "calledByNative", |  43       "calledByNative", | 
|  42  |  44  | 
|  43 "(" |  45 "(" | 
|  44 "Lorg/chromium/foo/Bar$Callback;" |  46 "Lorg/chromium/foo/Bar1$Callback;" | 
 |  47 "Lorg/chromium/foo/Bar2$Callback;" | 
|  45 ")" |  48 ")" | 
|  46 "V", |  49 "V", | 
|  47       &g_Foo_calledByNative); |  50       &g_Foo_calledByNative); | 
|  48  |  51  | 
|  49      env->CallStaticVoidMethod(g_Foo_clazz, |  52      env->CallStaticVoidMethod(g_Foo_clazz, | 
|  50           method_id, callback); |  53           method_id, callback1, callback2); | 
|  51   jni_generator::CheckException(env); |  54   jni_generator::CheckException(env); | 
|  52  |  55  | 
|  53 } |  56 } | 
|  54  |  57  | 
|  55 // Step 3: RegisterNatives. |  58 // Step 3: RegisterNatives. | 
|  56  |  59  | 
|  57 static const JNINativeMethod kMethodsFoo[] = { |  60 static const JNINativeMethod kMethodsFoo[] = { | 
|  58     { "nativeDoSomething", |  61     { "nativeDoSomething", | 
|  59 "(" |  62 "(" | 
|  60 "Lorg/chromium/foo/Bar$Callback;" |  63 "Lorg/chromium/foo/Bar1$Callback;" | 
 |  64 "Lorg/chromium/foo/Bar2$Callback;" | 
|  61 ")" |  65 ")" | 
|  62 "V", reinterpret_cast<void*>(DoSomething) }, |  66 "V", reinterpret_cast<void*>(DoSomething) }, | 
|  63 }; |  67 }; | 
|  64  |  68  | 
|  65 static bool RegisterNativesImpl(JNIEnv* env) { |  69 static bool RegisterNativesImpl(JNIEnv* env) { | 
|  66   g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |  70   g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | 
|  67       base::android::GetClass(env, kFooClassPath).obj())); |  71       base::android::GetClass(env, kFooClassPath).obj())); | 
|  68  |  72  | 
|  69   const int kMethodsFooSize = arraysize(kMethodsFoo); |  73   const int kMethodsFooSize = arraysize(kMethodsFoo); | 
|  70  |  74  | 
|  71   if (env->RegisterNatives(g_Foo_clazz, |  75   if (env->RegisterNatives(g_Foo_clazz, | 
|  72                            kMethodsFoo, |  76                            kMethodsFoo, | 
|  73                            kMethodsFooSize) < 0) { |  77                            kMethodsFooSize) < 0) { | 
|  74     jni_generator::HandleRegistrationError( |  78     jni_generator::HandleRegistrationError( | 
|  75         env, g_Foo_clazz, __FILE__); |  79         env, g_Foo_clazz, __FILE__); | 
|  76     return false; |  80     return false; | 
|  77   } |  81   } | 
|  78  |  82  | 
|  79   return true; |  83   return true; | 
|  80 } |  84 } | 
|  81  |  85  | 
|  82 #endif  // org_chromium_foo_Foo_JNI |  86 #endif  // org_chromium_foo_Foo_JNI | 
| OLD | NEW |