diff --git a/atom/common/api/atom_api_crash_reporter.cc b/atom/common/api/atom_api_crash_reporter.cc index 4b51a88b9f3d..e1932ad7f5f0 100644 --- a/atom/common/api/atom_api_crash_reporter.cc +++ b/atom/common/api/atom_api_crash_reporter.cc @@ -34,20 +34,13 @@ struct Converter > { }; template<> -struct Converter > { +struct Converter { static v8::Local ToV8(v8::Isolate* isolate, - const std::vector& reports) { - v8::Local 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(i), dict.GetHandle()); - if (try_catch.HasCaught()) - LOG(ERROR) << "Setter for index " << i << " threw an exception."; - } - return result; + const CrashReporter::UploadReportResult& reports) { + mate::Dictionary dict(isolate, v8::Object::New(isolate)); + dict.Set("date", v8::Date::New(isolate, reports.first*1000.0)); + dict.Set("id", reports.second); + return dict.GetHandle(); } }; @@ -55,17 +48,15 @@ struct Converter > { namespace { -std::vector GetUploadedReports() { - return (CrashReporter::GetInstance())->GetUploadedReports(); -} void Initialize(v8::Local exports, v8::Local unused, v8::Local context, void* priv) { mate::Dictionary dict(context->GetIsolate(), exports); + auto report = base::Unretained(CrashReporter::GetInstance()); dict.SetMethod("start", - base::Bind(&CrashReporter::Start, - base::Unretained(CrashReporter::GetInstance()))); - dict.SetMethod("_getUploadedReports", &GetUploadedReports); + base::Bind(&CrashReporter::Start, report)); + dict.SetMethod("_getUploadedReports", + base::Bind(&CrashReporter::GetUploadedReports, report)); } } // namespace diff --git a/atom/common/crash_reporter/crash_reporter_mac.mm b/atom/common/crash_reporter/crash_reporter_mac.mm index 3cb3063d079b..4edd35a43138 100644 --- a/atom/common/crash_reporter/crash_reporter_mac.mm +++ b/atom/common/crash_reporter/crash_reporter_mac.mm @@ -15,7 +15,6 @@ #include "vendor/crashpad/client/crashpad_client.h" #include "vendor/crashpad/client/crashpad_info.h" #include "vendor/crashpad/client/settings.h" -#include "vendor/crashpad/client/simple_string_dictionary.h" namespace crash_reporter { @@ -31,10 +30,10 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name, const std::string& submit_url, bool auto_submit, bool skip_system_crash_handler) { - static bool initialized = false; - if (initialized) + // check whether crashpad has been initilized. + // Only need to initilize once. + if (simple_string_dictionary_) return; - initialized = true; std::string dump_dir = "/tmp/" + product_name + " Crashes"; 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()); SetCrashKeyValue("prod", ATOM_PRODUCT_NAME); - SetCrashKeyValue("process_type", is_browser_ ? base::StringPiece("browser") - : base::StringPiece("renderer")); + SetCrashKeyValue("process_type", is_browser_ ? "browser" : "renderer"); SetCrashKeyValue("ver", version); - for (auto iter = upload_parameters_.begin(); - iter != upload_parameters_.end(); ++iter) { - SetCrashKeyValue(iter->first, iter->second); + for (const auto& upload_parameter: upload_parameters_) { + SetCrashKeyValue(upload_parameter.first, upload_parameter.second); } if (is_browser_) { crash_report_database_ = crashpad::CrashReportDatabase::Initialize( @@ -120,11 +117,8 @@ CrashReporterMac::GetUploadedReports() { } } - struct { - bool operator()(const UploadReportResult& a, const UploadReportResult& b) { - return a.first >= b.first; - } - } sort_by_time; + auto sort_by_time = [](const UploadReportResult& a, + const UploadReportResult& b) {return a.first >= b.first;}; std::sort(uploaded_reports.begin(), uploaded_reports.end(), sort_by_time); return uploaded_reports; } diff --git a/docs/api/crash-reporter.md b/docs/api/crash-reporter.md index 8e4540567908..d867f77ce398 100644 --- a/docs/api/crash-reporter.md +++ b/docs/api/crash-reporter.md @@ -29,7 +29,8 @@ crashReporter.start({ **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, -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() diff --git a/spec/api-crash-reporter-spec.coffee b/spec/api-crash-reporter-spec.coffee index 60144bc63087..fc93eb304b65 100644 --- a/spec/api-crash-reporter-spec.coffee +++ b/spec/api-crash-reporter-spec.coffee @@ -45,5 +45,5 @@ describe 'crash-reporter module', -> protocol: 'file' pathname: path.join fixtures, 'api', 'crash.html' search: "?port=#{port}" - crashReporter.start {'submitUrl': 'http://127.0.0.1:' + port} + crashReporter.start {'submitUrl': 'http://127.0.0.1:' + port} w.loadUrl url