2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-11-14 05:33:09 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/crash_reporter/crash_reporter.h"
|
2013-11-14 05:33:09 +00:00
|
|
|
|
2019-06-13 06:42:21 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2014-03-16 01:37:04 +00:00
|
|
|
#include "base/command_line.h"
|
2019-06-13 06:42:21 +00:00
|
|
|
#include "base/environment.h"
|
2015-06-05 10:50:52 +00:00
|
|
|
#include "base/files/file_util.h"
|
|
|
|
#include "base/strings/string_number_conversions.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
#include "base/strings/string_split.h"
|
2017-12-18 10:48:49 +00:00
|
|
|
#include "base/threading/thread_restrictions.h"
|
2016-10-06 16:50:06 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2019-06-19 21:31:55 +00:00
|
|
|
#include "electron/electron_version.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/browser.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/common/electron_constants.h"
|
2019-10-18 00:31:29 +00:00
|
|
|
#include "shell/common/gin_converters/file_path_converter.h"
|
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2013-11-14 05:33:09 +00:00
|
|
|
|
|
|
|
namespace crash_reporter {
|
|
|
|
|
2019-06-13 06:42:21 +00:00
|
|
|
const char kCrashpadProcess[] = "crash-handler";
|
|
|
|
const char kCrashesDirectoryKey[] = "crashes-directory";
|
|
|
|
|
2013-11-14 05:33:09 +00:00
|
|
|
CrashReporter::CrashReporter() {
|
2019-06-19 23:15:14 +00:00
|
|
|
#if BUILDFLAG(ENABLE_RUN_AS_NODE)
|
2019-06-19 21:23:04 +00:00
|
|
|
bool run_as_node = base::Environment::Create()->HasVar(electron::kRunAsNode);
|
2019-06-19 23:15:14 +00:00
|
|
|
#else
|
|
|
|
bool run_as_node = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (run_as_node) {
|
2019-06-13 06:42:21 +00:00
|
|
|
process_type_ = "node";
|
|
|
|
} else {
|
|
|
|
auto* cmd = base::CommandLine::ForCurrentProcess();
|
|
|
|
process_type_ = cmd->GetSwitchValueASCII(switches::kProcessType);
|
|
|
|
}
|
|
|
|
// process_type_ will be empty for browser process
|
2013-11-14 05:33:09 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
CrashReporter::~CrashReporter() = default;
|
2013-11-14 05:33:09 +00:00
|
|
|
|
2019-06-13 06:42:21 +00:00
|
|
|
bool CrashReporter::IsInitialized() {
|
|
|
|
return is_initialized_;
|
|
|
|
}
|
|
|
|
|
2013-11-19 04:19:23 +00:00
|
|
|
void CrashReporter::Start(const std::string& product_name,
|
2013-11-14 05:33:09 +00:00
|
|
|
const std::string& company_name,
|
|
|
|
const std::string& submit_url,
|
2016-10-06 17:39:57 +00:00
|
|
|
const base::FilePath& crashes_dir,
|
2016-11-22 08:30:20 +00:00
|
|
|
bool upload_to_server,
|
2013-11-18 10:27:50 +00:00
|
|
|
bool skip_system_crash_handler,
|
|
|
|
const StringMap& extra_parameters) {
|
2019-06-13 06:42:21 +00:00
|
|
|
is_initialized_ = true;
|
2013-11-18 10:27:50 +00:00
|
|
|
SetUploadParameters(extra_parameters);
|
|
|
|
|
2019-06-13 06:42:21 +00:00
|
|
|
Init(product_name, company_name, submit_url, crashes_dir, upload_to_server,
|
|
|
|
skip_system_crash_handler);
|
2016-10-05 20:31:16 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 10:27:50 +00:00
|
|
|
void CrashReporter::SetUploadParameters(const StringMap& parameters) {
|
|
|
|
upload_parameters_ = parameters;
|
2019-06-13 06:42:21 +00:00
|
|
|
upload_parameters_["process_type"] =
|
|
|
|
process_type_.empty() ? "browser" : process_type_;
|
2019-06-17 20:37:55 +00:00
|
|
|
upload_parameters_["prod"] = ELECTRON_PRODUCT_NAME;
|
|
|
|
upload_parameters_["ver"] = ELECTRON_VERSION_STRING;
|
2013-11-18 10:37:32 +00:00
|
|
|
|
|
|
|
// Setting platform dependent parameters.
|
|
|
|
SetUploadParameters();
|
2013-11-14 10:02:15 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void CrashReporter::SetUploadToServer(const bool upload_to_server) {}
|
2016-11-08 00:03:57 +00:00
|
|
|
|
2016-11-22 08:30:20 +00:00
|
|
|
bool CrashReporter::GetUploadToServer() {
|
2016-11-08 00:39:11 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-03 03:31:34 +00:00
|
|
|
std::vector<CrashReporter::UploadReportResult>
|
2016-10-06 17:39:57 +00:00
|
|
|
CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) {
|
2017-12-18 10:48:49 +00:00
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
2016-10-06 17:39:57 +00:00
|
|
|
std::string file_content;
|
2015-06-05 10:50:52 +00:00
|
|
|
std::vector<CrashReporter::UploadReportResult> result;
|
2016-10-05 22:23:51 +00:00
|
|
|
base::FilePath uploads_path =
|
2016-10-06 17:39:57 +00:00
|
|
|
crashes_dir.Append(FILE_PATH_LITERAL("uploads.log"));
|
2016-10-05 22:23:51 +00:00
|
|
|
if (base::ReadFileToString(uploads_path, &file_content)) {
|
2015-12-07 11:56:23 +00:00
|
|
|
std::vector<std::string> reports = base::SplitString(
|
|
|
|
file_content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
2015-06-05 10:50:52 +00:00
|
|
|
for (const std::string& report : reports) {
|
2015-12-07 11:56:23 +00:00
|
|
|
std::vector<std::string> report_item = base::SplitString(
|
|
|
|
report, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
2015-06-05 10:50:52 +00:00
|
|
|
int report_time = 0;
|
2018-04-18 01:55:30 +00:00
|
|
|
if (report_item.size() >= 2 &&
|
|
|
|
base::StringToInt(report_item[0], &report_time)) {
|
2019-09-13 14:26:59 +00:00
|
|
|
result.emplace_back(report_time, report_item[1]);
|
2015-06-05 10:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2015-06-03 01:47:42 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 06:42:21 +00:00
|
|
|
void CrashReporter::Init(const std::string& product_name,
|
|
|
|
const std::string& company_name,
|
|
|
|
const std::string& submit_url,
|
|
|
|
const base::FilePath& crashes_dir,
|
|
|
|
bool auto_submit,
|
|
|
|
bool skip_system_crash_handler) {}
|
2015-09-28 06:52:55 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void CrashReporter::SetUploadParameters() {}
|
2015-09-28 06:52:55 +00:00
|
|
|
|
2017-11-02 01:57:43 +00:00
|
|
|
void CrashReporter::AddExtraParameter(const std::string& key,
|
2018-04-18 01:55:30 +00:00
|
|
|
const std::string& value) {}
|
2017-10-31 17:06:54 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void CrashReporter::RemoveExtraParameter(const std::string& key) {}
|
2017-02-02 22:23:21 +00:00
|
|
|
|
2017-11-01 03:42:25 +00:00
|
|
|
std::map<std::string, std::string> CrashReporter::GetParameters() const {
|
2017-10-31 17:06:54 +00:00
|
|
|
return upload_parameters_;
|
2017-02-09 21:05:23 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 08:45:53 +00:00
|
|
|
#if defined(OS_MACOSX) && defined(MAS_BUILD)
|
2015-09-28 06:52:55 +00:00
|
|
|
// static
|
|
|
|
CrashReporter* CrashReporter::GetInstance() {
|
|
|
|
static CrashReporter crash_reporter;
|
|
|
|
return &crash_reporter;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-10-18 00:31:29 +00:00
|
|
|
void CrashReporter::StartInstance(const gin_helper::Dictionary& options) {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* reporter = GetInstance();
|
2018-04-18 01:55:30 +00:00
|
|
|
if (!reporter)
|
|
|
|
return;
|
2017-01-24 21:53:05 +00:00
|
|
|
|
|
|
|
std::string product_name;
|
|
|
|
options.Get("productName", &product_name);
|
|
|
|
std::string company_name;
|
|
|
|
options.Get("companyName", &company_name);
|
|
|
|
std::string submit_url;
|
|
|
|
options.Get("submitURL", &submit_url);
|
|
|
|
base::FilePath crashes_dir;
|
|
|
|
options.Get("crashesDirectory", &crashes_dir);
|
|
|
|
StringMap extra_parameters;
|
|
|
|
options.Get("extra", &extra_parameters);
|
|
|
|
|
|
|
|
extra_parameters["_productName"] = product_name;
|
|
|
|
extra_parameters["_companyName"] = company_name;
|
|
|
|
|
|
|
|
reporter->Start(product_name, company_name, submit_url, crashes_dir, true,
|
|
|
|
false, extra_parameters);
|
|
|
|
}
|
|
|
|
|
2013-11-14 05:33:09 +00:00
|
|
|
} // namespace crash_reporter
|