| 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 |
| 20 JavaVM* g_jvm = NULL; | 22 JavaVM* g_jvm = NULL; |
| 21 // Leak the global app context, as it is used from a non-joinable worker thread | 23 // Leak the global app context, as it is used from a non-joinable worker thread |
| 22 // that may still be running at shutdown. There is no harm in doing this. | 24 // that may still be running at shutdown. There is no harm in doing this. |
| 23 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky | 25 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky |
| 24 g_application_context = LAZY_INSTANCE_INITIALIZER; | 26 g_application_context = LAZY_INSTANCE_INITIALIZER; |
| 25 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky | 27 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky |
| 26 g_class_loader = LAZY_INSTANCE_INITIALIZER; | 28 g_class_loader = LAZY_INSTANCE_INITIALIZER; |
| 27 jmethodID g_class_loader_load_class_method_id = 0; | 29 jmethodID g_class_loader_load_class_method_id = 0; |
| 28 | 30 |
| 29 std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) { | 31 std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 bytearray_output_stream_tostring))); | 72 bytearray_output_stream_tostring))); |
| 71 | 73 |
| 72 return ConvertJavaStringToUTF8(exception_string); | 74 return ConvertJavaStringToUTF8(exception_string); |
| 73 } | 75 } |
| 74 | 76 |
| 75 } // namespace | 77 } // namespace |
| 76 | 78 |
| 77 namespace base { | 79 namespace base { |
| 78 namespace android { | 80 namespace android { |
| 79 | 81 |
| 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 |
| 80 JNIEnv* AttachCurrentThread() { | 91 JNIEnv* AttachCurrentThread() { |
| 81 DCHECK(g_jvm); | 92 DCHECK(g_jvm); |
| 82 JNIEnv* env = NULL; | 93 JNIEnv* env = NULL; |
| 83 jint ret = g_jvm->AttachCurrentThread(&env, NULL); | 94 jint ret = g_jvm->AttachCurrentThread(&env, NULL); |
| 84 DCHECK_EQ(JNI_OK, ret); | 95 DCHECK_EQ(JNI_OK, ret); |
| 85 return env; | 96 return env; |
| 86 } | 97 } |
| 87 | 98 |
| 88 JNIEnv* AttachCurrentThreadWithName(const std::string& thread_name) { | 99 JNIEnv* AttachCurrentThreadWithName(const std::string& thread_name) { |
| 89 DCHECK(g_jvm); | 100 DCHECK(g_jvm); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 base::android::BuildInfo::GetInstance()->set_java_exception_info( | 275 base::android::BuildInfo::GetInstance()->set_java_exception_info( |
| 265 GetJavaExceptionInfo(env, java_throwable)); | 276 GetJavaExceptionInfo(env, java_throwable)); |
| 266 } | 277 } |
| 267 | 278 |
| 268 // Now, feel good about it and die. | 279 // Now, feel good about it and die. |
| 269 CHECK(false) << "Please include Java exception stack in crash report"; | 280 CHECK(false) << "Please include Java exception stack in crash report"; |
| 270 } | 281 } |
| 271 | 282 |
| 272 } // namespace android | 283 } // namespace android |
| 273 } // namespace base | 284 } // namespace base |
| OLD | NEW |