| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/android/jni_android.h" | 5 #include "base/android/jni_android.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 11 #include "base/android/jni_utils.h" | 11 #include "base/android/jni_utils.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 using base::android::GetClass; | 16 using base::android::GetClass; |
| 17 using base::android::MethodID; | 17 using base::android::MethodID; |
| 18 using base::android::ScopedJavaLocalRef; | 18 using base::android::ScopedJavaLocalRef; |
| 19 | 19 |
| 20 bool g_disable_manual_jni_registration = false; | |
| 21 | |
| 22 JavaVM* g_jvm = NULL; | 20 JavaVM* g_jvm = NULL; |
| 23 // Leak the global app context, as it is used from a non-joinable worker thread | 21 // Leak the global app context, as it is used from a non-joinable worker thread |
| 24 // that may still be running at shutdown. There is no harm in doing this. | 22 // that may still be running at shutdown. There is no harm in doing this. |
| 25 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky | 23 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky |
| 26 g_application_context = LAZY_INSTANCE_INITIALIZER; | 24 g_application_context = LAZY_INSTANCE_INITIALIZER; |
| 27 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky | 25 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky |
| 28 g_class_loader = LAZY_INSTANCE_INITIALIZER; | 26 g_class_loader = LAZY_INSTANCE_INITIALIZER; |
| 29 jmethodID g_class_loader_load_class_method_id = 0; | 27 jmethodID g_class_loader_load_class_method_id = 0; |
| 30 | 28 |
| 31 std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) { | 29 std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 bytearray_output_stream_tostring))); | 70 bytearray_output_stream_tostring))); |
| 73 | 71 |
| 74 return ConvertJavaStringToUTF8(exception_string); | 72 return ConvertJavaStringToUTF8(exception_string); |
| 75 } | 73 } |
| 76 | 74 |
| 77 } // namespace | 75 } // namespace |
| 78 | 76 |
| 79 namespace base { | 77 namespace base { |
| 80 namespace android { | 78 namespace android { |
| 81 | 79 |
| 82 bool IsManualJniRegistrationDisabled() { | |
| 83 return g_disable_manual_jni_registration; | |
| 84 } | |
| 85 | |
| 86 void DisableManualJniRegistration() { | |
| 87 DCHECK(!g_disable_manual_jni_registration); | |
| 88 g_disable_manual_jni_registration = true; | |
| 89 } | |
| 90 | |
| 91 JNIEnv* AttachCurrentThread() { | 80 JNIEnv* AttachCurrentThread() { |
| 92 DCHECK(g_jvm); | 81 DCHECK(g_jvm); |
| 93 JNIEnv* env = NULL; | 82 JNIEnv* env = NULL; |
| 94 jint ret = g_jvm->AttachCurrentThread(&env, NULL); | 83 jint ret = g_jvm->AttachCurrentThread(&env, NULL); |
| 95 DCHECK_EQ(JNI_OK, ret); | 84 DCHECK_EQ(JNI_OK, ret); |
| 96 return env; | 85 return env; |
| 97 } | 86 } |
| 98 | 87 |
| 99 JNIEnv* AttachCurrentThreadWithName(const std::string& thread_name) { | 88 JNIEnv* AttachCurrentThreadWithName(const std::string& thread_name) { |
| 100 DCHECK(g_jvm); | 89 DCHECK(g_jvm); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 base::android::BuildInfo::GetInstance()->set_java_exception_info( | 264 base::android::BuildInfo::GetInstance()->set_java_exception_info( |
| 276 GetJavaExceptionInfo(env, java_throwable)); | 265 GetJavaExceptionInfo(env, java_throwable)); |
| 277 } | 266 } |
| 278 | 267 |
| 279 // Now, feel good about it and die. | 268 // Now, feel good about it and die. |
| 280 CHECK(false) << "Please include Java exception stack in crash report"; | 269 CHECK(false) << "Please include Java exception stack in crash report"; |
| 281 } | 270 } |
| 282 | 271 |
| 283 } // namespace android | 272 } // namespace android |
| 284 } // namespace base | 273 } // namespace base |
| OLD | NEW |