diff options
-rw-r--r-- | base/android/jni_android.cc | 6 | ||||
-rw-r--r-- | base/android/jni_android.h | 3 | ||||
-rw-r--r-- | content/app/android/content_main.cc | 2 | ||||
-rw-r--r-- | content/shell/android/browsertests_apk/content_browser_tests_android.cc | 2 | ||||
-rw-r--r-- | mojo/shell/android/mojo_main.cc | 2 | ||||
-rw-r--r-- | remoting/client/jni/chromoting_jni_runtime.cc | 2 | ||||
-rw-r--r-- | testing/android/native_test_launcher.cc | 2 |
7 files changed, 12 insertions, 7 deletions
diff --git a/base/android/jni_android.cc b/base/android/jni_android.cc index 6dc6a8d..59f25e2 100644 --- a/base/android/jni_android.cc +++ b/base/android/jni_android.cc @@ -97,7 +97,11 @@ bool IsVMInitialized() { return g_jvm != NULL; } -void InitApplicationContext(const JavaRef<jobject>& context) { +void InitApplicationContext(JNIEnv* env, const JavaRef<jobject>& context) { + if (env->IsSameObject(g_application_context.Get().obj(), context.obj())) { + // It's safe to set the context more than once if it's the same context. + return; + } DCHECK(g_application_context.Get().is_null()); g_application_context.Get().Reset(context); } diff --git a/base/android/jni_android.h b/base/android/jni_android.h index 81ce3fd..7a00632 100644 --- a/base/android/jni_android.h +++ b/base/android/jni_android.h @@ -41,7 +41,8 @@ BASE_EXPORT bool IsVMInitialized(); // 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. -BASE_EXPORT void InitApplicationContext(const JavaRef<jobject>& context); +BASE_EXPORT void InitApplicationContext(JNIEnv* env, + const JavaRef<jobject>& context); // Gets a global ref to the application context set with // InitApplicationContext(). Ownership is retained by the function - the caller diff --git a/content/app/android/content_main.cc b/content/app/android/content_main.cc index bfc372f..00074b8 100644 --- a/content/app/android/content_main.cc +++ b/content/app/android/content_main.cc @@ -32,7 +32,7 @@ namespace content { static void InitApplicationContext(JNIEnv* env, jclass clazz, jobject context) { base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); - base::android::InitApplicationContext(scoped_context); + base::android::InitApplicationContext(env, scoped_context); } static jint Start(JNIEnv* env, jclass clazz) { diff --git a/content/shell/android/browsertests_apk/content_browser_tests_android.cc b/content/shell/android/browsertests_apk/content_browser_tests_android.cc index b9792dc..0acff50 100644 --- a/content/shell/android/browsertests_apk/content_browser_tests_android.cc +++ b/content/shell/android/browsertests_apk/content_browser_tests_android.cc @@ -61,7 +61,7 @@ static void RunTests(JNIEnv* env, // Set the application context in base. base::android::ScopedJavaLocalRef<jobject> scoped_context( env, env->NewLocalRef(app_context)); - base::android::InitApplicationContext(scoped_context); + base::android::InitApplicationContext(env, scoped_context); base::android::RegisterJni(env); std::vector<std::string> args; diff --git a/mojo/shell/android/mojo_main.cc b/mojo/shell/android/mojo_main.cc index 214c553..2fb2597 100644 --- a/mojo/shell/android/mojo_main.cc +++ b/mojo/shell/android/mojo_main.cc @@ -66,7 +66,7 @@ void StartOnShellThread(ShellInit* init) { static void Init(JNIEnv* env, jclass clazz, jobject context) { base::android::ScopedJavaLocalRef<jobject> scoped_context(env, context); - base::android::InitApplicationContext(scoped_context); + base::android::InitApplicationContext(env, scoped_context); if (g_at_exit) return; diff --git a/remoting/client/jni/chromoting_jni_runtime.cc b/remoting/client/jni/chromoting_jni_runtime.cc index cbc7a35..9e9c953 100644 --- a/remoting/client/jni/chromoting_jni_runtime.cc +++ b/remoting/client/jni/chromoting_jni_runtime.cc @@ -40,7 +40,7 @@ bool RegisterJni(JNIEnv* env) { static void LoadNative(JNIEnv* env, jclass clazz, jobject context) { base::android::ScopedJavaLocalRef<jobject> context_activity(env, context); - base::android::InitApplicationContext(context_activity); + base::android::InitApplicationContext(env, context_activity); // The google_apis functions check the command-line arguments to make sure no // runtime API keys have been specified by the environment. Unfortunately, we diff --git a/testing/android/native_test_launcher.cc b/testing/android/native_test_launcher.cc index 300efc9..50b213e 100644 --- a/testing/android/native_test_launcher.cc +++ b/testing/android/native_test_launcher.cc @@ -128,7 +128,7 @@ static void RunTests(JNIEnv* env, // Set the application context in base. base::android::ScopedJavaLocalRef<jobject> scoped_context( env, env->NewLocalRef(app_context)); - base::android::InitApplicationContext(scoped_context); + base::android::InitApplicationContext(env, scoped_context); base::android::RegisterJni(env); std::vector<std::string> args; |