From f146c1fe3baaf3a02612ce0a49ae40305b686fac Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 4 Jul 2013 15:54:34 +0800 Subject: [PATCH] Seperate implementation of crash reporter to standalone class. --- atom.gyp | 5 ++- ...rter_mac.mm => atom_api_crash_reporter.cc} | 27 ++++------------ browser/crash_reporter.h | 26 +++++++++++++++ browser/crash_reporter_mac.mm | 32 +++++++++++++++++++ browser/crash_reporter_win.cc | 22 +++++++++++++ 5 files changed, 90 insertions(+), 22 deletions(-) rename browser/api/{atom_api_crash_reporter_mac.mm => atom_api_crash_reporter.cc} (58%) create mode 100644 browser/crash_reporter.h create mode 100644 browser/crash_reporter_mac.mm create mode 100644 browser/crash_reporter_win.cc diff --git a/atom.gyp b/atom.gyp index 9109dc14..533ffcb1 100644 --- a/atom.gyp +++ b/atom.gyp @@ -42,7 +42,7 @@ 'browser/api/atom_api_browser_ipc.cc', 'browser/api/atom_api_browser_ipc.h', 'browser/api/atom_api_crash_reporter.h', - 'browser/api/atom_api_crash_reporter_mac.mm', + 'browser/api/atom_api_crash_reporter.cc', 'browser/api/atom_api_dialog.cc', 'browser/api/atom_api_dialog.h', 'browser/api/atom_api_event.cc', @@ -82,6 +82,9 @@ 'browser/browser.h', 'browser/browser_mac.mm', 'browser/browser_observer.h', + 'browser/crash_reporter.h', + 'browser/crash_reporter_mac.mm', + 'browser/crash_reporter_win.cc', 'browser/file_dialog.h', 'browser/file_dialog_mac.mm', 'browser/media/media_capture_devices_dispatcher.cc', diff --git a/browser/api/atom_api_crash_reporter_mac.mm b/browser/api/atom_api_crash_reporter.cc similarity index 58% rename from browser/api/atom_api_crash_reporter_mac.mm rename to browser/api/atom_api_crash_reporter.cc index ca86b204..2b23db1d 100644 --- a/browser/api/atom_api_crash_reporter_mac.mm +++ b/browser/api/atom_api_crash_reporter.cc @@ -4,9 +4,7 @@ #include "browser/api/atom_api_crash_reporter.h" -#import - -#include "base/strings/sys_string_conversions.h" +#include "browser/crash_reporter.h" #include "vendor/node/src/node.h" #include "vendor/node/src/node_internals.h" @@ -14,37 +12,24 @@ namespace atom { namespace api { -namespace { - -// Converts a V8 value to a string16. -string16 V8ValueToUTF16(v8::Handle value) { - v8::String::Value s(value); - return string16(reinterpret_cast(*s), s.length()); -} - -} // namespace - // static v8::Handle CrashReporter::SetCompanyName(const v8::Arguments &args) { - BWQuincyManager *manager = [BWQuincyManager sharedQuincyManager]; - string16 str(V8ValueToUTF16(args[0])); - [manager setCompanyName:base::SysUTF16ToNSString(str)]; + std::string name(*v8::String::Utf8Value(args[0])); + crash_reporter::CrashReporter::SetCompanyName(name); return v8::Undefined(); } // static v8::Handle CrashReporter::SetSubmissionURL( const v8::Arguments &args) { - BWQuincyManager *manager = [BWQuincyManager sharedQuincyManager]; - string16 str(V8ValueToUTF16(args[0])); - [manager setSubmissionURL:base::SysUTF16ToNSString(str)]; + std::string url(*v8::String::Utf8Value(args[0])); + crash_reporter::CrashReporter::SetSubmissionURL(url); return v8::Undefined(); } // static v8::Handle CrashReporter::SetAutoSubmit(const v8::Arguments &args) { - BWQuincyManager *manager = [BWQuincyManager sharedQuincyManager]; - [manager setAutoSubmitCrashReport:args[0]->BooleanValue()]; + crash_reporter::CrashReporter::SetAutoSubmit(args[0]->BooleanValue()); return v8::Undefined(); } diff --git a/browser/crash_reporter.h b/browser/crash_reporter.h new file mode 100644 index 00000000..14b6c7ad --- /dev/null +++ b/browser/crash_reporter.h @@ -0,0 +1,26 @@ +// 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_BROWSER_CRASH_REPORTER_H_ +#define ATOM_BROWSER_CRASH_REPORTER_H_ + +#include + +#include "base/basictypes.h" + +namespace crash_reporter { + +class CrashReporter { + public: + static void SetCompanyName(const std::string& name); + static void SetSubmissionURL(const std::string& url); + static void SetAutoSubmit(bool yes); + + private: + DISALLOW_IMPLICIT_CONSTRUCTORS(CrashReporter); +}; + +} // namespace crash_reporter + +#endif // ATOM_BROWSER_CRASH_REPORTER_H_ diff --git a/browser/crash_reporter_mac.mm b/browser/crash_reporter_mac.mm new file mode 100644 index 00000000..90e709ad --- /dev/null +++ b/browser/crash_reporter_mac.mm @@ -0,0 +1,32 @@ +// 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. + +#include "browser/crash_reporter.h" + +#import + +#include "base/strings/sys_string_conversions.h" + +namespace crash_reporter { + +// static +void CrashReporter::SetCompanyName(const std::string& name) { + BWQuincyManager *manager = [BWQuincyManager sharedQuincyManager]; + [manager setCompanyName:base::SysUTF8ToNSString(name)]; +} + +// static +void CrashReporter::SetSubmissionURL(const std::string& url) { + BWQuincyManager *manager = [BWQuincyManager sharedQuincyManager]; + [manager setSubmissionURL:base::SysUTF8ToNSString(name)]; + return v8::Undefined(); +} + +// static +void CrashReporter::SetAutoSubmit(bool yes) { + BWQuincyManager *manager = [BWQuincyManager sharedQuincyManager]; + [manager setAutoSubmitCrashReport:yes]; +} + +} // namespace crash_reporter diff --git a/browser/crash_reporter_win.cc b/browser/crash_reporter_win.cc new file mode 100644 index 00000000..ca3c7e6f --- /dev/null +++ b/browser/crash_reporter_win.cc @@ -0,0 +1,22 @@ +// 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. + +#include "browser/crash_reporter.h" + +namespace crash_reporter { + +// static +void CrashReporter::SetCompanyName(const std::string& name) { +} + +// static +void CrashReporter::SetSubmissionURL(const std::string& url) { +} + +// static +void CrashReporter::SetAutoSubmit(bool yes) { +} + +} // namespace crash_reporter + -- 2.43.0