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

Unified Diff: base/android/jni_android.h

Issue 11038015: Android: lazy initialization for method id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/android/jni_android.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/jni_android.h
diff --git a/base/android/jni_android.h b/base/android/jni_android.h
index 40e235943c64b88e04a1bd16166f107c81c574cf..a3ac18a164e95d150d53ebdc2afe511a5f004ac3 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,36 @@ 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 Type {
+ TYPE_STATIC,
+ TYPE_INSTANCE,
+ };
+
+ // 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.
+ template<Type type>
+ 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|.
+ // It's fine to simultaneously call this on multiple threads referencing the
+ // same |atomic_method_id|.
+ template<Type type>
+ 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::Get() above avoids a class lookup, but does not cache results.
// 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
« no previous file with comments | « no previous file | base/android/jni_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698