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"
|
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
|
|
|
|
2014-04-15 08:02:19 +00:00
|
|
|
namespace mate {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Converter<std::map<std::string, std::string> > {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> val,
|
2014-04-15 08:02:19 +00:00
|
|
|
std::map<std::string, std::string>* out) {
|
|
|
|
if (!val->IsObject())
|
|
|
|
return false;
|
|
|
|
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Object> dict = val->ToObject();
|
|
|
|
v8::Local<v8::Array> keys = dict->GetOwnPropertyNames();
|
2014-04-15 08:02:19 +00:00
|
|
|
for (uint32_t i = 0; i < keys->Length(); ++i) {
|
2015-05-22 11:11:22 +00:00
|
|
|
v8::Local<v8::Value> key = keys->Get(i);
|
2014-04-15 08:02:19 +00:00
|
|
|
(*out)[V8ToString(key)] = V8ToString(dict->Get(key));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-03 01:47:42 +00:00
|
|
|
template<>
|
|
|
|
struct Converter<std::vector<crash_reporter::CrashReporter::UploadReportResult> > {
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
const std::vector<
|
|
|
|
crash_reporter::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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-15 08:02:19 +00:00
|
|
|
} // namespace mate
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-06-03 01:47:42 +00:00
|
|
|
std::vector<crash_reporter::CrashReporter::UploadReportResult>
|
|
|
|
GetUploadedReports() {
|
|
|
|
return (crash_reporter::CrashReporter::GetInstance())->GetUploadedReports();
|
|
|
|
}
|
|
|
|
|
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) {
|
2014-04-15 08:02:19 +00:00
|
|
|
using crash_reporter::CrashReporter;
|
2014-06-29 12:48:44 +00:00
|
|
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
2014-04-16 07:31:59 +00:00
|
|
|
dict.SetMethod("start",
|
|
|
|
base::Bind(&CrashReporter::Start,
|
|
|
|
base::Unretained(CrashReporter::GetInstance())));
|
2015-06-03 01:47:42 +00:00
|
|
|
dict.SetMethod("_getUploadedReports", &GetUploadedReports);
|
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
|
|
|
|
2014-06-29 12:48:44 +00:00
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_crash_reporter, Initialize)
|