Implement crash-reporter.getLastLastCrashReport API on OS X.
This commit is contained in:
parent
2396b51cb6
commit
4457edb1d3
6 changed files with 72 additions and 0 deletions
|
@ -31,10 +31,34 @@ struct Converter<std::map<std::string, std::string> > {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Converter<std::vector<crash_reporter::CrashReporter::UploadReportResult> > {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const std::vector<
|
||||||
|
crash_reporter::CrashReporter::UploadReportResult>& reports) {
|
||||||
|
v8::Local<v8::Array> result(v8::Array::New(isolate, reports.size()));
|
||||||
|
for (size_t i = 0; i < reports.size(); ++i) {
|
||||||
|
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||||
|
dict.Set("date", reports[i].first);
|
||||||
|
dict.Set("id", reports[i].second);
|
||||||
|
v8::TryCatch try_catch;
|
||||||
|
result->Set(static_cast<uint32>(i), dict.GetHandle());
|
||||||
|
if (try_catch.HasCaught())
|
||||||
|
LOG(ERROR) << "Setter for index " << i << " threw an exception.";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
std::vector<crash_reporter::CrashReporter::UploadReportResult>
|
||||||
|
GetUploadedReports() {
|
||||||
|
return (crash_reporter::CrashReporter::GetInstance())->GetUploadedReports();
|
||||||
|
}
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
v8::Local<v8::Context> context, void* priv) {
|
||||||
using crash_reporter::CrashReporter;
|
using crash_reporter::CrashReporter;
|
||||||
|
@ -42,6 +66,7 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
dict.SetMethod("start",
|
dict.SetMethod("start",
|
||||||
base::Bind(&CrashReporter::Start,
|
base::Bind(&CrashReporter::Start,
|
||||||
base::Unretained(CrashReporter::GetInstance())));
|
base::Unretained(CrashReporter::GetInstance())));
|
||||||
|
dict.SetMethod("_getUploadedReports", &GetUploadedReports);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -41,6 +41,10 @@ class CrashReporter
|
||||||
start()
|
start()
|
||||||
|
|
||||||
getLastCrashReport: ->
|
getLastCrashReport: ->
|
||||||
|
if process.platform is 'darwin'
|
||||||
|
reports = binding._getUploadedReports()
|
||||||
|
return if reports.length > 0 then reports[0] else null
|
||||||
|
|
||||||
tmpdir =
|
tmpdir =
|
||||||
if process.platform is 'win32'
|
if process.platform is 'win32'
|
||||||
os.tmpdir()
|
os.tmpdir()
|
||||||
|
|
|
@ -39,4 +39,8 @@ void CrashReporter::SetUploadParameters(const StringMap& parameters) {
|
||||||
SetUploadParameters();
|
SetUploadParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CrashReporter::UploadReportResult> CrashReporter::GetUploadedReports() {
|
||||||
|
return std::vector<CrashReporter::UploadReportResult>();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace crash_reporter
|
} // namespace crash_reporter
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ namespace crash_reporter {
|
||||||
class CrashReporter {
|
class CrashReporter {
|
||||||
public:
|
public:
|
||||||
typedef std::map<std::string, std::string> StringMap;
|
typedef std::map<std::string, std::string> StringMap;
|
||||||
|
typedef std::pair<int, std::string> UploadReportResult; // upload-date, id
|
||||||
|
|
||||||
static CrashReporter* GetInstance();
|
static CrashReporter* GetInstance();
|
||||||
|
|
||||||
|
@ -25,6 +27,8 @@ class CrashReporter {
|
||||||
bool skip_system_crash_handler,
|
bool skip_system_crash_handler,
|
||||||
const StringMap& extra_parameters);
|
const StringMap& extra_parameters);
|
||||||
|
|
||||||
|
virtual std::vector<CrashReporter::UploadReportResult> GetUploadedReports();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CrashReporter();
|
CrashReporter();
|
||||||
virtual ~CrashReporter();
|
virtual ~CrashReporter();
|
||||||
|
|
|
@ -43,6 +43,8 @@ class CrashReporterMac : public CrashReporter {
|
||||||
void SetCrashKeyValue(const base::StringPiece& key,
|
void SetCrashKeyValue(const base::StringPiece& key,
|
||||||
const base::StringPiece& value);
|
const base::StringPiece& value);
|
||||||
|
|
||||||
|
std::vector<UploadReportResult> GetUploadedReports() override;
|
||||||
|
|
||||||
scoped_ptr<crashpad::SimpleStringDictionary> simple_string_dictionary_;
|
scoped_ptr<crashpad::SimpleStringDictionary> simple_string_dictionary_;
|
||||||
scoped_ptr<crashpad::CrashReportDatabase> crash_report_database_;
|
scoped_ptr<crashpad::CrashReportDatabase> crash_report_database_;
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,39 @@ void CrashReporterMac::SetCrashKeyValue(const base::StringPiece& key,
|
||||||
simple_string_dictionary_->SetKeyValue(key.data(), value.data());
|
simple_string_dictionary_->SetKeyValue(key.data(), value.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CrashReporter::UploadReportResult>
|
||||||
|
CrashReporterMac::GetUploadedReports() {
|
||||||
|
std::vector<CrashReporter::UploadReportResult> uploaded_reports;
|
||||||
|
|
||||||
|
if (!crash_report_database_) {
|
||||||
|
return uploaded_reports;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<crashpad::CrashReportDatabase::Report> completed_reports;
|
||||||
|
crashpad::CrashReportDatabase::OperationStatus status =
|
||||||
|
crash_report_database_->GetCompletedReports(&completed_reports);
|
||||||
|
if (status != crashpad::CrashReportDatabase::kNoError) {
|
||||||
|
return uploaded_reports;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const crashpad::CrashReportDatabase::Report& completed_report :
|
||||||
|
completed_reports) {
|
||||||
|
if (completed_report.uploaded) {
|
||||||
|
uploaded_reports.push_back(
|
||||||
|
UploadReportResult(static_cast<int>(completed_report.creation_time),
|
||||||
|
completed_report.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct {
|
||||||
|
bool operator()(const UploadReportResult& a, const UploadReportResult& b) {
|
||||||
|
return a.first >= b.first;
|
||||||
|
}
|
||||||
|
} sort_by_time;
|
||||||
|
std::sort(uploaded_reports.begin(), uploaded_reports.end(), sort_by_time);
|
||||||
|
return uploaded_reports;
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
CrashReporterMac* CrashReporterMac::GetInstance() {
|
CrashReporterMac* CrashReporterMac::GetInstance() {
|
||||||
return Singleton<CrashReporterMac>::get();
|
return Singleton<CrashReporterMac>::get();
|
||||||
|
|
Loading…
Reference in a new issue