Update crashpad implementation after code review.

This commit is contained in:
Haojian Wu 2015-06-02 11:41:47 +08:00
parent 51d5ef9d86
commit 317406f26d
3 changed files with 31 additions and 27 deletions

View file

@ -9,9 +9,16 @@
#include "atom/common/crash_reporter/crash_reporter.h" #include "atom/common/crash_reporter/crash_reporter.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_piece.h"
#include "vendor/crashpad/client/simple_string_dictionary.h"
template <typename T> struct DefaultSingletonTraits; template <typename T> struct DefaultSingletonTraits;
namespace crashpad {
class CrashReportDatabase;
}
namespace crash_reporter { namespace crash_reporter {
class CrashReporterMac : public CrashReporter { class CrashReporterMac : public CrashReporter {
@ -32,6 +39,13 @@ class CrashReporterMac : public CrashReporter {
CrashReporterMac(); CrashReporterMac();
virtual ~CrashReporterMac(); virtual ~CrashReporterMac();
void SetUploadsEnabled(bool enable_uploads);
void SetCrashKeyValue(const base::StringPiece& key,
const base::StringPiece& value);
scoped_ptr<crashpad::SimpleStringDictionary> simple_string_dictionary_;
scoped_ptr<crashpad::CrashReportDatabase> crash_report_database_;
DISALLOW_COPY_AND_ASSIGN(CrashReporterMac); DISALLOW_COPY_AND_ASSIGN(CrashReporterMac);
}; };

View file

@ -19,25 +19,6 @@
namespace crash_reporter { namespace crash_reporter {
namespace {
crashpad::SimpleStringDictionary* g_simple_string_dictionary;
crashpad::CrashReportDatabase* g_database;
void SetUploadsEnabled(bool enable_uploads) {
if (g_database) {
crashpad::Settings* settings = g_database->GetSettings();
settings->SetUploadsEnabled(enable_uploads);
}
}
void SetCrashKeyValue(const base::StringPiece& key,
const base::StringPiece& value) {
g_simple_string_dictionary->SetKeyValue(key.data(), value.data());
}
} // namespace
CrashReporterMac::CrashReporterMac() { CrashReporterMac::CrashReporterMac() {
} }
@ -64,12 +45,10 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
framework_bundle_path.Append("Resources").Append("crashpad_handler"); framework_bundle_path.Append("Resources").Append("crashpad_handler");
crashpad::CrashpadClient crashpad_client; crashpad::CrashpadClient crashpad_client;
// Send all crash reports.
std::vector<std::string> arguments = { "--upload-internal=0" };
if (crashpad_client.StartHandler(handler_path, database_path, if (crashpad_client.StartHandler(handler_path, database_path,
submit_url, submit_url,
StringMap(), StringMap(),
arguments)) { std::vector<std::string>())) {
crashpad_client.UseHandler(); crashpad_client.UseHandler();
} }
} // @autoreleasepool } // @autoreleasepool
@ -82,8 +61,8 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
crashpad::TriState::kDisabled); crashpad::TriState::kDisabled);
} }
g_simple_string_dictionary = new crashpad::SimpleStringDictionary(); simple_string_dictionary_.reset(new crashpad::SimpleStringDictionary());
crashpad_info->set_simple_annotations(g_simple_string_dictionary); crashpad_info->set_simple_annotations(simple_string_dictionary_.get());
SetCrashKeyValue("prod", ATOM_PRODUCT_NAME); SetCrashKeyValue("prod", ATOM_PRODUCT_NAME);
SetCrashKeyValue("process_type", is_browser_ ? base::StringPiece("browser") SetCrashKeyValue("process_type", is_browser_ ? base::StringPiece("browser")
@ -95,8 +74,8 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name,
SetCrashKeyValue(iter->first, iter->second); SetCrashKeyValue(iter->first, iter->second);
} }
if (is_browser_) { if (is_browser_) {
g_database = crash_report_database_ = crashpad::CrashReportDatabase::Initialize(
crashpad::CrashReportDatabase::Initialize(database_path).release(); database_path);
SetUploadsEnabled(auto_submit); SetUploadsEnabled(auto_submit);
} }
} }
@ -105,6 +84,18 @@ void CrashReporterMac::SetUploadParameters() {
upload_parameters_["platform"] = "darwin"; upload_parameters_["platform"] = "darwin";
} }
void CrashReporterMac::SetUploadsEnabled(bool enable_uploads) {
if (crash_report_database_) {
crashpad::Settings* settings = crash_report_database_->GetSettings();
settings->SetUploadsEnabled(enable_uploads);
}
}
void CrashReporterMac::SetCrashKeyValue(const base::StringPiece& key,
const base::StringPiece& value) {
simple_string_dictionary_->SetKeyValue(key.data(), value.data());
}
// static // static
CrashReporterMac* CrashReporterMac::GetInstance() { CrashReporterMac* CrashReporterMac::GetInstance() {
return Singleton<CrashReporterMac>::get(); return Singleton<CrashReporterMac>::get();

View file

@ -30,7 +30,6 @@
'v8_enable_i18n_support': 'false', 'v8_enable_i18n_support': 'false',
# Required by Linux (empty for now, should support it in future). # Required by Linux (empty for now, should support it in future).
'sysroot': '', 'sysroot': '',
'crashpad_standalone': 1,
}, },
# Settings to compile node under Windows. # Settings to compile node under Windows.
'target_defaults': { 'target_defaults': {