This commit is contained in:
Haojian Wu 2015-06-04 15:52:16 +08:00
Родитель 94382cbaa2
Коммит d5b47d1059
4 изменённых файлов: 21 добавлений и 35 удалений

Просмотреть файл

@ -34,20 +34,13 @@ struct Converter<std::map<std::string, std::string> > {
};
template<>
struct Converter<std::vector<CrashReporter::UploadReportResult> > {
struct Converter<CrashReporter::UploadReportResult> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const std::vector<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;
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<std::vector<CrashReporter::UploadReportResult> > {
namespace {
std::vector<CrashReporter::UploadReportResult> GetUploadedReports() {
return (CrashReporter::GetInstance())->GetUploadedReports();
}
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
v8::Local<v8::Context> 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

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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()

Просмотреть файл

@ -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