Simplify and polish the code.
This commit is contained in:
parent
94382cbaa2
commit
d5b47d1059
4 changed files with 21 additions and 35 deletions
|
@ -34,20 +34,13 @@ struct Converter<std::map<std::string, std::string> > {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Converter<std::vector<CrashReporter::UploadReportResult> > {
|
struct Converter<CrashReporter::UploadReportResult> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
const std::vector<CrashReporter::UploadReportResult>& reports) {
|
const CrashReporter::UploadReportResult& reports) {
|
||||||
v8::Local<v8::Array> result(v8::Array::New(isolate, reports.size()));
|
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
||||||
for (size_t i = 0; i < reports.size(); ++i) {
|
dict.Set("date", v8::Date::New(isolate, reports.first*1000.0));
|
||||||
mate::Dictionary dict(isolate, v8::Object::New(isolate));
|
dict.Set("id", reports.second);
|
||||||
dict.Set("date", reports[i].first);
|
return dict.GetHandle();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -55,17 +48,15 @@ struct Converter<std::vector<CrashReporter::UploadReportResult> > {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::vector<CrashReporter::UploadReportResult> GetUploadedReports() {
|
|
||||||
return (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) {
|
||||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
||||||
|
auto report = base::Unretained(CrashReporter::GetInstance());
|
||||||
dict.SetMethod("start",
|
dict.SetMethod("start",
|
||||||
base::Bind(&CrashReporter::Start,
|
base::Bind(&CrashReporter::Start, report));
|
||||||
base::Unretained(CrashReporter::GetInstance())));
|
dict.SetMethod("_getUploadedReports",
|
||||||
dict.SetMethod("_getUploadedReports", &GetUploadedReports);
|
base::Bind(&CrashReporter::GetUploadedReports, report));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include "vendor/crashpad/client/crashpad_client.h"
|
#include "vendor/crashpad/client/crashpad_client.h"
|
||||||
#include "vendor/crashpad/client/crashpad_info.h"
|
#include "vendor/crashpad/client/crashpad_info.h"
|
||||||
#include "vendor/crashpad/client/settings.h"
|
#include "vendor/crashpad/client/settings.h"
|
||||||
#include "vendor/crashpad/client/simple_string_dictionary.h"
|
|
||||||
|
|
||||||
namespace crash_reporter {
|
namespace crash_reporter {
|
||||||
|
|
||||||
|
@ -31,10 +30,10 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
|
||||||
const std::string& submit_url,
|
const std::string& submit_url,
|
||||||
bool auto_submit,
|
bool auto_submit,
|
||||||
bool skip_system_crash_handler) {
|
bool skip_system_crash_handler) {
|
||||||
static bool initialized = false;
|
// check whether crashpad has been initilized.
|
||||||
if (initialized)
|
// Only need to initilize once.
|
||||||
|
if (simple_string_dictionary_)
|
||||||
return;
|
return;
|
||||||
initialized = true;
|
|
||||||
|
|
||||||
std::string dump_dir = "/tmp/" + product_name + " Crashes";
|
std::string dump_dir = "/tmp/" + product_name + " Crashes";
|
||||||
base::FilePath database_path(dump_dir);
|
base::FilePath database_path(dump_dir);
|
||||||
|
@ -65,13 +64,11 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
|
||||||
crashpad_info->set_simple_annotations(simple_string_dictionary_.get());
|
crashpad_info->set_simple_annotations(simple_string_dictionary_.get());
|
||||||
|
|
||||||
SetCrashKeyValue("prod", ATOM_PRODUCT_NAME);
|
SetCrashKeyValue("prod", ATOM_PRODUCT_NAME);
|
||||||
SetCrashKeyValue("process_type", is_browser_ ? base::StringPiece("browser")
|
SetCrashKeyValue("process_type", is_browser_ ? "browser" : "renderer");
|
||||||
: base::StringPiece("renderer"));
|
|
||||||
SetCrashKeyValue("ver", version);
|
SetCrashKeyValue("ver", version);
|
||||||
|
|
||||||
for (auto iter = upload_parameters_.begin();
|
for (const auto& upload_parameter: upload_parameters_) {
|
||||||
iter != upload_parameters_.end(); ++iter) {
|
SetCrashKeyValue(upload_parameter.first, upload_parameter.second);
|
||||||
SetCrashKeyValue(iter->first, iter->second);
|
|
||||||
}
|
}
|
||||||
if (is_browser_) {
|
if (is_browser_) {
|
||||||
crash_report_database_ = crashpad::CrashReportDatabase::Initialize(
|
crash_report_database_ = crashpad::CrashReportDatabase::Initialize(
|
||||||
|
@ -120,11 +117,8 @@ CrashReporterMac::GetUploadedReports() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct {
|
auto sort_by_time = [](const UploadReportResult& a,
|
||||||
bool operator()(const UploadReportResult& a, const UploadReportResult& b) {
|
const UploadReportResult& b) {return a.first >= b.first;};
|
||||||
return a.first >= b.first;
|
|
||||||
}
|
|
||||||
} sort_by_time;
|
|
||||||
std::sort(uploaded_reports.begin(), uploaded_reports.end(), sort_by_time);
|
std::sort(uploaded_reports.begin(), uploaded_reports.end(), sort_by_time);
|
||||||
return uploaded_reports;
|
return uploaded_reports;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,8 @@ crashReporter.start({
|
||||||
|
|
||||||
**Note:** On OS X, electron uses a new `crashpad` client, which is different
|
**Note:** On OS X, electron uses a new `crashpad` client, which is different
|
||||||
with the `breakpad` on Windows and Linux. To enable crash collection feature,
|
with the `breakpad` on Windows and Linux. To enable crash collection feature,
|
||||||
you are required to call `crashReporter.start` API to initiliaze `crashpad` in Browser Process, even you only collect crash report in Renderer Process.
|
you are required to call `crashReporter.start` API to initiliaze `crashpad` in
|
||||||
|
main process, even you only collect crash report in renderer process.
|
||||||
|
|
||||||
## crashReporter.getLastCrashReport()
|
## crashReporter.getLastCrashReport()
|
||||||
|
|
||||||
|
|
|
@ -45,5 +45,5 @@ describe 'crash-reporter module', ->
|
||||||
protocol: 'file'
|
protocol: 'file'
|
||||||
pathname: path.join fixtures, 'api', 'crash.html'
|
pathname: path.join fixtures, 'api', 'crash.html'
|
||||||
search: "?port=#{port}"
|
search: "?port=#{port}"
|
||||||
crashReporter.start {'submitUrl': 'http://127.0.0.1:' + port}
|
crashReporter.start {'submitUrl': 'http://127.0.0.1:' + port}
|
||||||
w.loadUrl url
|
w.loadUrl url
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue