OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
6 | 6 |
| 7 #include "base/android/scoped_java_ref.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 | 9 |
9 namespace { | 10 namespace { |
10 JavaVM* g_jvm = 0; | 11 JavaVM* g_jvm = 0; |
11 jobject g_application_context = NULL; | 12 jobject g_application_context = NULL; |
12 } | 13 } |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 namespace android { | 16 namespace android { |
16 | 17 |
(...skipping 22 matching lines...) Expand all Loading... |
39 void InitApplicationContext(jobject context) { | 40 void InitApplicationContext(jobject context) { |
40 DCHECK(!g_application_context); | 41 DCHECK(!g_application_context); |
41 g_application_context = context; | 42 g_application_context = context; |
42 } | 43 } |
43 | 44 |
44 jobject GetApplicationContext() { | 45 jobject GetApplicationContext() { |
45 DCHECK(g_application_context); | 46 DCHECK(g_application_context); |
46 return g_application_context; | 47 return g_application_context; |
47 } | 48 } |
48 | 49 |
| 50 MethodID::MethodID(JNIEnv* env, const char* class_name, const char* method, |
| 51 const char* jni_signature) { |
| 52 ScopedJavaLocalRef<jclass> clazz(env, env->FindClass(class_name)); |
| 53 id_ = GetMethodID(env, clazz.obj(), method, jni_signature); |
| 54 } |
| 55 |
49 jmethodID GetMethodID(JNIEnv* env, | 56 jmethodID GetMethodID(JNIEnv* env, |
50 jclass clazz, | 57 jclass clazz, |
51 const char* const method, | 58 const char* const method, |
52 const char* const jni_signature) { | 59 const char* const jni_signature) { |
53 jmethodID id = env->GetMethodID(clazz, method, jni_signature); | 60 jmethodID id = env->GetMethodID(clazz, method, jni_signature); |
54 DCHECK(id) << method; | 61 DCHECK(id) << method; |
55 CheckException(env); | 62 CheckException(env); |
56 return id; | 63 return id; |
57 } | 64 } |
58 | 65 |
59 jmethodID GetStaticMethodID(JNIEnv* env, | 66 jmethodID GetStaticMethodID(JNIEnv* env, |
60 jclass clazz, | 67 jclass clazz, |
61 const char* const method, | 68 const char* const method, |
62 const char* const jni_signature) { | 69 const char* const jni_signature) { |
63 jmethodID id = env->GetStaticMethodID(clazz, method, jni_signature); | 70 jmethodID id = env->GetStaticMethodID(clazz, method, jni_signature); |
64 DCHECK(id) << method; | 71 DCHECK(id) << method; |
65 CheckException(env); | 72 CheckException(env); |
66 return id; | 73 return id; |
67 } | 74 } |
68 | 75 |
| 76 jfieldID GetFieldID(JNIEnv* env, |
| 77 jclass clazz, |
| 78 const char* field, |
| 79 const char* jni_signature) { |
| 80 jfieldID id = env->GetFieldID(clazz, field, jni_signature); |
| 81 DCHECK(id) << field; |
| 82 CheckException(env); |
| 83 return id; |
| 84 } |
| 85 |
69 bool CheckException(JNIEnv* env) { | 86 bool CheckException(JNIEnv* env) { |
70 if (env->ExceptionCheck() == JNI_FALSE) | 87 if (env->ExceptionCheck() == JNI_FALSE) |
71 return false; | 88 return false; |
72 env->ExceptionDescribe(); | 89 env->ExceptionDescribe(); |
73 env->ExceptionClear(); | 90 env->ExceptionClear(); |
74 return true; | 91 return true; |
75 } | 92 } |
76 | 93 |
77 } // namespace android | 94 } // namespace android |
78 } // namespace base | 95 } // namespace base |
OLD | NEW |