crash_allow_setting_more_options.patch 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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/breakpad_linux.cc b/components/crash/core/app/breakpad_linux.cc
  9. index 823e49a234e3dd31bf6527c2e4efa96f3d23f1f2..43f6d476f3ee2759cf41c492f932522994e7ddec 100644
  10. --- a/components/crash/core/app/breakpad_linux.cc
  11. +++ b/components/crash/core/app/breakpad_linux.cc
  12. @@ -112,6 +112,7 @@ void SetUploadURL(const std::string& url) {
  13. }
  14. #endif
  15. +bool g_is_node = false;
  16. bool g_is_crash_reporter_enabled = false;
  17. uint64_t g_process_start_time = 0;
  18. pid_t g_pid = 0;
  19. diff --git a/components/crash/core/app/crash_reporter_client.cc b/components/crash/core/app/crash_reporter_client.cc
  20. index 82b7f241e26184240260d0b6287ded159681e15b..abbb267f6a40de0cdf4d09700f9dd444a575fbdf 100644
  21. --- a/components/crash/core/app/crash_reporter_client.cc
  22. +++ b/components/crash/core/app/crash_reporter_client.cc
  23. @@ -141,6 +141,17 @@ bool CrashReporterClient::ReportingIsEnforcedByPolicy(bool* breakpad_enabled) {
  24. return false;
  25. }
  26. +bool CrashReporterClient::GetShouldRateLimit() {
  27. + return true;
  28. +}
  29. +
  30. +bool CrashReporterClient::GetShouldCompressUploads() {
  31. + return true;
  32. +}
  33. +
  34. +void CrashReporterClient::GetProcessSimpleAnnotations(std::map<std::string, std::string>* annotations) {
  35. +}
  36. +
  37. #if BUILDFLAG(IS_ANDROID)
  38. unsigned int CrashReporterClient::GetCrashDumpPercentage() {
  39. return 100;
  40. diff --git a/components/crash/core/app/crash_reporter_client.h b/components/crash/core/app/crash_reporter_client.h
  41. index 24e53fa62c2c4a11494ad3d43f0c5a806930fcdd..9b691baa6cc90cc3f9ada307c43f44c4353e2487 100644
  42. --- a/components/crash/core/app/crash_reporter_client.h
  43. +++ b/components/crash/core/app/crash_reporter_client.h
  44. @@ -5,6 +5,7 @@
  45. #ifndef COMPONENTS_CRASH_CORE_APP_CRASH_REPORTER_CLIENT_H_
  46. #define COMPONENTS_CRASH_CORE_APP_CRASH_REPORTER_CLIENT_H_
  47. +#include <map>
  48. #include <string>
  49. #include "build/build_config.h"
  50. @@ -146,6 +147,19 @@ class CrashReporterClient {
  51. // that case, |breakpad_enabled| is set to the value enforced by policies.
  52. virtual bool ReportingIsEnforcedByPolicy(bool* breakpad_enabled);
  53. + // Returns true if crash uploads should be rate limited. If false, no
  54. + // throttling will be applied for uploads.
  55. + virtual bool GetShouldRateLimit();
  56. +
  57. + // Returns true if crash uploads should be compressed with gzip. If false,
  58. + // reports will be uploaded uncompressed.
  59. + virtual bool GetShouldCompressUploads();
  60. +
  61. + // Allows the client to add or edit global annotations passed to the crashpad
  62. + // handler.
  63. + virtual void GetProcessSimpleAnnotations(
  64. + std::map<std::string, std::string>* annotations);
  65. +
  66. #if BUILDFLAG(IS_ANDROID)
  67. // Used by WebView to sample crashes without generating the unwanted dumps. If
  68. // the returned value is less than 100, crash dumping will be sampled to that
  69. diff --git a/components/crash/core/app/crashpad_linux.cc b/components/crash/core/app/crashpad_linux.cc
  70. index dc2b18b322350121768571b7997d632a10220ac9..3e3ee0f721a2316d324fb31e17ba97ff24d9e6d7 100644
  71. --- a/components/crash/core/app/crashpad_linux.cc
  72. +++ b/components/crash/core/app/crashpad_linux.cc
  73. @@ -180,6 +180,7 @@ bool PlatformCrashpadInitialization(
  74. // where crash_reporter provides it's own values for lsb-release.
  75. annotations["lsb-release"] = base::GetLinuxDistro();
  76. #endif
  77. + crash_reporter_client->GetProcessSimpleAnnotations(&annotations);
  78. std::vector<std::string> arguments;
  79. if (crash_reporter_client->ShouldMonitorCrashHandlerExpensively()) {
  80. @@ -201,6 +202,13 @@ bool PlatformCrashpadInitialization(
  81. }
  82. #endif
  83. + if (!crash_reporter_client->GetShouldRateLimit()) {
  84. + arguments.push_back("--no-rate-limit");
  85. + }
  86. + if (!crash_reporter_client->GetShouldCompressUploads()) {
  87. + arguments.push_back("--no-upload-gzip");
  88. + }
  89. +
  90. bool result =
  91. client.StartHandler(handler_path, *database_path, metrics_path, url,
  92. annotations, arguments, false, false);
  93. diff --git a/components/crash/core/app/crashpad_mac.mm b/components/crash/core/app/crashpad_mac.mm
  94. index dc041c43371fd58e3121ef6bc423aadb644bb8d0..a1fa566775724b4a1662a939fda3f0a59bf46b96 100644
  95. --- a/components/crash/core/app/crashpad_mac.mm
  96. +++ b/components/crash/core/app/crashpad_mac.mm
  97. @@ -85,6 +85,8 @@
  98. } // @autoreleasepool
  99. return process_annotations;
  100. }();
  101. + CrashReporterClient* crash_reporter_client = GetCrashReporterClient();
  102. + crash_reporter_client->GetProcessSimpleAnnotations(&annotations);
  103. return annotations;
  104. }
  105. @@ -155,6 +157,13 @@ bool PlatformCrashpadInitialization(
  106. std::vector<std::string> arguments;
  107. + if (!crash_reporter_client->GetShouldRateLimit()) {
  108. + arguments.push_back("--no-rate-limit");
  109. + }
  110. + if (!crash_reporter_client->GetShouldCompressUploads()) {
  111. + arguments.push_back("--no-upload-gzip");
  112. + }
  113. +
  114. if (crash_reporter_client->ShouldMonitorCrashHandlerExpensively()) {
  115. arguments.push_back("--monitor-self");
  116. }
  117. diff --git a/components/crash/core/app/crashpad_win.cc b/components/crash/core/app/crashpad_win.cc
  118. index 1a8f42cb4e2ea493642d8b264d0be5c3da358793..e972272de54107aaed6143e3f3569ba56bd3cf3e 100644
  119. --- a/components/crash/core/app/crashpad_win.cc
  120. +++ b/components/crash/core/app/crashpad_win.cc
  121. @@ -89,6 +89,7 @@ bool PlatformCrashpadInitialization(
  122. std::map<std::string, std::string> process_annotations;
  123. GetPlatformCrashpadAnnotations(&process_annotations);
  124. + crash_reporter_client->GetProcessSimpleAnnotations(&process_annotations);
  125. std::string url = crash_reporter_client->GetUploadUrl();
  126. @@ -127,6 +128,13 @@ bool PlatformCrashpadInitialization(
  127. std::vector<std::string> arguments(start_arguments);
  128. + if (!crash_reporter_client->GetShouldRateLimit()) {
  129. + arguments.push_back("--no-rate-limit");
  130. + }
  131. + if (!crash_reporter_client->GetShouldCompressUploads()) {
  132. + arguments.push_back("--no-upload-gzip");
  133. + }
  134. +
  135. if (crash_reporter_client->ShouldMonitorCrashHandlerExpensively()) {
  136. arguments.push_back("--monitor-self");
  137. for (const std::string& start_argument : start_arguments) {