2013-07-04 07:54:34 +00:00
|
|
|
// 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.
|
|
|
|
|
2013-11-13 09:29:35 +00:00
|
|
|
#include "common/crash_reporter/crash_reporter.h"
|
2013-07-04 07:54:34 +00:00
|
|
|
|
2013-11-13 09:20:13 +00:00
|
|
|
#include "browser/browser.h"
|
|
|
|
#include "base/mac/mac_util.h"
|
2013-07-04 07:54:34 +00:00
|
|
|
#include "base/strings/sys_string_conversions.h"
|
2013-11-13 08:48:30 +00:00
|
|
|
#include "common/atom_version.h"
|
|
|
|
#import "vendor/breakpad/src/client/apple/Framework/BreakpadDefines.h"
|
|
|
|
#import "vendor/breakpad/src/client/mac/Framework/Breakpad.h"
|
2013-07-04 07:54:34 +00:00
|
|
|
|
|
|
|
namespace crash_reporter {
|
|
|
|
|
2013-11-13 08:48:30 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ScopedCrashReporter {
|
|
|
|
public:
|
2013-11-13 09:20:13 +00:00
|
|
|
ScopedCrashReporter() : is_browser_(!base::mac::IsBackgroundOnlyProcess()) {
|
2013-11-13 08:48:30 +00:00
|
|
|
NSMutableDictionary* parameters =
|
|
|
|
[NSMutableDictionary dictionaryWithCapacity:4];
|
|
|
|
[parameters setValue:@"GitHub, Inc" forKey:@BREAKPAD_VENDOR];
|
2013-11-13 09:20:13 +00:00
|
|
|
|
|
|
|
if (is_browser_) {
|
2013-11-13 11:06:11 +00:00
|
|
|
[parameters setValue:@"Atom-Shell" forKey:@BREAKPAD_PRODUCT];
|
|
|
|
// Use application's version for crashes in browser.
|
2013-11-13 09:20:13 +00:00
|
|
|
std::string version = atom::Browser::Get()->GetVersion();
|
|
|
|
[parameters setValue:base::SysUTF8ToNSString(version)
|
|
|
|
forKey:@BREAKPAD_VERSION];
|
|
|
|
} else {
|
2013-11-13 11:06:11 +00:00
|
|
|
[parameters setValue:@"Atom-Shell Renderer" forKey:@BREAKPAD_PRODUCT];
|
2013-11-13 09:20:13 +00:00
|
|
|
[parameters setValue:@ATOM_VERSION_STRING forKey:@BREAKPAD_VERSION];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report all crashes (important for testing the crash reporter).
|
2013-11-13 08:48:30 +00:00
|
|
|
[parameters setValue:@"0" forKey:@BREAKPAD_REPORT_INTERVAL];
|
2013-11-13 09:20:13 +00:00
|
|
|
|
|
|
|
// Let the crash reporter log everything in Console.app.
|
|
|
|
[parameters setValue:@"NO" forKey:@BREAKPAD_SEND_AND_EXIT];
|
|
|
|
|
|
|
|
// Send the report by default.
|
|
|
|
[parameters setValue:@"YES" forKey:@BREAKPAD_SKIP_CONFIRM];
|
|
|
|
|
|
|
|
// Use my server as /dev/null if not specified.
|
2013-11-13 08:48:30 +00:00
|
|
|
[parameters setValue:@"http://54.249.141.255" forKey:@BREAKPAD_URL];
|
|
|
|
|
|
|
|
breakpad_ = BreakpadCreate(parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
~ScopedCrashReporter() { if (breakpad_) BreakpadRelease(breakpad_); }
|
|
|
|
|
2013-11-13 11:06:11 +00:00
|
|
|
bool is_browser() const { return is_browser_; }
|
|
|
|
|
2013-11-13 08:48:30 +00:00
|
|
|
void SetKey(const std::string& key, const std::string& value) {
|
|
|
|
BreakpadSetKeyValue(breakpad_,
|
|
|
|
base::SysUTF8ToNSString(key),
|
|
|
|
base::SysUTF8ToNSString(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ScopedCrashReporter* Get() {
|
|
|
|
if (g_scoped_crash_reporter_ == NULL)
|
|
|
|
g_scoped_crash_reporter_ = new ScopedCrashReporter();
|
|
|
|
return g_scoped_crash_reporter_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BreakpadRef breakpad_;
|
2013-11-13 09:20:13 +00:00
|
|
|
bool is_browser_;
|
2013-11-13 08:48:30 +00:00
|
|
|
|
|
|
|
static ScopedCrashReporter* g_scoped_crash_reporter_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ScopedCrashReporter);
|
|
|
|
};
|
|
|
|
|
|
|
|
ScopedCrashReporter* ScopedCrashReporter::g_scoped_crash_reporter_ = NULL;
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-11-13 11:12:13 +00:00
|
|
|
// static
|
|
|
|
void CrashReporter::SetProductName(const std::string& name) {
|
|
|
|
ScopedCrashReporter* reporter = ScopedCrashReporter::Get();
|
|
|
|
if (reporter->is_browser())
|
|
|
|
ScopedCrashReporter::Get()->SetKey(BREAKPAD_PRODUCT_DISPLAY, name);
|
|
|
|
else
|
|
|
|
ScopedCrashReporter::Get()->SetKey(BREAKPAD_PRODUCT_DISPLAY,
|
|
|
|
name + " Renderer");
|
|
|
|
}
|
|
|
|
|
2013-07-04 07:54:34 +00:00
|
|
|
// static
|
|
|
|
void CrashReporter::SetCompanyName(const std::string& name) {
|
2013-11-13 08:48:30 +00:00
|
|
|
ScopedCrashReporter::Get()->SetKey(BREAKPAD_VENDOR, name);
|
2013-07-04 07:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CrashReporter::SetSubmissionURL(const std::string& url) {
|
2013-11-13 08:48:30 +00:00
|
|
|
ScopedCrashReporter::Get()->SetKey(BREAKPAD_URL, url);
|
2013-07-04 07:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CrashReporter::SetAutoSubmit(bool yes) {
|
2013-11-13 08:48:30 +00:00
|
|
|
ScopedCrashReporter::Get()->SetKey(BREAKPAD_SKIP_CONFIRM, yes ? "YES" : "NO");
|
2013-07-04 07:54:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace crash_reporter
|