diff options
author | steveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-12 12:33:36 +0000 |
---|---|---|
committer | steveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-12 12:33:36 +0000 |
commit | acb386c7a5537edaa38dc5d1f7f28ee5b98b376d (patch) | |
tree | bdd59850c4384bc66064a9ee307ec912667dfdd2 /base/android | |
parent | a543728378cd5ebda1f6b77e4b1f39ba115b8ef6 (diff) | |
download | chromium_src-acb386c7a5537edaa38dc5d1f7f28ee5b98b376d.zip chromium_src-acb386c7a5537edaa38dc5d1f7f28ee5b98b376d.tar.gz chromium_src-acb386c7a5537edaa38dc5d1f7f28ee5b98b376d.tar.bz2 |
Clean up base::android::Init/GetApplicationContext()
- Modify InitApplicationContext() to take a ScopedJavaRef
- Clarify documentation
Review URL: http://codereview.chromium.org/8894002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114010 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/android')
-rw-r--r-- | base/android/jni_android.cc | 6 | ||||
-rw-r--r-- | base/android/jni_android.h | 14 |
2 files changed, 11 insertions, 9 deletions
diff --git a/base/android/jni_android.cc b/base/android/jni_android.cc index dca2ca4..a746fd4 100644 --- a/base/android/jni_android.cc +++ b/base/android/jni_android.cc @@ -6,7 +6,6 @@ #include <map> -#include "base/android/scoped_java_ref.h" #include "base/atomicops.h" #include "base/lazy_instance.h" #include "base/logging.h" @@ -55,7 +54,6 @@ namespace android { JNIEnv* AttachCurrentThread() { if (!g_jvm) return NULL; - JNIEnv* env = NULL; jint ret = g_jvm->AttachCurrentThread(&env, NULL); DCHECK_EQ(ret, JNI_OK); @@ -74,9 +72,9 @@ void InitVM(JavaVM* vm) { g_jvm = vm; } -void InitApplicationContext(jobject context) { +void InitApplicationContext(const JavaRef<jobject>& context) { DCHECK(!g_application_context); - g_application_context = context; + g_application_context = context.env()->NewGlobalRef(context.obj()); } jobject GetApplicationContext() { diff --git a/base/android/jni_android.h b/base/android/jni_android.h index 08e4b6d..a5571e0 100644 --- a/base/android/jni_android.h +++ b/base/android/jni_android.h @@ -8,6 +8,8 @@ #include <jni.h> #include <sys/types.h> +#include "base/android/scoped_java_ref.h" + namespace base { namespace android { @@ -21,13 +23,15 @@ void DetachFromVM(); // InitApplicationContext(). void InitVM(JavaVM* vm); -// Initializes the global application context object. The |context| should be -// the global reference of application context object. It is not necessarily -// called after InitVM(). +// 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(jobject context); +void InitApplicationContext(const JavaRef<jobject>& context); -// Returns the application context assigned by InitApplicationContext(). +// 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(); // Gets the method ID from the class name. Clears the pending Java exception |