Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: base/android/jni_generator/testMultipleJNIAdditionalImport.golden

Issue 472553002: Make class lookup lazy in jni_generator when using lazy method lookup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #if __clang__
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wunused-function"
25 #endif
22 // Leaking this jclass as we cannot use LazyInstance from some threads. 26 // Leaking this jclass as we cannot use LazyInstance from some threads.
23 jclass g_Foo_clazz = NULL; 27 jclass g_Foo_clazz = NULL;
28 jclass Foo_clazz(JNIEnv*) { return g_Foo_clazz; }
29 #if __clang__
30 #pragma clang diagnostic pop
31 #endif
24 32
25 } // namespace 33 } // namespace
26 34
27 static void DoSomething(JNIEnv* env, jclass jcaller, 35 static void DoSomething(JNIEnv* env, jclass jcaller,
28 jobject callback1, 36 jobject callback1,
29 jobject callback2); 37 jobject callback2);
30 38
31 // Step 2: method stubs. 39 // Step 2: method stubs.
32 40
33 static base::subtle::AtomicWord g_Foo_calledByNative = 0; 41 static base::subtle::AtomicWord g_Foo_calledByNative = 0;
34 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback1, 42 static void Java_Foo_calledByNative(JNIEnv* env, jobject callback1,
35 jobject callback2) { 43 jobject callback2) {
36 /* Must call RegisterNativesImpl() */ 44 /* Must call RegisterNativesImpl() */
37 CHECK_CLAZZ(env, g_Foo_clazz, 45 CHECK_CLAZZ(env, Foo_clazz(env),
38 g_Foo_clazz); 46 Foo_clazz(env));
39 jmethodID method_id = 47 jmethodID method_id =
40 base::android::MethodID::LazyGet< 48 base::android::MethodID::LazyGet<
41 base::android::MethodID::TYPE_STATIC>( 49 base::android::MethodID::TYPE_STATIC>(
42 env, g_Foo_clazz, 50 env, Foo_clazz(env),
43 "calledByNative", 51 "calledByNative",
44 52
45 "(" 53 "("
46 "Lorg/chromium/foo/Bar1$Callback;" 54 "Lorg/chromium/foo/Bar1$Callback;"
47 "Lorg/chromium/foo/Bar2$Callback;" 55 "Lorg/chromium/foo/Bar2$Callback;"
48 ")" 56 ")"
49 "V", 57 "V",
50 &g_Foo_calledByNative); 58 &g_Foo_calledByNative);
51 59
52 env->CallStaticVoidMethod(g_Foo_clazz, 60 env->CallStaticVoidMethod(Foo_clazz(env),
53 method_id, callback1, callback2); 61 method_id, callback1, callback2);
54 jni_generator::CheckException(env); 62 jni_generator::CheckException(env);
55 63
56 } 64 }
57 65
58 // Step 3: RegisterNatives. 66 // Step 3: RegisterNatives.
59 67
60 static const JNINativeMethod kMethodsFoo[] = { 68 static const JNINativeMethod kMethodsFoo[] = {
61 { "nativeDoSomething", 69 { "nativeDoSomething",
62 "(" 70 "("
63 "Lorg/chromium/foo/Bar1$Callback;" 71 "Lorg/chromium/foo/Bar1$Callback;"
64 "Lorg/chromium/foo/Bar2$Callback;" 72 "Lorg/chromium/foo/Bar2$Callback;"
65 ")" 73 ")"
66 "V", reinterpret_cast<void*>(DoSomething) }, 74 "V", reinterpret_cast<void*>(DoSomething) },
67 }; 75 };
68 76
69 static bool RegisterNativesImpl(JNIEnv* env) { 77 static bool RegisterNativesImpl(JNIEnv* env) {
70 g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( 78 g_Foo_clazz = reinterpret_cast<jclass>(env->NewGlobalRef(
71 base::android::GetClass(env, kFooClassPath).obj())); 79 base::android::GetClass(env, kFooClassPath).obj()));
72 80
73 const int kMethodsFooSize = arraysize(kMethodsFoo); 81 const int kMethodsFooSize = arraysize(kMethodsFoo);
74 82
75 if (env->RegisterNatives(g_Foo_clazz, 83 if (env->RegisterNatives(Foo_clazz(env),
76 kMethodsFoo, 84 kMethodsFoo,
77 kMethodsFooSize) < 0) { 85 kMethodsFooSize) < 0) {
78 jni_generator::HandleRegistrationError( 86 jni_generator::HandleRegistrationError(
79 env, g_Foo_clazz, __FILE__); 87 env, Foo_clazz(env), __FILE__);
80 return false; 88 return false;
81 } 89 }
82 90
83 return true; 91 return true;
84 } 92 }
85 93
86 #endif // org_chromium_foo_Foo_JNI 94 #endif // org_chromium_foo_Foo_JNI
OLDNEW
« no previous file with comments | « base/android/jni_generator/testJarJarRemapping.golden ('k') | base/android/jni_generator/testNativeExportsOption.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698