2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-11-14 13:33:09 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 08:30:26 +08:00
|
|
|
#include "atom/common/crash_reporter/crash_reporter.h"
|
2013-11-14 13:33:09 +08:00
|
|
|
|
2014-03-16 08:30:26 +08:00
|
|
|
#include "atom/browser/browser.h"
|
|
|
|
#include "atom/common/atom_version.h"
|
2016-12-12 14:35:59 -08:00
|
|
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
2014-03-16 09:37:04 +08:00
|
|
|
#include "base/command_line.h"
|
2015-06-05 18:50:52 +08:00
|
|
|
#include "base/files/file_util.h"
|
|
|
|
#include "base/strings/string_number_conversions.h"
|
2016-08-26 15:30:02 -07:00
|
|
|
#include "base/strings/string_split.h"
|
2017-12-18 16:18:49 +05:30
|
|
|
#include "base/threading/thread_restrictions.h"
|
2016-10-06 09:50:06 -07:00
|
|
|
#include "content/public/common/content_switches.h"
|
2013-11-14 13:33:09 +08:00
|
|
|
|
|
|
|
namespace crash_reporter {
|
|
|
|
|
|
|
|
CrashReporter::CrashReporter() {
|
2018-04-17 15:41:47 -07:00
|
|
|
auto* cmd = base::CommandLine::ForCurrentProcess();
|
2015-03-10 17:00:55 -07:00
|
|
|
is_browser_ = cmd->GetSwitchValueASCII(switches::kProcessType).empty();
|
2013-11-14 13:33:09 +08:00
|
|
|
}
|
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
CrashReporter::~CrashReporter() {}
|
2013-11-14 13:33:09 +08:00
|
|
|
|
2013-11-19 12:19:23 +08:00
|
|
|
void CrashReporter::Start(const std::string& product_name,
|
2013-11-14 13:33:09 +08:00
|
|
|
const std::string& company_name,
|
|
|
|
const std::string& submit_url,
|
2016-10-06 10:39:57 -07:00
|
|
|
const base::FilePath& crashes_dir,
|
2016-11-22 19:30:20 +11:00
|
|
|
bool upload_to_server,
|
2013-11-18 18:27:50 +08:00
|
|
|
bool skip_system_crash_handler,
|
|
|
|
const StringMap& extra_parameters) {
|
|
|
|
SetUploadParameters(extra_parameters);
|
|
|
|
|
2013-11-18 18:03:41 +08:00
|
|
|
InitBreakpad(product_name, ATOM_VERSION_STRING, company_name, submit_url,
|
2016-11-22 19:30:20 +11:00
|
|
|
crashes_dir, upload_to_server, skip_system_crash_handler);
|
2016-10-05 13:31:16 -07:00
|
|
|
}
|
|
|
|
|
2013-11-18 18:27:50 +08:00
|
|
|
void CrashReporter::SetUploadParameters(const StringMap& parameters) {
|
|
|
|
upload_parameters_ = parameters;
|
|
|
|
upload_parameters_["process_type"] = is_browser_ ? "browser" : "renderer";
|
2013-11-18 18:37:32 +08:00
|
|
|
|
|
|
|
// Setting platform dependent parameters.
|
|
|
|
SetUploadParameters();
|
2013-11-14 18:02:15 +08:00
|
|
|
}
|
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
void CrashReporter::SetUploadToServer(const bool upload_to_server) {}
|
2016-11-08 11:03:57 +11:00
|
|
|
|
2016-11-22 19:30:20 +11:00
|
|
|
bool CrashReporter::GetUploadToServer() {
|
2016-11-08 13:39:11 +13:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-03 11:31:34 +08:00
|
|
|
std::vector<CrashReporter::UploadReportResult>
|
2016-10-06 10:39:57 -07:00
|
|
|
CrashReporter::GetUploadedReports(const base::FilePath& crashes_dir) {
|
2017-12-18 16:18:49 +05:30
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
2016-10-06 10:39:57 -07:00
|
|
|
std::string file_content;
|
2015-06-05 18:50:52 +08:00
|
|
|
std::vector<CrashReporter::UploadReportResult> result;
|
2016-10-05 15:23:51 -07:00
|
|
|
base::FilePath uploads_path =
|
2016-10-06 10:39:57 -07:00
|
|
|
crashes_dir.Append(FILE_PATH_LITERAL("uploads.log"));
|
2016-10-05 15:23:51 -07:00
|
|
|
if (base::ReadFileToString(uploads_path, &file_content)) {
|
2015-12-07 19:56:23 +08:00
|
|
|
std::vector<std::string> reports = base::SplitString(
|
|
|
|
file_content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
2015-06-05 18:50:52 +08:00
|
|
|
for (const std::string& report : reports) {
|
2015-12-07 19:56:23 +08:00
|
|
|
std::vector<std::string> report_item = base::SplitString(
|
|
|
|
report, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
2015-06-05 18:50:52 +08:00
|
|
|
int report_time = 0;
|
2018-04-17 21:55:30 -04:00
|
|
|
if (report_item.size() >= 2 &&
|
|
|
|
base::StringToInt(report_item[0], &report_time)) {
|
|
|
|
result.push_back(
|
|
|
|
CrashReporter::UploadReportResult(report_time, report_item[1]));
|
2015-06-05 18:50:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2015-06-03 09:47:42 +08:00
|
|
|
}
|
|
|
|
|
2015-09-28 14:52:55 +08:00
|
|
|
void CrashReporter::InitBreakpad(const std::string& product_name,
|
|
|
|
const std::string& version,
|
|
|
|
const std::string& company_name,
|
|
|
|
const std::string& submit_url,
|
2016-10-06 10:39:57 -07:00
|
|
|
const base::FilePath& crashes_dir,
|
2015-09-28 14:52:55 +08:00
|
|
|
bool auto_submit,
|
2018-04-17 21:55:30 -04:00
|
|
|
bool skip_system_crash_handler) {}
|
2015-09-28 14:52:55 +08:00
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
void CrashReporter::SetUploadParameters() {}
|
2015-09-28 14:52:55 +08:00
|
|
|
|
2017-11-01 21:57:43 -04:00
|
|
|
void CrashReporter::AddExtraParameter(const std::string& key,
|
2018-04-17 21:55:30 -04:00
|
|
|
const std::string& value) {}
|
2017-10-31 13:06:54 -04:00
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
void CrashReporter::RemoveExtraParameter(const std::string& key) {}
|
2017-02-02 14:23:21 -08:00
|
|
|
|
2017-10-31 23:42:25 -04:00
|
|
|
std::map<std::string, std::string> CrashReporter::GetParameters() const {
|
2017-10-31 13:06:54 -04:00
|
|
|
return upload_parameters_;
|
2017-02-09 13:05:23 -08:00
|
|
|
}
|
|
|
|
|
2015-09-28 16:45:53 +08:00
|
|
|
#if defined(OS_MACOSX) && defined(MAS_BUILD)
|
2015-09-28 14:52:55 +08:00
|
|
|
// static
|
|
|
|
CrashReporter* CrashReporter::GetInstance() {
|
|
|
|
static CrashReporter crash_reporter;
|
|
|
|
return &crash_reporter;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-24 13:53:05 -08:00
|
|
|
void CrashReporter::StartInstance(const mate::Dictionary& options) {
|
2018-04-17 15:41:47 -07:00
|
|
|
auto* reporter = GetInstance();
|
2018-04-17 21:55:30 -04:00
|
|
|
if (!reporter)
|
|
|
|
return;
|
2017-01-24 13:53:05 -08: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 13:33:09 +08:00
|
|
|
} // namespace crash_reporter
|