From c25911db0d668120f9bbc2fab50fcd48eee53c72 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Apr 2014 16:02:19 +0800 Subject: [PATCH] Use native_mate to simplify crash_reporter api. --- atom.gyp | 1 - atom/common/api/atom_api_crash_reporter.cc | 56 ++++++++++++---------- atom/common/api/atom_api_crash_reporter.h | 29 ----------- atom/common/api/atom_api_shell.cc | 8 ---- 4 files changed, 32 insertions(+), 62 deletions(-) delete mode 100644 atom/common/api/atom_api_crash_reporter.h diff --git a/atom.gyp b/atom.gyp index 990924509b05..d40e956efc83 100644 --- a/atom.gyp +++ b/atom.gyp @@ -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', diff --git a/atom/common/api/atom_api_crash_reporter.cc b/atom/common/api/atom_api_crash_reporter.cc index 5682447d003d..ba840e36d28c 100644 --- a/atom/common/api/atom_api_crash_reporter.cc +++ b/atom/common/api/atom_api_crash_reporter.cc @@ -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 #include #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 > { + static bool FromV8(v8::Isolate* isolate, + v8::Handle val, + std::map* out) { + if (!val->IsObject()) + return false; -// static -void CrashReporter::Start(const v8::FunctionCallbackInfo& args) { - std::string product_name, company_name, submit_url; - bool auto_submit, skip_system; - std::map dict; - if (!FromV8Arguments(args, &product_name, &company_name, &submit_url, - &auto_submit, &skip_system, &dict)) - return node::ThrowTypeError("Bad argument"); + v8::Handle dict = val->ToObject(); + v8::Handle keys = dict->GetOwnPropertyNames(); + for (uint32_t i = 0; i < keys->Length(); ++i) { + v8::Handle 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 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 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) diff --git a/atom/common/api/atom_api_crash_reporter.h b/atom/common/api/atom_api_crash_reporter.h deleted file mode 100644 index f92141ba767a..000000000000 --- a/atom/common/api/atom_api_crash_reporter.h +++ /dev/null @@ -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 target); - - private: - static void Start(const v8::FunctionCallbackInfo& args); - - DISALLOW_IMPLICIT_CONSTRUCTORS(CrashReporter); -}; - -} // namespace api - -} // namespace atom - -#endif // ATOM_COMMON_API_ATOM_API_CRASH_REPORTER_H_ diff --git a/atom/common/api/atom_api_shell.cc b/atom/common/api/atom_api_shell.cc index a58bc74aaa8c..071a733f2c1d 100644 --- a/atom/common/api/atom_api_shell.cc +++ b/atom/common/api/atom_api_shell.cc @@ -15,10 +15,6 @@ namespace mate { template<> struct Converter { - static v8::Handle ToV8(v8::Isolate* isolate, - const GURL& val) { - return Converter::ToV8(isolate, val.spec()); - } static bool FromV8(v8::Isolate* isolate, v8::Handle val, GURL* out) { @@ -34,10 +30,6 @@ struct Converter { template<> struct Converter { - static v8::Handle ToV8(v8::Isolate* isolate, - const base::FilePath& val) { - return Converter::ToV8(isolate, val.AsUTF8Unsafe()); - } static bool FromV8(v8::Isolate* isolate, v8::Handle val, base::FilePath* out) {