2014-10-31 18:17:05 +00:00
|
|
|
// 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
|
2013-06-01 07:57:37 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/common/crash_reporter/crash_reporter.h"
|
2016-10-05 23:15:49 +00:00
|
|
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
2014-04-15 08:02:19 +00:00
|
|
|
#include "base/bind.h"
|
2014-04-16 07:31:59 +00:00
|
|
|
#include "native_mate/dictionary.h"
|
2013-12-11 07:48:19 +00:00
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
2013-06-01 07:57:37 +00:00
|
|
|
|
2015-06-03 03:31:34 +00:00
|
|
|
using crash_reporter::CrashReporter;
|
|
|
|
|
2014-04-15 08:02:19 +00:00
|
|
|
namespace mate {
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2015-06-04 07:52:16 +00:00
|
|
|
struct Converter<CrashReporter::UploadReportResult> {
|
2018-04-18 01:55:30 +00:00
|
|
|
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));
|
2019-01-12 01:00:43 +00:00
|
|
|
dict.Set("date",
|
|
|
|
v8::Date::New(isolate->GetCurrentContext(), reports.first * 1000.0)
|
|
|
|
.ToLocalChecked());
|
2015-06-04 07:52:16 +00:00
|
|
|
dict.Set("id", reports.second);
|
|
|
|
return dict.GetHandle();
|
2015-06-03 01:47:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-15 08:02:19 +00:00
|
|
|
} // namespace mate
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-11-02 01:57:43 +00:00
|
|
|
void AddExtraParameter(const std::string& key, const std::string& value) {
|
|
|
|
CrashReporter::GetInstance()->AddExtraParameter(key, value);
|
2017-10-31 03:12:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveExtraParameter(const std::string& key) {
|
|
|
|
CrashReporter::GetInstance()->RemoveExtraParameter(key);
|
2017-02-09 21:05:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-01 03:55:22 +00:00
|
|
|
std::map<std::string, std::string> GetParameters() {
|
2017-10-31 17:06:54 +00:00
|
|
|
return CrashReporter::GetInstance()->GetParameters();
|
|
|
|
}
|
2015-06-03 01:47:42 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2014-06-29 12:48:44 +00:00
|
|
|
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-11-02 01:57:43 +00:00
|
|
|
dict.SetMethod("addExtraParameter", &AddExtraParameter);
|
2017-10-31 17:06:54 +00:00
|
|
|
dict.SetMethod("removeExtraParameter", &RemoveExtraParameter);
|
|
|
|
dict.SetMethod("getParameters", &GetParameters);
|
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));
|
2013-06-01 07:57:37 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 08:02:19 +00:00
|
|
|
} // namespace
|
2013-06-01 07:57:37 +00:00
|
|
|
|
2019-03-08 18:29:52 +00:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_common_crash_reporter, Initialize)
|