start()
getLastCrashReport: ->
- if process.platform is 'darwin'
- reports = binding._getUploadedReports()
- return if reports.length > 0 then reports[0] else null
+ reports = this.getUploadedReports()
+ if reports.length > 0 then reports[0] else null
+ getUploadedReports: ->
tmpdir =
if process.platform is 'win32'
os.tmpdir()
else
'/tmp'
- log = path.join tmpdir, "#{@productName} Crashes", 'uploads.log'
- try
- reports = String(fs.readFileSync(log)).split('\n')
- return null unless reports.length > 1
- [time, id] = reports[reports.length - 2].split ','
- return {date: new Date(parseInt(time) * 1000), id}
- catch e
- return null
+ log =
+ if process.platform is 'darwin'
+ path.join tmpdir, "#{@productName} Crashes"
+ else
+ path.join tmpdir, "#{@productName} Crashes", 'uploads.log'
+ console.log log;
+ binding._getUploadedReports(log)
+
crashRepoter = new CrashReporter
module.exports = crashRepoter
#include "atom/browser/browser.h"
#include "atom/common/atom_version.h"
#include "base/command_line.h"
+#include "base/files/file_util.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_number_conversions.h"
#include "content/public/common/content_switches.h"
namespace crash_reporter {
}
std::vector<CrashReporter::UploadReportResult>
-CrashReporter::GetUploadedReports() {
- return std::vector<CrashReporter::UploadReportResult>();
+CrashReporter::GetUploadedReports(const std::string& path) {
+ std::string file_content;
+ std::vector<CrashReporter::UploadReportResult> result;
+ if (base::ReadFileToString(base::FilePath(path), &file_content)) {
+ std::vector<std::string> reports;
+ base::SplitString(file_content, '\n', &reports);
+ for (const std::string& report : reports) {
+ std::vector<std::string> report_item;
+ base::SplitString(report, ',', &report_item);
+ 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;
}
} // namespace crash_reporter
bool skip_system_crash_handler,
const StringMap& extra_parameters);
- virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports();
+ virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports(
+ const std::string& path);
protected:
CrashReporter();
template <typename T> struct DefaultSingletonTraits;
-namespace crashpad {
-class CrashReportDatabase;
-}
-
namespace crash_reporter {
class CrashReporterMac : public CrashReporter {
void SetCrashKeyValue(const base::StringPiece& key,
const base::StringPiece& value);
- std::vector<UploadReportResult> GetUploadedReports() override;
+ std::vector<UploadReportResult> GetUploadedReports(
+ const std::string& path) override;
scoped_ptr<crashpad::SimpleStringDictionary> simple_string_dictionary_;
- scoped_ptr<crashpad::CrashReportDatabase> crash_report_database_;
DISALLOW_COPY_AND_ASSIGN(CrashReporterMac);
};
#include "atom/common/crash_reporter/crash_reporter_mac.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/mac_util.h"
#include "base/memory/singleton.h"
SetCrashKeyValue(upload_parameter.first, upload_parameter.second);
}
if (is_browser_) {
- crash_report_database_ = crashpad::CrashReportDatabase::Initialize(
- database_path);
- SetUploadsEnabled(auto_submit);
+ scoped_ptr<crashpad::CrashReportDatabase> database =
+ crashpad::CrashReportDatabase::Initialize(database_path);
+ if (database) {
+ database->GetSettings()->SetUploadsEnabled(auto_submit);
+ }
}
}
upload_parameters_["platform"] = "darwin";
}
-void CrashReporterMac::SetUploadsEnabled(bool enable_uploads) {
- if (crash_report_database_) {
- crashpad::Settings* settings = crash_report_database_->GetSettings();
- settings->SetUploadsEnabled(enable_uploads);
- }
-}
-
void CrashReporterMac::SetCrashKeyValue(const base::StringPiece& key,
const base::StringPiece& value) {
simple_string_dictionary_->SetKeyValue(key.data(), value.data());
}
std::vector<CrashReporter::UploadReportResult>
-CrashReporterMac::GetUploadedReports() {
+CrashReporterMac::GetUploadedReports(const std::string& path) {
std::vector<CrashReporter::UploadReportResult> uploaded_reports;
- if (!crash_report_database_) {
+ base::FilePath file_path(path);
+ if (!base::PathExists(file_path)) {
return uploaded_reports;
}
+ // Load crashpad database.
+ scoped_ptr<crashpad::CrashReportDatabase> database =
+ crashpad::CrashReportDatabase::Initialize(file_path);
+ DCHECK(database);
std::vector<crashpad::CrashReportDatabase::Report> completed_reports;
crashpad::CrashReportDatabase::OperationStatus status =
- crash_report_database_->GetCompletedReports(&completed_reports);
+ database->GetCompletedReports(&completed_reports);
if (status != crashpad::CrashReportDatabase::kNoError) {
return uploaded_reports;
}