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 3f3ed53d48fc4b19642cae847e69982782790e31..51d089f9fa0e1734f98f270a81a200beda71f2f4 100644
  10. --- a/components/crash/core/app/crash_reporter_client.cc
  11. +++ b/components/crash/core/app/crash_reporter_client.cc
  12. @@ -141,6 +141,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 a604df7a5ea6a1f5613acc032a65668364aadf89..93a8bf787bdaa0e4251a41453eb22062646f4bcb 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. @@ -153,6 +154,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 99efa6b245b9944710b76a342ec9a37947078a48..e55df93f17560a566e1dd2a63c560054edd772a5 100644
  59. --- a/components/crash/core/app/crashpad_linux.cc
  60. +++ b/components/crash/core/app/crashpad_linux.cc
  61. @@ -170,6 +170,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. @@ -191,6 +192,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 eb5bcfe0234c39526d6d162434476fe9e32d8184..8480d07e2607eb3c8c16b54a02077c0454d11fce 100644
  83. --- a/components/crash/core/app/crashpad_mac.mm
  84. +++ b/components/crash/core/app/crashpad_mac.mm
  85. @@ -87,6 +87,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. @@ -157,6 +159,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 15addd5c5e6635ad3b5797d5986c79353590a583..f31ae6b9e8bfdcc32239d0f6859e29ea6b4112b1 100644
  107. --- a/components/crash/core/app/crashpad_win.cc
  108. +++ b/components/crash/core/app/crashpad_win.cc
  109. @@ -91,6 +91,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) {