Commit 13eb3668 authored by Tobias Sargeant's avatar Tobias Sargeant Committed by Commit Bot

[weblayer] Enable Crashpad on Android

Enable Crashpad collection of minidumps on Android. Other platforms are
skipped because the concept of the user data directory is OS-specific.
On Android specifically crashes are written to
[app-data-dir]/cache/Crashpad.

Test: manual
Test: Check current crash count with:
Test: adb shell ls '/data/data/org.chromium.weblayer.shell/cache/Crashpad/pending/*.dmp' | wc -l
Test: load chrome://crash or chrome://inducebrowsercrashforrealz
Test: Check crash count has increased by 1
Change-Id: I9718754dc4218e7e2f2e7737de420db83d4de14b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1883653
Commit-Queue: Tobias Sargeant <tobiasjs@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711180}
parent 4bd75d99
......@@ -97,6 +97,8 @@ jumbo_static_library("weblayer_lib") {
"//base:base_static",
"//base/third_party/dynamic_annotations",
"//cc",
"//components/crash/content/app",
"//components/crash/content/browser",
"//components/safe_browsing",
"//components/safe_browsing/browser",
"//components/safe_browsing/db:database_manager",
......@@ -137,7 +139,15 @@ jumbo_static_library("weblayer_lib") {
]
if (is_android) {
deps += [ "//components/safe_browsing/android:remote_database_manager" ]
sources += [
"common/crash_reporter_client.cc",
"common/crash_reporter_client.h",
]
deps += [
"//components/crash/android:crashpad_main",
"//components/safe_browsing/android:remote_database_manager",
"//components/version_info/android:channel_getter",
]
}
if (enable_vulkan) {
......
......@@ -34,6 +34,7 @@
#include "ui/base/resource/resource_bundle_android.h"
#include "ui/base/ui_base_switches.h"
#include "weblayer/browser/android_descriptors.h"
#include "weblayer/common/crash_reporter_client.h"
#endif
#if defined(OS_WIN)
......@@ -146,6 +147,12 @@ void ContentMainDelegateImpl::PreSandboxStartup() {
#endif
InitializeResourceBundle();
#if defined(OS_ANDROID)
EnableCrashReporter(
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessType));
#endif
}
int ContentMainDelegateImpl::RunProcess(
......
include_rules = [
"+cc",
"+components/crash/content/browser",
"+components/embedder_support",
"+components/safe_browsing",
"+content/public",
......
......@@ -37,6 +37,7 @@
#if defined(OS_ANDROID)
#include "base/android/path_utils.h"
#include "components/crash/content/browser/crash_handler_host_linux.h"
#include "ui/base/resource/resource_bundle_android.h"
#include "weblayer/browser/android_descriptors.h"
#endif
......@@ -216,7 +217,12 @@ void ContentBrowserClientImpl::GetAdditionalMappedFilesForChildProcess(
fd = ui::GetLocalePackFd(&region);
mappings->ShareWithRegion(kWebLayerLocalePakDescriptor, fd, region);
#endif
int crash_signal_fd =
crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket();
if (crash_signal_fd >= 0)
mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd);
#endif // defined(OS_ANDROID)
}
#endif // defined(OS_LINUX) || defined(OS_ANDROID)
......
......@@ -49,8 +49,11 @@ android_library("java") {
":weblayer_resources",
"//base:base_java",
"//base:jni_java",
"//components/crash/android:handler_java",
"//components/crash/android:java",
"//components/embedder_support/android:application_java",
"//components/embedder_support/android:web_contents_delegate_java",
"//components/version_info/android:version_constants_java",
"//content/public/android:content_java",
"//third_party/android_deps:com_android_support_support_compat_java",
"//ui/android:ui_java",
......
include_rules = [
"+components/crash",
"+components/version_info",
"+content/app/resources",
"+content/public/common",
"+third_party/blink/public/strings/grit/blink_strings.h",
......
// Copyright 2019 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.
#include "weblayer/common/crash_reporter_client.h"
#include <stdint.h>
#include "base/android/java_exception_reporter.h"
#include "base/android/path_utils.h"
#include "base/base_paths_android.h"
#include "base/files/file_util.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "components/crash/content/app/crash_reporter_client.h"
#include "components/crash/content/app/crashpad.h"
#include "components/version_info/android/channel_getter.h"
#include "components/version_info/version_info.h"
#include "components/version_info/version_info_values.h"
#include "weblayer/common/weblayer_paths.h"
namespace weblayer {
namespace {
class CrashReporterClientImpl : public crash_reporter::CrashReporterClient {
public:
CrashReporterClientImpl() = default;
// crash_reporter::CrashReporterClient implementation.
bool IsRunningUnattended() override { return false; }
bool GetCollectStatsConsent() override { return false; }
void GetProductNameAndVersion(std::string* product_name,
std::string* version,
std::string* channel) override {
*version = PRODUCT_VERSION;
*product_name = "WebLayer";
*channel =
version_info::GetChannelString(version_info::android::GetChannel());
}
bool GetCrashDumpLocation(base::FilePath* crash_dir) override {
return base::PathService::Get(weblayer::DIR_CRASH_DUMPS, crash_dir);
}
void GetSanitizationInformation(const char* const** annotations_whitelist,
void** target_module,
bool* sanitize_stacks) override {
// TODO(tobiasjs) implement appropriate crash filtering.
*annotations_whitelist = nullptr;
*target_module = nullptr;
*sanitize_stacks = false;
}
static CrashReporterClientImpl* Get() {
static base::NoDestructor<CrashReporterClientImpl> crash_reporter_client;
return crash_reporter_client.get();
}
private:
DISALLOW_COPY_AND_ASSIGN(CrashReporterClientImpl);
};
} // namespace
void EnableCrashReporter(const std::string& process_type) {
static bool enabled = false;
DCHECK(!enabled) << "EnableCrashReporter called more than once";
crash_reporter::SetCrashReporterClient(CrashReporterClientImpl::Get());
crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
if (process_type.empty())
base::android::InitJavaExceptionReporter();
else
base::android::InitJavaExceptionReporterForChildProcess();
enabled = true;
}
} // namespace weblayer
// Copyright 2019 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.
#ifndef WEBLAYER_COMMON_CRASH_REPORTER_CLIENT_H_
#define WEBLAYER_COMMON_CRASH_REPORTER_CLIENT_H_
#include <string>
namespace weblayer {
// Enable the collection of crashes for this process (of type |process_type|)
// via crashpad. This will collect both native crashes and uncaught Java
// exceptions as minidumps plus associated metadata.
void EnableCrashReporter(const std::string& process_type);
} // namespace weblayer
#endif // WEBLAYER_COMMON_CRASH_REPORTER_CLIENT_H_
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