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 9d8370ef035f2ca285c8aa35e98761bff7200d26..1c076672c77d90eb3814b5b269340d2800217868 100644 --- a/components/crash/core/app/breakpad_linux.cc +++ b/components/crash/core/app/breakpad_linux.cc @@ -110,6 +110,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 1d0fb4f2a633fa5ddbe232ce19d716c22be78a37..5b81608d6e90f62f435302a53976fb18bbbf9e98 100644 --- a/components/crash/core/app/crash_reporter_client.cc +++ b/components/crash/core/app/crash_reporter_client.cc @@ -140,6 +140,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 defined(OS_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 aaa9ad1d58d7f584cbf391e0cb0a61a0d25d5c69..5b02834b5ecaf4bcb7e051d9ee98cd5eb087b4fc 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 "base/strings/string16.h" @@ -145,6 +146,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 defined(OS_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_mac.mm b/components/crash/core/app/crashpad_mac.mm index eb675321436a53e82432144d43f258bed6e938e2..ae2032a12eac7c789d790e53857d11ba3e03d510 100644 --- a/components/crash/core/app/crashpad_mac.mm +++ b/components/crash/core/app/crashpad_mac.mm @@ -77,6 +77,8 @@ } // @autoreleasepool return process_annotations; }(); + CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); + crash_reporter_client->GetProcessSimpleAnnotations(&annotations); return annotations; } @@ -147,6 +149,13 @@ void DumpProcessWithoutCrashing(task_t task_port) { 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 c199b467ffeb007f3098ccde6879fbd71e9ec9fd..a2007514e799b77fa15cbc178d38594e4d847caa 100644 --- a/components/crash/core/app/crashpad_win.cc +++ b/components/crash/core/app/crashpad_win.cc @@ -84,6 +84,7 @@ base::FilePath PlatformCrashpadInitialization( std::map process_annotations; GetPlatformCrashpadAnnotations(&process_annotations); + crash_reporter_client->GetProcessSimpleAnnotations(&process_annotations); std::string url = crash_reporter_client->GetUploadUrl(); @@ -122,6 +123,13 @@ base::FilePath 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) {