Use native_mate to simplify crash_reporter api.

This commit is contained in:
Cheng Zhao 2014-04-15 16:02:19 +08:00
parent d9cd50c219
commit c25911db0d
4 changed files with 32 additions and 62 deletions

View file

@ -144,7 +144,6 @@
'atom/common/api/api_messages.h',
'atom/common/api/atom_api_clipboard.cc',
'atom/common/api/atom_api_crash_reporter.cc',
'atom/common/api/atom_api_crash_reporter.h',
'atom/common/api/atom_api_event_emitter.cc',
'atom/common/api/atom_api_event_emitter.h',
'atom/common/api/atom_api_id_weak_map.cc',

View file

@ -2,40 +2,48 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "atom/common/api/atom_api_crash_reporter.h"
#include <map>
#include <string>
#include "atom/common/crash_reporter/crash_reporter.h"
#include "atom/common/v8/native_type_conversions.h"
#include "base/bind.h"
#include "native_mate/object_template_builder.h"
#include "atom/common/v8/node_common.h"
namespace atom {
namespace mate {
namespace api {
template<>
struct Converter<std::map<std::string, std::string> > {
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
std::map<std::string, std::string>* out) {
if (!val->IsObject())
return false;
// static
void CrashReporter::Start(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string product_name, company_name, submit_url;
bool auto_submit, skip_system;
std::map<std::string, std::string> dict;
if (!FromV8Arguments(args, &product_name, &company_name, &submit_url,
&auto_submit, &skip_system, &dict))
return node::ThrowTypeError("Bad argument");
v8::Handle<v8::Object> dict = val->ToObject();
v8::Handle<v8::Array> keys = dict->GetOwnPropertyNames();
for (uint32_t i = 0; i < keys->Length(); ++i) {
v8::Handle<v8::Value> key = keys->Get(i);
(*out)[V8ToString(key)] = V8ToString(dict->Get(key));
}
return true;
}
};
crash_reporter::CrashReporter::GetInstance()->Start(
product_name, company_name, submit_url, auto_submit, skip_system, dict);
} // namespace mate
namespace {
void Initialize(v8::Handle<v8::Object> exports) {
using crash_reporter::CrashReporter;
mate::ObjectTemplateBuilder builder(v8::Isolate::GetCurrent());
builder.SetMethod("start",
base::Bind(&CrashReporter::Start,
base::Unretained(CrashReporter::GetInstance())));
exports->SetPrototype(builder.Build()->NewInstance());
}
// static
void CrashReporter::Initialize(v8::Handle<v8::Object> target) {
NODE_SET_METHOD(target, "start", Start);
}
} // namespace
} // namespace api
} // namespace atom
NODE_MODULE(atom_common_crash_reporter, atom::api::CrashReporter::Initialize)
NODE_MODULE(atom_common_crash_reporter, Initialize)

View file

@ -1,29 +0,0 @@
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATOM_COMMON_API_ATOM_API_CRASH_REPORTER_H_
#define ATOM_COMMON_API_ATOM_API_CRASH_REPORTER_H_
#include "base/basictypes.h"
#include "v8/include/v8.h"
namespace atom {
namespace api {
class CrashReporter {
public:
static void Initialize(v8::Handle<v8::Object> target);
private:
static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
DISALLOW_IMPLICIT_CONSTRUCTORS(CrashReporter);
};
} // namespace api
} // namespace atom
#endif // ATOM_COMMON_API_ATOM_API_CRASH_REPORTER_H_

View file

@ -15,10 +15,6 @@ namespace mate {
template<>
struct Converter<GURL> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
const GURL& val) {
return Converter<base::StringPiece>::ToV8(isolate, val.spec());
}
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
GURL* out) {
@ -34,10 +30,6 @@ struct Converter<GURL> {
template<>
struct Converter<base::FilePath> {
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
const base::FilePath& val) {
return Converter<base::StringPiece>::ToV8(isolate, val.AsUTF8Unsafe());
}
static bool FromV8(v8::Isolate* isolate,
v8::Handle<v8::Value> val,
base::FilePath* out) {