Use PathService for temp dir path for crashes
This commit is contained in:
parent
79a5de3fd8
commit
ac0658bbf1
6 changed files with 48 additions and 17 deletions
|
@ -8,6 +8,7 @@
|
|||
#include "atom/common/atom_version.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/string_split.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
|
@ -34,6 +35,19 @@ void CrashReporter::Start(const std::string& product_name,
|
|||
auto_submit, skip_system_crash_handler);
|
||||
}
|
||||
|
||||
bool CrashReporter::GetTempDirectory(base::FilePath* path) {
|
||||
return PathService::Get(base::DIR_TEMP, path);
|
||||
}
|
||||
|
||||
bool CrashReporter::GetCrashesDirectory(
|
||||
const std::string& product_name, base::FilePath* path) {
|
||||
if (GetTempDirectory(path)) {
|
||||
*path = path->Append(product_name + " Crashes");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CrashReporter::SetUploadParameters(const StringMap& parameters) {
|
||||
upload_parameters_ = parameters;
|
||||
upload_parameters_["process_type"] = is_browser_ ? "browser" : "renderer";
|
||||
|
@ -43,10 +57,15 @@ void CrashReporter::SetUploadParameters(const StringMap& parameters) {
|
|||
}
|
||||
|
||||
std::vector<CrashReporter::UploadReportResult>
|
||||
CrashReporter::GetUploadedReports(const std::string& path) {
|
||||
std::string file_content;
|
||||
CrashReporter::GetUploadedReports(const std::string& product_name) {
|
||||
std::vector<CrashReporter::UploadReportResult> result;
|
||||
if (base::ReadFileToString(base::FilePath::FromUTF8Unsafe(path),
|
||||
|
||||
base::FilePath crashes_dir;
|
||||
if (!GetCrashesDirectory(product_name, &crashes_dir))
|
||||
return result;
|
||||
|
||||
std::string file_content;
|
||||
if (base::ReadFileToString(crashes_dir.Append("uploads.log"),
|
||||
&file_content)) {
|
||||
std::vector<std::string> reports = base::SplitString(
|
||||
file_content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/macros.h"
|
||||
|
||||
namespace crash_reporter {
|
||||
|
@ -29,7 +30,7 @@ class CrashReporter {
|
|||
const StringMap& extra_parameters);
|
||||
|
||||
virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports(
|
||||
const std::string& path);
|
||||
const std::string& product_name);
|
||||
|
||||
protected:
|
||||
CrashReporter();
|
||||
|
@ -43,6 +44,10 @@ class CrashReporter {
|
|||
bool skip_system_crash_handler);
|
||||
virtual void SetUploadParameters();
|
||||
|
||||
bool GetTempDirectory(base::FilePath* path);
|
||||
bool GetCrashesDirectory(const std::string& product_name,
|
||||
base::FilePath* path);
|
||||
|
||||
StringMap upload_parameters_;
|
||||
bool is_browser_;
|
||||
|
||||
|
|
|
@ -78,8 +78,12 @@ void CrashReporterLinux::SetUploadParameters() {
|
|||
}
|
||||
|
||||
void CrashReporterLinux::EnableCrashDumping(const std::string& product_name) {
|
||||
std::string dump_dir = "/tmp/" + product_name + " Crashes";
|
||||
base::FilePath dumps_path(dump_dir);
|
||||
base::FilePath dumps_path;
|
||||
if (!GetCrashesDirectory(&dumps_path)) {
|
||||
LOG(ERROR) << "Cannot get temp directory";
|
||||
return;
|
||||
}
|
||||
|
||||
base::CreateDirectory(dumps_path);
|
||||
|
||||
std::string log_file = base::StringPrintf(
|
||||
|
|
|
@ -33,13 +33,17 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
|
|||
const std::string& submit_url,
|
||||
bool auto_submit,
|
||||
bool skip_system_crash_handler) {
|
||||
// check whether crashpad has been initilized.
|
||||
// check whether crashpad has been initialized.
|
||||
// Only need to initilize once.
|
||||
if (simple_string_dictionary_)
|
||||
return;
|
||||
|
||||
std::string dump_dir = "/tmp/" + product_name + " Crashes";
|
||||
base::FilePath database_path(dump_dir);
|
||||
base::FilePath database_path;
|
||||
if (!GetCrashesDirectory(product_name, &database_path)) {
|
||||
LOG(ERROR) << "Cannot get temp directory";
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_browser_) {
|
||||
@autoreleasepool {
|
||||
base::FilePath framework_bundle_path = base::mac::FrameworkBundlePath();
|
||||
|
@ -93,13 +97,15 @@ void CrashReporterMac::SetCrashKeyValue(const base::StringPiece& key,
|
|||
}
|
||||
|
||||
std::vector<CrashReporter::UploadReportResult>
|
||||
CrashReporterMac::GetUploadedReports(const std::string& path) {
|
||||
CrashReporterMac::GetUploadedReports(const std::string& product_name) {
|
||||
std::vector<CrashReporter::UploadReportResult> uploaded_reports;
|
||||
|
||||
base::FilePath file_path(path);
|
||||
if (!base::PathExists(file_path)) {
|
||||
base::FilePath file_path;
|
||||
if (!GetCrashesDirectory(product_name, &file_path) ||
|
||||
!base::PathExists(file_path)) {
|
||||
return uploaded_reports;
|
||||
}
|
||||
|
||||
// Load crashpad database.
|
||||
std::unique_ptr<crashpad::CrashReportDatabase> database =
|
||||
crashpad::CrashReportDatabase::Initialize(file_path);
|
||||
|
|
|
@ -154,7 +154,7 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name,
|
|||
skip_system_crash_handler_ = skip_system_crash_handler;
|
||||
|
||||
base::FilePath temp_dir;
|
||||
if (!base::GetTempDir(&temp_dir)) {
|
||||
if (!GetTempDirectory(&temp_dir)) {
|
||||
LOG(ERROR) << "Cannot get temp directory";
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -76,10 +76,7 @@ var CrashReporter = (function () {
|
|||
}
|
||||
|
||||
CrashReporter.prototype.getUploadedReports = function () {
|
||||
var log, tmpdir
|
||||
tmpdir = process.platform === 'win32' ? os.tmpdir() : '/tmp'
|
||||
log = process.platform === 'darwin' ? path.join(tmpdir, this.productName + ' Crashes') : path.join(tmpdir, this.productName + ' Crashes', 'uploads.log')
|
||||
return binding._getUploadedReports(log)
|
||||
return binding._getUploadedReports(this.productName)
|
||||
}
|
||||
|
||||
return CrashReporter
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue