Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors |
boliu | 9b51b51 | 2017-02-03 15:35:05 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_ANDROID_JAVA_EXCEPTION_REPORTER_H_ |
| 6 | #define BASE_ANDROID_JAVA_EXCEPTION_REPORTER_H_ |
| 7 | |
| 8 | #include <jni.h> |
| 9 | |
Tobias Sargeant | 5e78771d | 2019-09-21 13:49:23 | [diff] [blame] | 10 | #include "base/android/scoped_java_ref.h" |
boliu | 9b51b51 | 2017-02-03 15:35:05 | [diff] [blame] | 11 | #include "base/base_export.h" |
Avi Drissman | 63e1f99 | 2023-01-13 18:54:43 | [diff] [blame] | 12 | #include "base/functional/callback_forward.h" |
boliu | 9b51b51 | 2017-02-03 15:35:05 | [diff] [blame] | 13 | |
| 14 | namespace base { |
| 15 | namespace android { |
| 16 | |
Andrew Grieve | 6230a51 | 2023-12-11 16:47:21 | [diff] [blame^] | 17 | using JavaExceptionCallback = void (*)(const char* exception); |
| 18 | |
boliu | 9b51b51 | 2017-02-03 15:35:05 | [diff] [blame] | 19 | // Install the exception handler. This should only be called once per process. |
| 20 | BASE_EXPORT void InitJavaExceptionReporter(); |
| 21 | |
boliu | 328eda13 | 2017-02-10 16:39:57 | [diff] [blame] | 22 | // Same as above except the handler ensures child process exists immediately |
| 23 | // after an unhandled exception. This is used for child processes because |
| 24 | // DumpWithoutCrashing does not work for child processes on Android. |
| 25 | BASE_EXPORT void InitJavaExceptionReporterForChildProcess(); |
| 26 | |
Joshua Peraza | 7814da2 | 2018-07-10 21:37:50 | [diff] [blame] | 27 | // Sets a callback to be called with the contents of a Java exception, which may |
| 28 | // be nullptr. |
Andrew Grieve | 6230a51 | 2023-12-11 16:47:21 | [diff] [blame^] | 29 | BASE_EXPORT void SetJavaExceptionCallback(JavaExceptionCallback callback); |
| 30 | |
| 31 | // Returns the value last passed to SetJavaException(), or nullptr if it has |
| 32 | // not been called. |
| 33 | BASE_EXPORT JavaExceptionCallback GetJavaExceptionCallback(); |
Joshua Peraza | 7814da2 | 2018-07-10 21:37:50 | [diff] [blame] | 34 | |
| 35 | // Calls the Java exception callback, if any, with exception. |
| 36 | void SetJavaException(const char* exception); |
| 37 | |
Tobias Sargeant | 5e78771d | 2019-09-21 13:49:23 | [diff] [blame] | 38 | // Sets a filter that determines whether a java exception should cause a crash |
| 39 | // report. |java_exception_filter| should return true if a crash report should |
| 40 | // be generated. |
Tobias Sargeant | e3608f8 | 2019-09-30 14:10:32 | [diff] [blame] | 41 | BASE_EXPORT void SetJavaExceptionFilter( |
Tobias Sargeant | 5e78771d | 2019-09-21 13:49:23 | [diff] [blame] | 42 | base::RepeatingCallback<bool(const JavaRef<jthrowable>&)> |
| 43 | java_exception_filter); |
| 44 | |
boliu | 9b51b51 | 2017-02-03 15:35:05 | [diff] [blame] | 45 | } // namespace android |
| 46 | } // namespace base |
| 47 | |
| 48 | #endif // BASE_ANDROID_JAVA_EXCEPTION_REPORTER_H_ |