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

Unified Diff: base/android/jni_android.h

Issue 9358028: Upstream Android JNI code, allowing us to use more ScopedJava references. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased and added a TODO Created 8 years, 10 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 a5571e023fb87060a3b410d18eccb7124135fad9..d438096db16f54c4e9e9ea429193e72e497ea770 100644
--- a/base/android/jni_android.h
+++ b/base/android/jni_android.h
@@ -26,13 +26,45 @@ void InitVM(JavaVM* vm);
// Initializes the global application context object. The |context| can be any
// valid reference to the application context. Internally holds a global ref to
// the context. InitVM and InitApplicationContext maybe called in either order.
-// TODO: We might combine InitVM() and InitApplicationContext() into one method.
void InitApplicationContext(const JavaRef<jobject>& context);
// Gets a global ref to the application context set with
// InitApplicationContext(). Ownership is retained by the function - the caller
// must NOT release it.
-jobject GetApplicationContext();
+const jobject GetApplicationContext();
+
+// Finds the class named |class_name| and returns it.
+// Use this method instead of invoking directly the JNI FindClass method (to
+// prevent leaking local references).
+// This method triggers a fatal assertion if the class could not be found.
+// Use HasClass if you need to check whether the class exists.
+ScopedJavaLocalRef<jclass> GetClass(JNIEnv* env, const char* class_name);
+
+// 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);
+
+// 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);
+
+// 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);
// 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
@@ -46,30 +78,36 @@ jmethodID GetMethodIDFromClassName(JNIEnv* env,
const char* method,
const char* jni_signature);
-// Get the method ID for a method. Will clear the pending Java
-// exception and return 0 if the method is not found.
-jmethodID GetMethodID(JNIEnv* env,
- jclass clazz,
- const char* const method,
- const char* const jni_signature);
-
-// Get the method ID for a class static method. Will clear the pending Java
-// exception and return 0 if the method is not found.
-jmethodID GetStaticMethodID(JNIEnv* env,
- jclass clazz,
- const char* const method,
- const char* const jni_signature);
-
-// Gets the field ID for a class field. Clears the pending Java exception and
-// returns NULL if the field is not found.
+// Gets the field ID for a class field.
+// This method triggers a fatal assertion if the field could not be found.
jfieldID GetFieldID(JNIEnv* env,
- jclass clazz,
- const char* field,
+ const JavaRef<jclass>& clazz,
+ const char* field_name,
const char* jni_signature);
-// Returns true if an exception is pending in the provided JNIEnv*. If an
-// exception is pending, this function prints and then clears it.
-bool CheckException(JNIEnv* env);
+// Returns true if |clazz| as a field with the given name and signature.
+// TODO(jcivelli): Determine whether we explicitly have to pass the environment.
+bool HasField(JNIEnv* env,
+ const JavaRef<jclass>& clazz,
+ const char* field_name,
+ const char* jni_signature);
+
+// Gets the field ID for a static class field.
+// This method triggers a fatal assertion if the field could not be found.
+jfieldID GetStaticFieldID(JNIEnv* env,
+ const JavaRef<jclass>& clazz,
+ const char* field_name,
+ const char* jni_signature);
+
+// Returns true if an exception is pending in the provided JNIEnv*.
+bool HasException(JNIEnv* env);
+
+// If an exception is pending in the provided JNIEnv*, this function clears it
+// and returns true.
+bool ClearException(JNIEnv* env);
+
+// This function will call CHECK() macro if there's any pending exception.
+void CheckException(JNIEnv* env);
} // namespace android
} // namespace base
« 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