electron/atom/common/api/atom_api_crash_reporter.cc

60 lines
1.9 KiB
C++
Raw Normal View History

// Copyright (c) 2013 GitHub, Inc.
2014-04-25 09:49:37 +00:00
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include <map>
#include <string>
2014-03-16 00:30:26 +00:00
#include "atom/common/crash_reporter/crash_reporter.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "base/bind.h"
2014-04-16 07:31:59 +00:00
#include "native_mate/dictionary.h"
#include "atom/common/node_includes.h"
2015-06-03 03:31:34 +00:00
using crash_reporter::CrashReporter;
namespace mate {
template<>
2015-06-04 07:52:16 +00:00
struct Converter<CrashReporter::UploadReportResult> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
2015-06-04 07:52:16 +00:00
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();
}
};
} // namespace mate
namespace {
2017-02-09 21:05:23 +00:00
void SetExtraParameter(const std::string& key, mate::Arguments* args) {
std::string value;
if (args->GetNext(&value))
CrashReporter::GetInstance()->SetExtraParameter(key, value);
else
CrashReporter::GetInstance()->RemoveExtraParameter(key);
}
2015-05-22 11:11:22 +00:00
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);
2017-02-02 22:23:21 +00:00
auto reporter = base::Unretained(CrashReporter::GetInstance());
dict.SetMethod("start", base::Bind(&CrashReporter::Start, reporter));
2017-02-09 21:05:23 +00:00
dict.SetMethod("setExtraParameter", &SetExtraParameter);
2017-02-02 21:00:00 +00:00
dict.SetMethod("getUploadedReports",
2017-02-02 22:23:21 +00:00
base::Bind(&CrashReporter::GetUploadedReports, reporter));
2017-02-02 21:00:00 +00:00
dict.SetMethod("setUploadToServer",
2017-02-02 22:23:21 +00:00
base::Bind(&CrashReporter::SetUploadToServer, reporter));
2017-02-02 21:00:00 +00:00
dict.SetMethod("getUploadToServer",
2017-02-02 22:23:21 +00:00
base::Bind(&CrashReporter::GetUploadToServer, reporter));
}
} // namespace
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_crash_reporter, Initialize)