From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Thu, 30 Apr 2020 10:08:06 -0700 Subject: crash: allow setting more options This allows the client of //components/crash to set upload url, rate-limiting, compression and global annotations. This should be upstreamed. diff --git a/components/crash/core/app/breakpad_linux.cc b/components/crash/core/app/breakpad_linux.cc index 6aa864db880408bf7021ac58673f4d8d489426b4..1fa85302da7a64abc42fd9558ddbcaf68b387517 100644 --- a/components/crash/core/app/breakpad_linux.cc +++ b/components/crash/core/app/breakpad_linux.cc @@ -113,6 +113,7 @@ void SetUploadURL(const std::string& url) { } #endif +bool g_is_node = false; bool g_is_crash_reporter_enabled = false; uint64_t g_process_start_time = 0; pid_t g_pid = 0; diff --git a/components/crash/core/app/crash_reporter_client.cc b/components/crash/core/app/crash_reporter_client.cc index 463f92a6e547006a46119f52203482dd6695a84a..34e6f087613d76947ae463fda2b107fad6ec14e9 100644 --- a/components/crash/core/app/crash_reporter_client.cc +++ b/components/crash/core/app/crash_reporter_client.cc @@ -145,6 +145,17 @@ bool CrashReporterClient::ReportingIsEnforcedByPolicy(bool* breakpad_enabled) { return false; } +bool CrashReporterClient::GetShouldRateLimit() { + return true; +} + +bool CrashReporterClient::GetShouldCompressUploads() { + return true; +} + +void CrashReporterClient::GetProcessSimpleAnnotations(std::map* annotations) { +} + #if BUILDFLAG(IS_ANDROID) unsigned int CrashReporterClient::GetCrashDumpPercentage() { return 100; diff --git a/components/crash/core/app/crash_reporter_client.h b/components/crash/core/app/crash_reporter_client.h index 2532e99f00b39777cd9640c76704f7430d39502e..323e039e4591a4099b187f7a0097b4ee8be11a9f 100644 --- a/components/crash/core/app/crash_reporter_client.h +++ b/components/crash/core/app/crash_reporter_client.h @@ -5,6 +5,7 @@ #ifndef COMPONENTS_CRASH_CORE_APP_CRASH_REPORTER_CLIENT_H_ #define COMPONENTS_CRASH_CORE_APP_CRASH_REPORTER_CLIENT_H_ +#include #include #include "build/build_config.h" @@ -151,6 +152,19 @@ class CrashReporterClient { // that case, |breakpad_enabled| is set to the value enforced by policies. virtual bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled); + // Returns true if crash uploads should be rate limited. If false, no + // throttling will be applied for uploads. + virtual bool GetShouldRateLimit(); + + // Returns true if crash uploads should be compressed with gzip. If false, + // reports will be uploaded uncompressed. + virtual bool GetShouldCompressUploads(); + + // Allows the client to add or edit global annotations passed to the crashpad + // handler. + virtual void GetProcessSimpleAnnotations( + std::map* annotations); + #if BUILDFLAG(IS_ANDROID) // Used by WebView to sample crashes without generating the unwanted dumps. If // the returned value is less than 100, crash dumping will be sampled to that diff --git a/components/crash/core/app/crashpad_linux.cc b/components/crash/core/app/crashpad_linux.cc index 7159bea91a25700f0cb36c48cab62fe2d616b3bd..9bcc5ae7e870c27c3533534c06daa890de5a4816 100644 --- a/components/crash/core/app/crashpad_linux.cc +++ b/components/crash/core/app/crashpad_linux.cc @@ -170,6 +170,7 @@ bool PlatformCrashpadInitialization( // where crash_reporter provides it's own values for lsb-release. annotations["lsb-release"] = base::GetLinuxDistro(); #endif + crash_reporter_client->GetProcessSimpleAnnotations(&annotations); std::vector arguments; if (crash_reporter_client->ShouldMonitorCrashHandlerExpensively()) { @@ -191,6 +192,13 @@ bool PlatformCrashpadInitialization( } #endif + if (!crash_reporter_client->GetShouldRateLimit()) { + arguments.push_back("--no-rate-limit"); + } + if (!crash_reporter_client->GetShouldCompressUploads()) { + arguments.push_back("--no-upload-gzip"); + } + CHECK(client.StartHandler(handler_path, *database_path, metrics_path, url, annotations, arguments, false, false)); } else { diff --git a/components/crash/core/app/crashpad_mac.mm b/components/crash/core/app/crashpad_mac.mm index dc041c43371fd58e3121ef6bc423aadb644bb8d0..a1fa566775724b4a1662a939fda3f0a59bf46b96 100644 --- a/components/crash/core/app/crashpad_mac.mm +++ b/components/crash/core/app/crashpad_mac.mm @@ -85,6 +85,8 @@ } // @autoreleasepool return process_annotations; }(); + CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); + crash_reporter_client->GetProcessSimpleAnnotations(&annotations); return annotations; } @@ -155,6 +157,13 @@ bool PlatformCrashpadInitialization( std::vector arguments; + if (!crash_reporter_client->GetShouldRateLimit()) { + arguments.push_back("--no-rate-limit"); + } + if (!crash_reporter_client->GetShouldCompressUploads()) { + arguments.push_back("--no-upload-gzip"); + } + if (crash_reporter_client->ShouldMonitorCrashHandlerExpensively()) { arguments.push_back("--monitor-self"); } diff --git a/components/crash/core/app/crashpad_win.cc b/components/crash/core/app/crashpad_win.cc index ad401a7711ceff58abacb99a03fda258fccd12a0..de04f4df602e3a0b20af045111faf8a7bf8e9e28 100644 --- a/components/crash/core/app/crashpad_win.cc +++ b/components/crash/core/app/crashpad_win.cc @@ -91,6 +91,7 @@ bool PlatformCrashpadInitialization( std::map process_annotations; GetPlatformCrashpadAnnotations(&process_annotations); + crash_reporter_client->GetProcessSimpleAnnotations(&process_annotations); std::string url = crash_reporter_client->GetUploadUrl(); @@ -129,6 +130,13 @@ bool PlatformCrashpadInitialization( std::vector arguments(start_arguments); + if (!crash_reporter_client->GetShouldRateLimit()) { + arguments.push_back("--no-rate-limit"); + } + if (!crash_reporter_client->GetShouldCompressUploads()) { + arguments.push_back("--no-upload-gzip"); + } + if (crash_reporter_client->ShouldMonitorCrashHandlerExpensively()) { arguments.push_back("--monitor-self"); for (const std::string& start_argument : start_arguments) {