Support override of crash_reporter.cfg settings with environment variables (issue #2413)
This commit is contained in:
parent
d4ec164297
commit
ff8aa46e5e
|
@ -10,6 +10,7 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "base/environment.h"
|
||||||
#include "base/logging.h"
|
#include "base/logging.h"
|
||||||
#include "base/strings/string16.h"
|
#include "base/strings/string16.h"
|
||||||
#include "base/strings/string_number_conversions.h"
|
#include "base/strings/string_number_conversions.h"
|
||||||
|
@ -239,6 +240,29 @@ std::string NormalizeCrashKey(const base::StringPiece& key) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ParseURL(const std::string& value, std::string* url) {
|
||||||
|
if (value.find("http://") == 0 || value.find("https://") == 0) {
|
||||||
|
*url = value;
|
||||||
|
if (url->rfind('/') <= 8) {
|
||||||
|
// Make sure the URL includes a path component. Otherwise, crash
|
||||||
|
// upload will fail on older Windows versions due to
|
||||||
|
// https://crbug.com/826564.
|
||||||
|
*url += "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParseBool(const std::string& value) {
|
||||||
|
return base::EqualsCaseInsensitiveASCII(value, "true") || value == "1";
|
||||||
|
}
|
||||||
|
|
||||||
|
int ParseZeroBasedInt(const std::string& value) {
|
||||||
|
int int_val;
|
||||||
|
if (base::StringToInt(value, &int_val) && int_val > 0)
|
||||||
|
return int_val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
@ -387,37 +411,19 @@ bool CefCrashReporterClient::ReadCrashConfigFile() {
|
||||||
|
|
||||||
if (current_section == kConfigSection) {
|
if (current_section == kConfigSection) {
|
||||||
if (name_str == "ServerURL") {
|
if (name_str == "ServerURL") {
|
||||||
if (val_str.find("http://") == 0 || val_str.find("https://") == 0) {
|
ParseURL(val_str, &server_url_);
|
||||||
server_url_ = val_str;
|
|
||||||
if (server_url_.rfind('/') <= 8) {
|
|
||||||
// Make sure the URL includes a path component. Otherwise, crash
|
|
||||||
// upload will fail on older Windows versions due to
|
|
||||||
// https://crbug.com/826564.
|
|
||||||
server_url_ += "/";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (name_str == "ProductName") {
|
} else if (name_str == "ProductName") {
|
||||||
product_name_ = val_str;
|
product_name_ = val_str;
|
||||||
} else if (name_str == "ProductVersion") {
|
} else if (name_str == "ProductVersion") {
|
||||||
product_version_ = val_str;
|
product_version_ = val_str;
|
||||||
} else if (name_str == "RateLimitEnabled") {
|
} else if (name_str == "RateLimitEnabled") {
|
||||||
rate_limit_ = (base::EqualsCaseInsensitiveASCII(val_str, "true") ||
|
rate_limit_ = ParseBool(val_str);
|
||||||
val_str == "1");
|
|
||||||
} else if (name_str == "MaxUploadsPerDay") {
|
} else if (name_str == "MaxUploadsPerDay") {
|
||||||
if (base::StringToInt(val_str, &max_uploads_)) {
|
max_uploads_ = ParseZeroBasedInt(val_str);
|
||||||
if (max_uploads_ < 0)
|
|
||||||
max_uploads_ = 0;
|
|
||||||
}
|
|
||||||
} else if (name_str == "MaxDatabaseSizeInMb") {
|
} else if (name_str == "MaxDatabaseSizeInMb") {
|
||||||
if (base::StringToInt(val_str, &max_db_size_)) {
|
max_db_size_ = ParseZeroBasedInt(val_str);
|
||||||
if (max_db_size_ < 0)
|
|
||||||
max_db_size_ = 0;
|
|
||||||
}
|
|
||||||
} else if (name_str == "MaxDatabaseAgeInDays") {
|
} else if (name_str == "MaxDatabaseAgeInDays") {
|
||||||
if (base::StringToInt(val_str, &max_db_age_)) {
|
max_db_age_ = ParseZeroBasedInt(val_str);
|
||||||
if (max_db_age_ < 0)
|
|
||||||
max_db_age_ = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
else if (name_str == "ExternalHandler") {
|
else if (name_str == "ExternalHandler") {
|
||||||
|
@ -432,9 +438,7 @@ bool CefCrashReporterClient::ReadCrashConfigFile() {
|
||||||
}
|
}
|
||||||
#elif defined(OS_MACOSX)
|
#elif defined(OS_MACOSX)
|
||||||
else if (name_str == "BrowserCrashForwardingEnabled") {
|
else if (name_str == "BrowserCrashForwardingEnabled") {
|
||||||
enable_browser_crash_forwarding_ =
|
enable_browser_crash_forwarding_ = ParseBool(val_str);
|
||||||
(base::EqualsCaseInsensitiveASCII(val_str, "true") ||
|
|
||||||
val_str == "1");
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (current_section == kCrashKeysSection) {
|
} else if (current_section == kCrashKeysSection) {
|
||||||
|
@ -506,6 +510,19 @@ bool CefCrashReporterClient::ReadCrashConfigFile() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allow override of some values via environment variables.
|
||||||
|
{
|
||||||
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||||
|
std::string val_str;
|
||||||
|
|
||||||
|
if (env->GetVar("CEF_CRASH_REPORTER_SERVER_URL", &val_str)) {
|
||||||
|
ParseURL(val_str, &server_url_);
|
||||||
|
}
|
||||||
|
if (env->GetVar("CEF_CRASH_REPORTER_RATE_LIMIT_ENABLED", &val_str)) {
|
||||||
|
rate_limit_ = ParseBool(val_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
has_crash_config_file_ = true;
|
has_crash_config_file_ = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -498,7 +498,7 @@ index 6508c2a06760..f51ce5a17e63 100644
|
||||||
handler_path, database_path, metrics_path, url, process_annotations,
|
handler_path, database_path, metrics_path, url, process_annotations,
|
||||||
arguments, true, false);
|
arguments, true, false);
|
||||||
diff --git components/crash/content/app/crashpad_win.cc components/crash/content/app/crashpad_win.cc
|
diff --git components/crash/content/app/crashpad_win.cc components/crash/content/app/crashpad_win.cc
|
||||||
index a5d1afc409f4..91815d949f2e 100644
|
index a5d1afc409f4..dc9917f7eca9 100644
|
||||||
--- components/crash/content/app/crashpad_win.cc
|
--- components/crash/content/app/crashpad_win.cc
|
||||||
+++ components/crash/content/app/crashpad_win.cc
|
+++ components/crash/content/app/crashpad_win.cc
|
||||||
@@ -34,8 +34,8 @@ void GetPlatformCrashpadAnnotations(
|
@@ -34,8 +34,8 @@ void GetPlatformCrashpadAnnotations(
|
||||||
|
@ -524,16 +524,34 @@ index a5d1afc409f4..91815d949f2e 100644
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ base::FilePath PlatformCrashpadInitialization(
|
@@ -62,7 +62,9 @@ base::FilePath PlatformCrashpadInitialization(
|
||||||
|
base::FilePath metrics_path; // Only valid in the browser process.
|
||||||
|
|
||||||
|
const char kPipeNameVar[] = "CHROME_CRASHPAD_PIPE_NAME";
|
||||||
|
+#if defined(GOOGLE_CHROME_BUILD)
|
||||||
|
const char kServerUrlVar[] = "CHROME_CRASHPAD_SERVER_URL";
|
||||||
|
+#endif
|
||||||
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||||
|
if (initial_client) {
|
||||||
|
CrashReporterClient* crash_reporter_client = GetCrashReporterClient();
|
||||||
|
@@ -82,13 +84,13 @@ base::FilePath PlatformCrashpadInitialization(
|
||||||
|
|
||||||
#if defined(GOOGLE_CHROME_BUILD)
|
#if defined(GOOGLE_CHROME_BUILD)
|
||||||
std::string url = "https://clients2.google.com/cr/report";
|
std::string url = "https://clients2.google.com/cr/report";
|
||||||
#else
|
-#else
|
||||||
- std::string url;
|
- std::string url;
|
||||||
+ std::string url = crash_reporter_client->GetCrashServerURL();
|
-#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
// Allow the crash server to be overridden for testing. If the variable
|
// Allow the crash server to be overridden for testing. If the variable
|
||||||
@@ -103,13 +103,14 @@ base::FilePath PlatformCrashpadInitialization(
|
// isn't present in the environment then the default URL will remain.
|
||||||
|
env->GetVar(kServerUrlVar, &url);
|
||||||
|
+#else
|
||||||
|
+ std::string url = crash_reporter_client->GetCrashServerURL();
|
||||||
|
+#endif
|
||||||
|
|
||||||
|
wchar_t exe_file_path[MAX_PATH] = {};
|
||||||
|
CHECK(
|
||||||
|
@@ -103,13 +105,14 @@ base::FilePath PlatformCrashpadInitialization(
|
||||||
crashpad::TriState::kEnabled, kIndirectMemoryLimit);
|
crashpad::TriState::kEnabled, kIndirectMemoryLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,7 +571,7 @@ index a5d1afc409f4..91815d949f2e 100644
|
||||||
if (!user_data_dir.empty()) {
|
if (!user_data_dir.empty()) {
|
||||||
start_arguments.push_back(std::string("--user-data-dir=") +
|
start_arguments.push_back(std::string("--user-data-dir=") +
|
||||||
user_data_dir);
|
user_data_dir);
|
||||||
@@ -120,9 +121,12 @@ base::FilePath PlatformCrashpadInitialization(
|
@@ -120,9 +123,12 @@ base::FilePath PlatformCrashpadInitialization(
|
||||||
start_arguments.push_back("/prefetch:7");
|
start_arguments.push_back("/prefetch:7");
|
||||||
} else {
|
} else {
|
||||||
base::FilePath exe_dir = exe_file.DirName();
|
base::FilePath exe_dir = exe_file.DirName();
|
||||||
|
|
Loading…
Reference in New Issue