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

Unified Diff: base/android/jni_android.cc

Issue 1141793003: Update from https://crrev.com/329939 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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 | « base/android/jni_android.h ('k') | base/barrier_closure.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/jni_android.cc
diff --git a/base/android/jni_android.cc b/base/android/jni_android.cc
index 1b715dc7d544955ed5bc316d8808b6f35cd141fe..5416be32c2b1f430ed6cd531ce46d8cc438063a7 100644
--- a/base/android/jni_android.cc
+++ b/base/android/jni_android.cc
@@ -28,52 +28,6 @@ base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky
g_class_loader = LAZY_INSTANCE_INITIALIZER;
jmethodID g_class_loader_load_class_method_id = 0;
-std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) {
- ScopedJavaLocalRef<jclass> throwable_clazz =
- GetClass(env, "java/lang/Throwable");
- jmethodID throwable_printstacktrace =
- MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, throwable_clazz.obj(), "printStackTrace",
- "(Ljava/io/PrintStream;)V");
-
- // Create an instance of ByteArrayOutputStream.
- ScopedJavaLocalRef<jclass> bytearray_output_stream_clazz =
- GetClass(env, "java/io/ByteArrayOutputStream");
- jmethodID bytearray_output_stream_constructor =
- MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, bytearray_output_stream_clazz.obj(), "<init>", "()V");
- jmethodID bytearray_output_stream_tostring =
- MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, bytearray_output_stream_clazz.obj(), "toString",
- "()Ljava/lang/String;");
- ScopedJavaLocalRef<jobject> bytearray_output_stream(env,
- env->NewObject(bytearray_output_stream_clazz.obj(),
- bytearray_output_stream_constructor));
-
- // Create an instance of PrintStream.
- ScopedJavaLocalRef<jclass> printstream_clazz =
- GetClass(env, "java/io/PrintStream");
- jmethodID printstream_constructor =
- MethodID::Get<MethodID::TYPE_INSTANCE>(
- env, printstream_clazz.obj(), "<init>",
- "(Ljava/io/OutputStream;)V");
- ScopedJavaLocalRef<jobject> printstream(env,
- env->NewObject(printstream_clazz.obj(), printstream_constructor,
- bytearray_output_stream.obj()));
-
- // Call Throwable.printStackTrace(PrintStream)
- env->CallVoidMethod(java_throwable, throwable_printstacktrace,
- printstream.obj());
-
- // Call ByteArrayOutputStream.toString()
- ScopedJavaLocalRef<jstring> exception_string(
- env, static_cast<jstring>(
- env->CallObjectMethod(bytearray_output_stream.obj(),
- bytearray_output_stream_tostring)));
-
- return ConvertJavaStringToUTF8(exception_string);
-}
-
} // namespace
namespace base {
@@ -287,7 +241,7 @@ void CheckException(JNIEnv* env) {
// Set the exception_string in BuildInfo so that breakpad can read it.
// RVO should avoid any extra copies of the exception string.
- base::android::BuildInfo::GetInstance()->set_java_exception_info(
+ base::android::BuildInfo::GetInstance()->SetJavaExceptionInfo(
GetJavaExceptionInfo(env, java_throwable));
}
@@ -295,5 +249,52 @@ void CheckException(JNIEnv* env) {
CHECK(false) << "Please include Java exception stack in crash report";
}
+std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) {
+ ScopedJavaLocalRef<jclass> throwable_clazz =
+ GetClass(env, "java/lang/Throwable");
+ jmethodID throwable_printstacktrace =
+ MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, throwable_clazz.obj(), "printStackTrace",
+ "(Ljava/io/PrintStream;)V");
+
+ // Create an instance of ByteArrayOutputStream.
+ ScopedJavaLocalRef<jclass> bytearray_output_stream_clazz =
+ GetClass(env, "java/io/ByteArrayOutputStream");
+ jmethodID bytearray_output_stream_constructor =
+ MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, bytearray_output_stream_clazz.obj(), "<init>", "()V");
+ jmethodID bytearray_output_stream_tostring =
+ MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, bytearray_output_stream_clazz.obj(), "toString",
+ "()Ljava/lang/String;");
+ ScopedJavaLocalRef<jobject> bytearray_output_stream(env,
+ env->NewObject(bytearray_output_stream_clazz.obj(),
+ bytearray_output_stream_constructor));
+
+ // Create an instance of PrintStream.
+ ScopedJavaLocalRef<jclass> printstream_clazz =
+ GetClass(env, "java/io/PrintStream");
+ jmethodID printstream_constructor =
+ MethodID::Get<MethodID::TYPE_INSTANCE>(
+ env, printstream_clazz.obj(), "<init>",
+ "(Ljava/io/OutputStream;)V");
+ ScopedJavaLocalRef<jobject> printstream(env,
+ env->NewObject(printstream_clazz.obj(), printstream_constructor,
+ bytearray_output_stream.obj()));
+
+ // Call Throwable.printStackTrace(PrintStream)
+ env->CallVoidMethod(java_throwable, throwable_printstacktrace,
+ printstream.obj());
+
+ // Call ByteArrayOutputStream.toString()
+ ScopedJavaLocalRef<jstring> exception_string(
+ env, static_cast<jstring>(
+ env->CallObjectMethod(bytearray_output_stream.obj(),
+ bytearray_output_stream_tostring)));
+
+ return ConvertJavaStringToUTF8(exception_string);
+}
+
+
} // namespace android
} // namespace base
« no previous file with comments | « base/android/jni_android.h ('k') | base/barrier_closure.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698