2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-06-01 15:57:37 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 09:13:06 +08:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2014-03-16 08:30:26 +08:00
|
|
|
#include "atom/common/crash_reporter/crash_reporter.h"
|
2014-04-15 16:02:19 +08:00
|
|
|
#include "base/bind.h"
|
2014-04-16 15:31:59 +08:00
|
|
|
#include "native_mate/dictionary.h"
|
2013-12-11 15:48:19 +08:00
|
|
|
|
2014-04-17 13:45:14 +08:00
|
|
|
#include "atom/common/node_includes.h"
|
2013-06-01 15:57:37 +08:00
|
|
|
|
2015-06-03 11:31:34 +08:00
|
|
|
using crash_reporter::CrashReporter;
|
|
|
|
|
2014-04-15 16:02:19 +08:00
|
|
|
namespace mate {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Converter<std::map<std::string, std::string> > {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
2015-05-22 19:11:22 +08:00
|
|
|
v8::Local<v8::Value> val,
|
2014-04-15 16:02:19 +08:00
|
|
|
std::map<std::string, std::string>* out) {
|
|
|
|
if (!val->IsObject())
|
|
|
|
return false;
|
|
|
|
|
2015-05-22 19:11:22 +08:00
|
|
|
v8::Local<v8::Object> dict = val->ToObject();
|
|
|
|
v8::Local<v8::Array> keys = dict->GetOwnPropertyNames();
|
2014-04-15 16:02:19 +08:00
|
|
|
for (uint32_t i = 0; i < keys->Length(); ++i) {
|
2015-05-22 19:11:22 +08:00
|
|
|
v8::Local<v8::Value> key = keys->Get(i);
|
2014-04-15 16:02:19 +08:00
|
|
|
(*out)[V8ToString(key)] = V8ToString(dict->Get(key));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-03 09:47:42 +08:00
|
|
|
template<>
|
2015-06-04 15:52:16 +08:00
|
|
|
struct Converter<CrashReporter::UploadReportResult> {
|
2015-06-03 09:47:42 +08:00
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
2015-06-04 15:52:16 +08: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();
|
2015-06-03 09:47:42 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-15 16:02:19 +08:00
|
|
|
} // namespace mate
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-06-03 09:47:42 +08:00
|
|
|
|
2015-05-22 19:11:22 +08:00
|
|
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context, void* priv) {
|
2014-06-29 20:48:44 +08:00
|
|
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
2015-06-04 15:52:16 +08:00
|
|
|
auto report = base::Unretained(CrashReporter::GetInstance());
|
2014-04-16 15:31:59 +08:00
|
|
|
dict.SetMethod("start",
|
2015-06-04 15:52:16 +08:00
|
|
|
base::Bind(&CrashReporter::Start, report));
|
|
|
|
dict.SetMethod("_getUploadedReports",
|
|
|
|
base::Bind(&CrashReporter::GetUploadedReports, report));
|
2013-06-01 15:57:37 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 16:02:19 +08:00
|
|
|
} // namespace
|
2013-06-01 15:57:37 +08:00
|
|
|
|
2014-06-29 20:48:44 +08:00
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_crash_reporter, Initialize)
|