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.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/common/crash_reporter/crash_reporter.h"
|
2013-11-14 05:33:09 +00:00
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/browser.h"
|
|
|
|
#include "atom/common/atom_version.h"
|
2014-03-16 01:37:04 +00:00
|
|
|
#include "base/command_line.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"
|
2016-10-05 23:55:13 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2016-10-06 16:50:06 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2013-11-14 05:33:09 +00:00
|
|
|
|
|
|
|
namespace crash_reporter {
|
|
|
|
|
|
|
|
CrashReporter::CrashReporter() {
|
2015-03-11 00:00:55 +00:00
|
|
|
auto cmd = base::CommandLine::ForCurrentProcess();
|
|
|
|
is_browser_ = cmd->GetSwitchValueASCII(switches::kProcessType).empty();
|
2013-11-14 05:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CrashReporter::~CrashReporter() {
|
|
|
|
}
|
|
|
|
|
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-05 23:40:19 +00:00
|
|
|
const base::FilePath& temp_path,
|
2013-11-14 05:33:09 +00:00
|
|
|
bool auto_submit,
|
2013-11-18 10:27:50 +00:00
|
|
|
bool skip_system_crash_handler,
|
|
|
|
const StringMap& extra_parameters) {
|
|
|
|
SetUploadParameters(extra_parameters);
|
|
|
|
|
2013-11-18 10:03:41 +00:00
|
|
|
InitBreakpad(product_name, ATOM_VERSION_STRING, company_name, submit_url,
|
2016-10-05 23:40:19 +00:00
|
|
|
temp_path, auto_submit, skip_system_crash_handler);
|
2013-11-14 05:33:09 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 22:23:51 +00:00
|
|
|
base::FilePath CrashReporter::GetCrashesDirectory(
|
2016-10-05 23:40:19 +00:00
|
|
|
const std::string& product_name, const base::FilePath& temp_path) {
|
2016-10-06 16:14:16 +00:00
|
|
|
std::string folder_name = product_name + " Crashes";
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
return temp_path.Append(base::UTF8ToUTF16(folder_name));
|
|
|
|
#else
|
|
|
|
return temp_path.Append(folder_name);
|
|
|
|
#endif
|
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;
|
|
|
|
upload_parameters_["process_type"] = is_browser_ ? "browser" : "renderer";
|
2013-11-18 10:37:32 +00:00
|
|
|
|
|
|
|
// Setting platform dependent parameters.
|
|
|
|
SetUploadParameters();
|
2013-11-14 10:02:15 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 03:31:34 +00:00
|
|
|
std::vector<CrashReporter::UploadReportResult>
|
2016-10-05 22:23:51 +00:00
|
|
|
CrashReporter::GetUploadedReports(const std::string& product_name,
|
2016-10-05 23:40:19 +00:00
|
|
|
const base::FilePath& temp_path) {
|
2015-06-05 10:50:52 +00:00
|
|
|
std::vector<CrashReporter::UploadReportResult> result;
|
2016-10-05 20:31:16 +00:00
|
|
|
|
2016-10-05 22:23:51 +00:00
|
|
|
base::FilePath uploads_path =
|
2016-10-05 23:40:19 +00:00
|
|
|
GetCrashesDirectory(product_name, temp_path)
|
|
|
|
.Append(FILE_PATH_LITERAL("uploads.log"));
|
2016-10-05 20:31:16 +00:00
|
|
|
std::string file_content;
|
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;
|
|
|
|
if (report_item.size() >= 2 && base::StringToInt(report_item[0],
|
|
|
|
&report_time)) {
|
|
|
|
result.push_back(CrashReporter::UploadReportResult(report_time,
|
|
|
|
report_item[1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2015-06-03 01:47:42 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 06:52:55 +00: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-05 23:40:19 +00:00
|
|
|
const base::FilePath& temp_path,
|
2015-09-28 06:52:55 +00:00
|
|
|
bool auto_submit,
|
|
|
|
bool skip_system_crash_handler) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CrashReporter::SetUploadParameters() {
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2013-11-14 05:33:09 +00:00
|
|
|
} // namespace crash_reporter
|