Commit 1782edbe authored by Joshua Peraza's avatar Joshua Peraza Committed by Commit Bot

android: Add ChildProcessCrashObserver.java

ChildProcessCrashObserver.java serves a similar purpose as
CrashDumpManager.java did (which it will replace), except without the
need (or ability) to check for a minidump on the filesystem. Instead of
a minidump path, the process ID of the crashed child is passed to the
callback which it can use to identify the correct crash dump.

Bug: crashpad:30
Change-Id: I718e653acfa35b14ebaa17d0e8c76804f9856dfb
Reviewed-on: https://chromium-review.googlesource.com/1150202Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577935}
parent f2cc21c1
......@@ -5,7 +5,8 @@
import("//build/config/android/rules.gni")
_jni_sources =
[ "java/src/org/chromium/components/crash/browser/CrashDumpManager.java" ]
[ "java/src/org/chromium/components/crash/browser/ChildProcessCrashObserver.java",
"java/src/org/chromium/components/crash/browser/CrashDumpManager.java" ]
generate_jni("jni_headers") {
sources = _jni_sources
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.components.crash.browser;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
/**
* A Java-side bridge for notifying an observer when a child process has crashed.
*
* Crashpad writes a minidump for a child process in the time between the child receives a crash
* signal and when it exits. After the child process exits, Crashpad should have completed writing
* a minidump to its CrashReportDatabase and this class's childCrashed() is called, executing any
* registered callback.
*
* It is expected that the callback will be used to handle the newly created dump by, e.g. attaching
* a logcat and scheduling it for upload.
*/
public class ChildProcessCrashObserver {
private static final String TAG = "ChildCrashObserver";
/**
* An interface for registering a callback to be executed when a child process crashes.
*/
public interface ChildCrashedCallback { public void childCrashed(int pid); }
/**
* The globally registered callback for responding to child process crashes, or null if no
* callback has been registered yet.
*/
private static ChildCrashedCallback sCallback;
/**
* Registers a callback for responding to child process crashes. May be called at most once, and
* only on the UI thread.
*
* @param callback The callback to trigger when a child process has exited due to a crash.
*/
public static void registerCrashCallback(ChildCrashedCallback callback) {
ThreadUtils.assertOnUiThread();
assert sCallback == null;
sCallback = callback;
}
/**
* Notifies any registered observer that a child process has exited due to an apparent crash.
*/
@CalledByNative
public static void childCrashed(int pid) {
if (sCallback == null) {
Log.w(TAG, "Ignoring crash observed before a callback was registered...");
return;
}
sCallback.childCrashed(pid);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment