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 d4d3555891b19d61676465c856055fb04e0168bc..3228888f5449df723f4385a0f2c9b456caa472f0 100644 --- a/components/crash/core/app/crashpad_linux.cc +++ b/components/crash/core/app/crashpad_linux.cc @@ -219,6 +219,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()) { @@ -240,6 +241,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, attachments)); diff --git a/components/crash/core/app/crashpad_mac.mm b/components/crash/core/app/crashpad_mac.mm index 3b131e1fc804a55c80b3b2704686270211fcf9fb..f14ab66f240a236bd90ff4240089a0036ce7d460 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; } @@ -159,6 +161,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 a7af39181e259b4c793fa9a39cb95e4f86ac47d1..6101018813315074a1e06bea318ecf3f91188415 100644 --- a/components/crash/core/app/crashpad_win.cc +++ b/components/crash/core/app/crashpad_win.cc @@ -94,6 +94,7 @@ bool PlatformCrashpadInitialization( std::map process_annotations; GetPlatformCrashpadAnnotations(&process_annotations); + crash_reporter_client->GetProcessSimpleAnnotations(&process_annotations); std::string url = crash_reporter_client->GetUploadUrl(); @@ -134,6 +135,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) {