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/crash_reporter_client.cc b/components/crash/core/app/crash_reporter_client.cc index b6a2910848c66489e70acdce6e09237bf6188f94..744cca2d1b8856719b9ae5aed6c443e8752da75e 100644 --- a/components/crash/core/app/crash_reporter_client.cc +++ b/components/crash/core/app/crash_reporter_client.cc @@ -119,6 +119,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 7c890b331be4aaaf20c7efe8a4bcc2f6e9012b7a..c573524d05c07ec67d35046bc8548cc1dfdd0df3 100644 --- a/components/crash/core/app/crash_reporter_client.h +++ b/components/crash/core/app/crash_reporter_client.h @@ -7,6 +7,7 @@ #include +#include #include #include "build/build_config.h" @@ -141,6 +142,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 aff834c0a93716f769c24bcea7d9f6ed15761040..c29311266678522cfb992cc2b3fa0a0158731a36 100644 --- a/components/crash/core/app/crashpad_linux.cc +++ b/components/crash/core/app/crashpad_linux.cc @@ -230,6 +230,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()) { @@ -251,6 +252,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 42fe73aefe44f218d6a5e8cb1550ff48859c4b70..a1235f0c7ad44ae9c9fdc805af5b9dc5669f5aad 100644 --- a/components/crash/core/app/crashpad_mac.mm +++ b/components/crash/core/app/crashpad_mac.mm @@ -86,6 +86,8 @@ } // @autoreleasepool return process_annotations; }(); + CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); + crash_reporter_client->GetProcessSimpleAnnotations(&annotations); return annotations; } @@ -156,6 +158,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 0e00d26f79231a01e88981b30ff950e427cd31f4..70f014c75031f9529501e102f97e0e1adadb8ffb 100644 --- a/components/crash/core/app/crashpad_win.cc +++ b/components/crash/core/app/crashpad_win.cc @@ -92,6 +92,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) {