crash_allow_setting_more_options.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Jeremy Apthorp <[email protected]>
  3. Date: Thu, 30 Apr 2020 10:08:06 -0700
  4. Subject: crash: allow setting more options
  5. This allows the client of //components/crash to set upload url,
  6. rate-limiting, compression and global annotations.
  7. This should be upstreamed.
  8. diff --git a/components/crash/core/app/crash_reporter_client.cc b/components/crash/core/app/crash_reporter_client.cc
  9. index b6a2910848c66489e70acdce6e09237bf6188f94..744cca2d1b8856719b9ae5aed6c443e8752da75e 100644
  10. --- a/components/crash/core/app/crash_reporter_client.cc
  11. +++ b/components/crash/core/app/crash_reporter_client.cc
  12. @@ -119,6 +119,17 @@ bool CrashReporterClient::ReportingIsEnforcedByPolicy(bool* breakpad_enabled) {
  13. return false;
  14. }
  15. +bool CrashReporterClient::GetShouldRateLimit() {
  16. + return true;
  17. +}
  18. +
  19. +bool CrashReporterClient::GetShouldCompressUploads() {
  20. + return true;
  21. +}
  22. +
  23. +void CrashReporterClient::GetProcessSimpleAnnotations(std::map<std::string, std::string>* annotations) {
  24. +}
  25. +
  26. #if BUILDFLAG(IS_ANDROID)
  27. unsigned int CrashReporterClient::GetCrashDumpPercentage() {
  28. return 100;
  29. diff --git a/components/crash/core/app/crash_reporter_client.h b/components/crash/core/app/crash_reporter_client.h
  30. index 7c890b331be4aaaf20c7efe8a4bcc2f6e9012b7a..c573524d05c07ec67d35046bc8548cc1dfdd0df3 100644
  31. --- a/components/crash/core/app/crash_reporter_client.h
  32. +++ b/components/crash/core/app/crash_reporter_client.h
  33. @@ -7,6 +7,7 @@
  34. #include <stdint.h>
  35. +#include <map>
  36. #include <string>
  37. #include "build/build_config.h"
  38. @@ -141,6 +142,19 @@ class CrashReporterClient {
  39. // that case, |breakpad_enabled| is set to the value enforced by policies.
  40. virtual bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled);
  41. + // Returns true if crash uploads should be rate limited. If false, no
  42. + // throttling will be applied for uploads.
  43. + virtual bool GetShouldRateLimit();
  44. +
  45. + // Returns true if crash uploads should be compressed with gzip. If false,
  46. + // reports will be uploaded uncompressed.
  47. + virtual bool GetShouldCompressUploads();
  48. +
  49. + // Allows the client to add or edit global annotations passed to the crashpad
  50. + // handler.
  51. + virtual void GetProcessSimpleAnnotations(
  52. + std::map<std::string, std::string>* annotations);
  53. +
  54. #if BUILDFLAG(IS_ANDROID)
  55. // Used by WebView to sample crashes without generating the unwanted dumps. If
  56. // the returned value is less than 100, crash dumping will be sampled to that
  57. diff --git a/components/crash/core/app/crashpad_linux.cc b/components/crash/core/app/crashpad_linux.cc
  58. index 5d9b3bd5386ecbdb74cc470dbe65308c3afa0a61..dc29a4bedc0533e27affb26367cfcc2c3f9544f3 100644
  59. --- a/components/crash/core/app/crashpad_linux.cc
  60. +++ b/components/crash/core/app/crashpad_linux.cc
  61. @@ -218,6 +218,7 @@ bool PlatformCrashpadInitialization(
  62. // where crash_reporter provides it's own values for lsb-release.
  63. annotations["lsb-release"] = base::GetLinuxDistro();
  64. #endif
  65. + crash_reporter_client->GetProcessSimpleAnnotations(&annotations);
  66. std::vector<std::string> arguments;
  67. if (crash_reporter_client->ShouldMonitorCrashHandlerExpensively()) {
  68. @@ -239,6 +240,13 @@ bool PlatformCrashpadInitialization(
  69. }
  70. #endif
  71. + if (!crash_reporter_client->GetShouldRateLimit()) {
  72. + arguments.push_back("--no-rate-limit");
  73. + }
  74. + if (!crash_reporter_client->GetShouldCompressUploads()) {
  75. + arguments.push_back("--no-upload-gzip");
  76. + }
  77. +
  78. CHECK(client.StartHandler(handler_path, *database_path, metrics_path, url,
  79. annotations, arguments, false, false));
  80. } else {
  81. diff --git a/components/crash/core/app/crashpad_mac.mm b/components/crash/core/app/crashpad_mac.mm
  82. index 42fe73aefe44f218d6a5e8cb1550ff48859c4b70..a1235f0c7ad44ae9c9fdc805af5b9dc5669f5aad 100644
  83. --- a/components/crash/core/app/crashpad_mac.mm
  84. +++ b/components/crash/core/app/crashpad_mac.mm
  85. @@ -86,6 +86,8 @@
  86. } // @autoreleasepool
  87. return process_annotations;
  88. }();
  89. + CrashReporterClient* crash_reporter_client = GetCrashReporterClient();
  90. + crash_reporter_client->GetProcessSimpleAnnotations(&annotations);
  91. return annotations;
  92. }
  93. @@ -156,6 +158,13 @@ bool PlatformCrashpadInitialization(
  94. std::vector<std::string> arguments;
  95. + if (!crash_reporter_client->GetShouldRateLimit()) {
  96. + arguments.push_back("--no-rate-limit");
  97. + }
  98. + if (!crash_reporter_client->GetShouldCompressUploads()) {
  99. + arguments.push_back("--no-upload-gzip");
  100. + }
  101. +
  102. if (crash_reporter_client->ShouldMonitorCrashHandlerExpensively()) {
  103. arguments.push_back("--monitor-self");
  104. }
  105. diff --git a/components/crash/core/app/crashpad_win.cc b/components/crash/core/app/crashpad_win.cc
  106. index 0e00d26f79231a01e88981b30ff950e427cd31f4..70f014c75031f9529501e102f97e0e1adadb8ffb 100644
  107. --- a/components/crash/core/app/crashpad_win.cc
  108. +++ b/components/crash/core/app/crashpad_win.cc
  109. @@ -92,6 +92,7 @@ bool PlatformCrashpadInitialization(
  110. std::map<std::string, std::string> process_annotations;
  111. GetPlatformCrashpadAnnotations(&process_annotations);
  112. + crash_reporter_client->GetProcessSimpleAnnotations(&process_annotations);
  113. std::string url = crash_reporter_client->GetUploadUrl();
  114. @@ -129,6 +130,13 @@ bool PlatformCrashpadInitialization(
  115. std::vector<std::string> arguments(start_arguments);
  116. + if (!crash_reporter_client->GetShouldRateLimit()) {
  117. + arguments.push_back("--no-rate-limit");
  118. + }
  119. + if (!crash_reporter_client->GetShouldCompressUploads()) {
  120. + arguments.push_back("--no-upload-gzip");
  121. + }
  122. +
  123. if (crash_reporter_client->ShouldMonitorCrashHandlerExpensively()) {
  124. arguments.push_back("--monitor-self");
  125. for (const std::string& start_argument : start_arguments) {