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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « base/android/jni_android.h ('k') | base/barrier_closure.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 10 matching lines...) Expand all
21 21
22 JavaVM* g_jvm = NULL; 22 JavaVM* g_jvm = NULL;
23 // 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
24 // 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.
25 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky 25 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky
26 g_application_context = LAZY_INSTANCE_INITIALIZER; 26 g_application_context = LAZY_INSTANCE_INITIALIZER;
27 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky 27 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >::Leaky
28 g_class_loader = LAZY_INSTANCE_INITIALIZER; 28 g_class_loader = LAZY_INSTANCE_INITIALIZER;
29 jmethodID g_class_loader_load_class_method_id = 0; 29 jmethodID g_class_loader_load_class_method_id = 0;
30 30
31 std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) {
32 ScopedJavaLocalRef<jclass> throwable_clazz =
33 GetClass(env, "java/lang/Throwable");
34 jmethodID throwable_printstacktrace =
35 MethodID::Get<MethodID::TYPE_INSTANCE>(
36 env, throwable_clazz.obj(), "printStackTrace",
37 "(Ljava/io/PrintStream;)V");
38
39 // Create an instance of ByteArrayOutputStream.
40 ScopedJavaLocalRef<jclass> bytearray_output_stream_clazz =
41 GetClass(env, "java/io/ByteArrayOutputStream");
42 jmethodID bytearray_output_stream_constructor =
43 MethodID::Get<MethodID::TYPE_INSTANCE>(
44 env, bytearray_output_stream_clazz.obj(), "<init>", "()V");
45 jmethodID bytearray_output_stream_tostring =
46 MethodID::Get<MethodID::TYPE_INSTANCE>(
47 env, bytearray_output_stream_clazz.obj(), "toString",
48 "()Ljava/lang/String;");
49 ScopedJavaLocalRef<jobject> bytearray_output_stream(env,
50 env->NewObject(bytearray_output_stream_clazz.obj(),
51 bytearray_output_stream_constructor));
52
53 // Create an instance of PrintStream.
54 ScopedJavaLocalRef<jclass> printstream_clazz =
55 GetClass(env, "java/io/PrintStream");
56 jmethodID printstream_constructor =
57 MethodID::Get<MethodID::TYPE_INSTANCE>(
58 env, printstream_clazz.obj(), "<init>",
59 "(Ljava/io/OutputStream;)V");
60 ScopedJavaLocalRef<jobject> printstream(env,
61 env->NewObject(printstream_clazz.obj(), printstream_constructor,
62 bytearray_output_stream.obj()));
63
64 // Call Throwable.printStackTrace(PrintStream)
65 env->CallVoidMethod(java_throwable, throwable_printstacktrace,
66 printstream.obj());
67
68 // Call ByteArrayOutputStream.toString()
69 ScopedJavaLocalRef<jstring> exception_string(
70 env, static_cast<jstring>(
71 env->CallObjectMethod(bytearray_output_stream.obj(),
72 bytearray_output_stream_tostring)));
73
74 return ConvertJavaStringToUTF8(exception_string);
75 }
76
77 } // namespace 31 } // namespace
78 32
79 namespace base { 33 namespace base {
80 namespace android { 34 namespace android {
81 35
82 bool IsManualJniRegistrationDisabled() { 36 bool IsManualJniRegistrationDisabled() {
83 return g_disable_manual_jni_registration; 37 return g_disable_manual_jni_registration;
84 } 38 }
85 39
86 void DisableManualJniRegistration() { 40 void DisableManualJniRegistration() {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 234
281 // Exception has been found, might as well tell breakpad about it. 235 // Exception has been found, might as well tell breakpad about it.
282 jthrowable java_throwable = env->ExceptionOccurred(); 236 jthrowable java_throwable = env->ExceptionOccurred();
283 if (java_throwable) { 237 if (java_throwable) {
284 // Clear the pending exception, since a local reference is now held. 238 // Clear the pending exception, since a local reference is now held.
285 env->ExceptionDescribe(); 239 env->ExceptionDescribe();
286 env->ExceptionClear(); 240 env->ExceptionClear();
287 241
288 // Set the exception_string in BuildInfo so that breakpad can read it. 242 // Set the exception_string in BuildInfo so that breakpad can read it.
289 // RVO should avoid any extra copies of the exception string. 243 // RVO should avoid any extra copies of the exception string.
290 base::android::BuildInfo::GetInstance()->set_java_exception_info( 244 base::android::BuildInfo::GetInstance()->SetJavaExceptionInfo(
291 GetJavaExceptionInfo(env, java_throwable)); 245 GetJavaExceptionInfo(env, java_throwable));
292 } 246 }
293 247
294 // Now, feel good about it and die. 248 // Now, feel good about it and die.
295 CHECK(false) << "Please include Java exception stack in crash report"; 249 CHECK(false) << "Please include Java exception stack in crash report";
296 } 250 }
297 251
252 std::string GetJavaExceptionInfo(JNIEnv* env, jthrowable java_throwable) {
253 ScopedJavaLocalRef<jclass> throwable_clazz =
254 GetClass(env, "java/lang/Throwable");
255 jmethodID throwable_printstacktrace =
256 MethodID::Get<MethodID::TYPE_INSTANCE>(
257 env, throwable_clazz.obj(), "printStackTrace",
258 "(Ljava/io/PrintStream;)V");
259
260 // Create an instance of ByteArrayOutputStream.
261 ScopedJavaLocalRef<jclass> bytearray_output_stream_clazz =
262 GetClass(env, "java/io/ByteArrayOutputStream");
263 jmethodID bytearray_output_stream_constructor =
264 MethodID::Get<MethodID::TYPE_INSTANCE>(
265 env, bytearray_output_stream_clazz.obj(), "<init>", "()V");
266 jmethodID bytearray_output_stream_tostring =
267 MethodID::Get<MethodID::TYPE_INSTANCE>(
268 env, bytearray_output_stream_clazz.obj(), "toString",
269 "()Ljava/lang/String;");
270 ScopedJavaLocalRef<jobject> bytearray_output_stream(env,
271 env->NewObject(bytearray_output_stream_clazz.obj(),
272 bytearray_output_stream_constructor));
273
274 // Create an instance of PrintStream.
275 ScopedJavaLocalRef<jclass> printstream_clazz =
276 GetClass(env, "java/io/PrintStream");
277 jmethodID printstream_constructor =
278 MethodID::Get<MethodID::TYPE_INSTANCE>(
279 env, printstream_clazz.obj(), "<init>",
280 "(Ljava/io/OutputStream;)V");
281 ScopedJavaLocalRef<jobject> printstream(env,
282 env->NewObject(printstream_clazz.obj(), printstream_constructor,
283 bytearray_output_stream.obj()));
284
285 // Call Throwable.printStackTrace(PrintStream)
286 env->CallVoidMethod(java_throwable, throwable_printstacktrace,
287 printstream.obj());
288
289 // Call ByteArrayOutputStream.toString()
290 ScopedJavaLocalRef<jstring> exception_string(
291 env, static_cast<jstring>(
292 env->CallObjectMethod(bytearray_output_stream.obj(),
293 bytearray_output_stream_tostring)));
294
295 return ConvertJavaStringToUTF8(exception_string);
296 }
297
298
298 } // namespace android 299 } // namespace android
299 } // namespace base 300 } // namespace base
OLDNEW
« 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