Chromium Code Reviews| Index: base/android/jni_android.h |
| diff --git a/base/android/jni_android.h b/base/android/jni_android.h |
| index 40e235943c64b88e04a1bd16166f107c81c574cf..6b831a74f795ce63d1936e4c2f660ac029af60a4 100644 |
| --- a/base/android/jni_android.h |
| +++ b/base/android/jni_android.h |
| @@ -9,6 +9,7 @@ |
| #include <sys/types.h> |
| #include "base/android/scoped_java_ref.h" |
| +#include "base/atomicops.h" |
| #include "base/compiler_specific.h" |
| namespace base { |
| @@ -57,56 +58,44 @@ jclass GetUnscopedClass(JNIEnv* env, const char* class_name) WARN_UNUSED_RESULT; |
| // Returns true iff the class |class_name| could be found. |
| bool HasClass(JNIEnv* env, const char* class_name); |
| -// Returns the method ID for the method with the specified name and signature. |
| -// This method triggers a fatal assertion if the method could not be found. |
| -// Use HasMethod if you need to check whether a method exists. |
| -jmethodID GetMethodID(JNIEnv* env, |
| - const JavaRef<jclass>& clazz, |
| - const char* method_name, |
| - const char* jni_signature); |
| - |
| -// Similar to GetMethodID, but takes a raw jclass. |
| -jmethodID GetMethodID(JNIEnv* env, |
| - jclass clazz, |
| - const char* method_name, |
| - const char* jni_signature); |
| - |
| -// Unlike GetMethodID, returns NULL if the method could not be found. |
| -jmethodID GetMethodIDOrNull(JNIEnv* env, |
| - jclass clazz, |
| - const char* method_name, |
| - const char* jni_signature); |
| - |
| -// Returns the method ID for the static method with the specified name and |
| -// signature. |
| -// This method triggers a fatal assertion if the method could not be found. |
| -// Use HasMethod if you need to check whether a method exists. |
| -jmethodID GetStaticMethodID(JNIEnv* env, |
| - const JavaRef<jclass>& clazz, |
| - const char* method_name, |
| - const char* jni_signature); |
| - |
| -// Similar to the GetStaticMethodID, but takes a raw jclass. |
| -jmethodID GetStaticMethodID(JNIEnv* env, |
| - jclass clazz, |
| - const char* method_name, |
| - const char* jni_signature); |
| - |
| -// Unlike GetStaticMethodID, returns NULL if the method could not be found. |
| -jmethodID GetStaticMethodIDOrNull(JNIEnv* env, |
| - jclass clazz, |
| - const char* method_name, |
| - const char* jni_signature); |
| - |
| -// Returns true iff |clazz| has a method with the specified name and signature. |
| -bool HasMethod(JNIEnv* env, |
| - const JavaRef<jclass>& clazz, |
| - const char* method_name, |
| - const char* jni_signature); |
| +// This class is a wrapper for JNIEnv Get(Static)MethodID. |
| +class MethodID { |
| + public: |
| + enum MethodType { |
| + METHODTYPE_STATIC, |
| + METHODTYPE_NORMAL, |
| + }; |
| + |
| + // Wether or not to CHECK if an exception happens when |
| + // trying to obtain a method id. |
| + enum ExceptionCheck { |
| + EXCEPTIONCHECK_NO, |
| + EXCEPTIONCHECK_YES, |
| + }; |
| + |
| + template<MethodType method_type, |
| + ExceptionCheck exception_check> |
| + static jmethodID Get(JNIEnv* env, |
| + jclass clazz, |
| + const char* method_name, |
| + const char* jni_signature); |
| + |
| + // The caller is responsible to zero-initialize |atomic_method_id|. |
| + // If it's set, it'll return immediately. Otherwise, it'll call into |
| + // ::Get() above. If there's a race, it's ok since the values are the same |
|
joth
2012/10/04 17:59:59
nit: if there's a race... is all implementation de
bulach
2012/10/04 18:58:17
Done.
|
| + // (and the duplicated effort will happen only once). |
| + template<MethodType method_type, |
| + ExceptionCheck exception_check> |
| + static jmethodID LazyGet(JNIEnv* env, |
| + jclass clazz, |
| + const char* method_name, |
| + const char* jni_signature, |
| + base::subtle::AtomicWord* atomic_method_id); |
| +}; |
| // Gets the method ID from the class name. Clears the pending Java exception |
| // and returns NULL if the method is not found. Caches results. Note that |
| -// GetMethodID() below avoids a class lookup, but does not cache results. |
| +// MethodID() above avoids a class lookup, but does not cache results. |
|
joth
2012/10/04 17:59:59
nit: MethodID above is not a function. MethodID::G
bulach
2012/10/04 18:58:17
Done.
|
| // Strings passed to this function are held in the cache and MUST remain valid |
| // beyond the duration of all future calls to this function, across all |
| // threads. In practice, this means that the function should only be used with |