Index: base/android/jni_android.cc |
diff --git a/base/android/jni_android.cc b/base/android/jni_android.cc |
index d3b4e79058381652baf17f512ce57c2c8b2fb0fe..713691d8f789ffc81022add00a6ec3bbdede68c9 100644 |
--- a/base/android/jni_android.cc |
+++ b/base/android/jni_android.cc |
@@ -96,6 +96,37 @@ std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) { |
return ConvertJavaStringToUTF8(exception_string); |
} |
+ |
+enum MethodType { |
+ METHODTYPE_STATIC, |
+ METHODTYPE_NORMAL, |
+}; |
+ |
+enum ExceptionCheck { |
+ EXCEPTIIONCHECK_YES, |
nyquist
2012/10/02 02:59:17
Remove one I from the enum value from these two
EX
bulach
2012/10/02 08:19:22
Done.
|
+ EXCEPTIIONCHECK_NO, |
+}; |
+ |
+jmethodID GetMethodIDInternal(JNIEnv* env, |
+ jclass clazz, |
+ const char* method_name, |
+ const char* jni_signature, |
+ MethodType method_type, |
+ ExceptionCheck exception_check) { |
+ jmethodID method_id = method_type == METHODTYPE_STATIC ? |
+ env->GetMethodID(clazz, method_name, jni_signature) : |
nyquist
2012/10/02 02:59:17
These two lines should be swapped. If method_type
bulach
2012/10/02 08:19:22
Done.
|
+ env->GetStaticMethodID(clazz, method_name, jni_signature); |
+ if (exception_check == EXCEPTIIONCHECK_YES) { |
+ CHECK(method_id && base::android::ClearException(env)) << |
nyquist
2012/10/02 02:59:17
Can we use || instead of && here? Otherwise we mig
bulach
2012/10/02 08:19:22
Done.
|
+ "Failed to find " << |
+ (method_type == METHODTYPE_STATIC ? "static" : "") << |
nyquist
2012/10/02 02:59:17
Add space after static: "static " : ""
bulach
2012/10/02 08:19:22
Done.
|
+ "method " << method_name << " " << jni_signature; |
+ } else if (base::android::HasException(env)) { |
+ env->ExceptionClear(); |
+ } |
+ return method_id; |
+} |
+ |
} // namespace |
namespace base { |
@@ -165,11 +196,18 @@ jmethodID GetMethodID(JNIEnv* env, |
jclass clazz, |
const char* method_name, |
const char* jni_signature) { |
- jmethodID method_id = |
- env->GetMethodID(clazz, method_name, jni_signature); |
- CHECK(method_id && !ClearException(env)) << "Failed to find method " << |
- method_name << " " << jni_signature; |
- return method_id; |
+ return GetMethodIDInternal( |
+ env, clazz, method_name, jni_signature, |
+ METHODTYPE_NORMAL, EXCEPTIIONCHECK_YES); |
+} |
+ |
+jmethodID GetMethodIDOrNull(JNIEnv* env, |
+ jclass clazz, |
+ const char* method_name, |
+ const char* jni_signature) { |
+ return GetMethodIDInternal( |
+ env, clazz, method_name, jni_signature, |
+ METHODTYPE_NORMAL, EXCEPTIIONCHECK_NO); |
} |
jmethodID GetStaticMethodID(JNIEnv* env, |
@@ -184,11 +222,18 @@ jmethodID GetStaticMethodID(JNIEnv* env, |
jclass clazz, |
const char* method_name, |
const char* jni_signature) { |
- jmethodID method_id = |
- env->GetStaticMethodID(clazz, method_name, jni_signature); |
- CHECK(method_id && !ClearException(env)) << "Failed to find static method " << |
- method_name << " " << jni_signature; |
- return method_id; |
+ return GetMethodIDInternal( |
+ env, clazz, method_name, jni_signature, |
+ METHODTYPE_STATIC, EXCEPTIIONCHECK_YES); |
+} |
+ |
+jmethodID GetStaticMethodIDOrNull(JNIEnv* env, |
+ jclass clazz, |
+ const char* method_name, |
+ const char* jni_signature) { |
+ return GetMethodIDInternal( |
+ env, clazz, method_name, jni_signature, |
+ METHODTYPE_STATIC, EXCEPTIIONCHECK_NO); |
} |
bool HasMethod(JNIEnv* env, |