Chromium Code Reviews| Index: base/android/jni_android.h |
| diff --git a/base/android/jni_android.h b/base/android/jni_android.h |
| index 492f11ff90bbcafbd70a8a8f659287eddd94d23a..69bd36c0ac74c087ce4f1930ff9f03f501103b07 100644 |
| --- a/base/android/jni_android.h |
| +++ b/base/android/jni_android.h |
| @@ -9,7 +9,9 @@ |
| #include <sys/types.h> |
| #include "base/android/scoped_java_ref.h" |
| +#include "base/atomicops.h" |
| #include "base/compiler_specific.h" |
| +#include "base/logging.h" |
|
joth
2012/10/02 17:47:43
rather than pull this spew into the header, can yo
bulach
2012/10/03 13:09:00
see above: I split this into its own file, let me
|
| namespace base { |
| namespace android { |
| @@ -136,6 +138,46 @@ bool ClearException(JNIEnv* env); |
| // This function will call CHECK() macro if there's any pending exception. |
| void CheckException(JNIEnv* env); |
| +class LazyMethodID { |
|
joth
2012/10/02 17:47:43
needs class (function) doc
- when to use
- how to
bulach
2012/10/03 13:09:00
Done.
|
| + public: |
| + enum MethodType { |
| + METHODTYPE_STATIC, |
| + METHODTYPE_NORMAL, |
| + }; |
| + |
| + enum ExceptionCheck { |
| + EXCEPTIONCHECK_YES, |
| + EXCEPTIONCHECK_NO, |
| + }; |
|
joth
2012/10/02 17:47:43
enum duplication from the previous patch feels fin
bulach
2012/10/02 18:20:42
sure, as soon as the other patch lands :)
fyi, I d
|
| + |
| + template<MethodType method_type, ExceptionCheck exception_check> |
| + static void Get(JNIEnv* env, |
|
joth
2012/10/02 17:47:43
why is this in a class?
bulach
2012/10/03 13:09:00
we already have a bunch of free functions here, an
|
| + jclass clazz, |
| + const char* method_name, |
| + const char* jni_signature, |
| + jmethodID* method_id) { |
|
joth
2012/10/02 17:47:43
method_id should be passed in & out as a AtomicWor
bulach
2012/10/02 18:20:42
sorry, not sure I understood..
the caller has "sta
joth
2012/10/02 18:30:39
Neither! :-)
Calling code:
static AtomicWord g_
bulach
2012/10/03 13:09:00
Done.
|
| + subtle::AtomicWord* atomic = reinterpret_cast<subtle::AtomicWord*>( |
| + method_id); |
|
joth
2012/10/02 17:47:43
nit: could compile assert that sizeof(AtomicWord)
bulach
2012/10/03 13:09:00
Done.
|
| + subtle::AtomicWord value = base::subtle::Acquire_Load(atomic); |
| + if (value) |
| + return; |
|
joth
2012/10/02 17:47:43
need to document on the function that the caller i
bulach
2012/10/03 13:09:00
Done.
|
| + jmethodID id = method_type == METHODTYPE_STATIC ? |
|
joth
2012/10/02 17:47:43
comment that if we get a race in loading the value
bulach
2012/10/03 13:09:00
Done.
|
| + env->GetStaticMethodID(clazz, method_name, jni_signature) : |
|
joth
2012/10/02 17:47:43
as |env| is only need in uncommon case, we could c
bulach
2012/10/03 13:09:00
so far, the caller seems to always have one.
|
| + env->GetMethodID(clazz, method_name, jni_signature); |
| + if (exception_check == EXCEPTIONCHECK_YES) { |
| + CHECK(id || base::android::ClearException(env)) << |
| + "Failed to find " << |
| + (method_type == METHODTYPE_STATIC ? "static " : "") << |
| + "method " << method_name << " " << jni_signature; |
| + } else if (base::android::HasException(env)) { |
| + env->ExceptionClear(); |
|
joth
2012/10/02 17:47:43
can we call an existing GetMethodID blah class her
bulach
2012/10/03 13:09:00
see above.. I'd prefer to move towards this api an
|
| + } |
| + base::subtle::Acquire_Store( |
|
joth
2012/10/02 17:47:43
This needs to be a Release_Store
bulach
2012/10/03 13:09:00
Done.
|
| + atomic, reinterpret_cast<subtle::AtomicWord>(id)); |
| + } |
| +}; |
| + |
| + |
| } // namespace android |
| } // namespace base |