Support override of crash_reporter.cfg settings with environment variables (issue #2413)

This commit is contained in:
Marshall Greenblatt 2018-03-28 17:15:05 -04:00
parent d4ec164297
commit ff8aa46e5e
2 changed files with 68 additions and 33 deletions

View File

@ -10,6 +10,7 @@
#include <windows.h>
#endif
#include "base/environment.h"
#include "base/logging.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
@ -239,6 +240,29 @@ std::string NormalizeCrashKey(const base::StringPiece& key) {
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
#if defined(OS_WIN)
@ -387,37 +411,19 @@ bool CefCrashReporterClient::ReadCrashConfigFile() {
if (current_section == kConfigSection) {
if (name_str == "ServerURL") {
if (val_str.find("http://") == 0 || val_str.find("https://") == 0) {
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_ += "/";
}
}
ParseURL(val_str, &server_url_);
} else if (name_str == "ProductName") {
product_name_ = val_str;
} else if (name_str == "ProductVersion") {
product_version_ = val_str;
} else if (name_str == "RateLimitEnabled") {
rate_limit_ = (base::EqualsCaseInsensitiveASCII(val_str, "true") ||
val_str == "1");
rate_limit_ = ParseBool(val_str);
} else if (name_str == "MaxUploadsPerDay") {
if (base::StringToInt(val_str, &max_uploads_)) {
if (max_uploads_ < 0)
max_uploads_ = 0;
}
max_uploads_ = ParseZeroBasedInt(val_str);
} else if (name_str == "MaxDatabaseSizeInMb") {
if (base::StringToInt(val_str, &max_db_size_)) {
if (max_db_size_ < 0)
max_db_size_ = 0;
}
max_db_size_ = ParseZeroBasedInt(val_str);
} else if (name_str == "MaxDatabaseAgeInDays") {
if (base::StringToInt(val_str, &max_db_age_)) {
if (max_db_age_ < 0)
max_db_age_ = 0;
}
max_db_age_ = ParseZeroBasedInt(val_str);
}
#if defined(OS_WIN)
else if (name_str == "ExternalHandler") {
@ -432,9 +438,7 @@ bool CefCrashReporterClient::ReadCrashConfigFile() {
}
#elif defined(OS_MACOSX)
else if (name_str == "BrowserCrashForwardingEnabled") {
enable_browser_crash_forwarding_ =
(base::EqualsCaseInsensitiveASCII(val_str, "true") ||
val_str == "1");
enable_browser_crash_forwarding_ = ParseBool(val_str);
}
#endif
} 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;
return true;
}

View File

@ -498,7 +498,7 @@ index 6508c2a06760..f51ce5a17e63 100644
handler_path, database_path, metrics_path, url, process_annotations,
arguments, true, false);
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
@@ -34,8 +34,8 @@ void GetPlatformCrashpadAnnotations(
@ -524,16 +524,34 @@ index a5d1afc409f4..91815d949f2e 100644
#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)
std::string url = "https://clients2.google.com/cr/report";
#else
-#else
- std::string url;
+ std::string url = crash_reporter_client->GetCrashServerURL();
#endif
-#endif
// 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);
}
@ -553,7 +571,7 @@ index a5d1afc409f4..91815d949f2e 100644
if (!user_data_dir.empty()) {
start_arguments.push_back(std::string("--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");
} else {
base::FilePath exe_dir = exe_file.DirName();