1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-24 16:31:22 +01:00

Split the crashreporting.cpp into separate files for different platforms (only Linux works right now... maybe mac)

This commit is contained in:
David Sansome 2012-11-25 19:35:38 +11:00
parent dbeae392b9
commit 2ae7008236
9 changed files with 210 additions and 82 deletions

View File

@ -818,7 +818,10 @@ optional_source(HAVE_SPOTIFY_DOWNLOADER
optional_source(APPLE
INCLUDE_DIRECTORIES
${GROWL}/Headers
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/google-breakpad/client/mac/build/Release/Breakpad.framework
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/google-breakpad/client/mac
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/google-breakpad/client/mac/Framework
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/google-breakpad/client/apple
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/google-breakpad/client/apple/Framework
SOURCES
core/macfslistener.mm
core/macglobalshortcutbackend.mm
@ -1088,6 +1091,19 @@ optional_source(LINUX
HEADERS core/ubuntuunityhack.h
)
# Breakpad source files
if(HAVE_BREAKPAD)
if(LINUX)
list(APPEND SOURCES core/crashreporting_linux.cpp)
elseif(APPLE)
list(APPEND SOURCES core/crashreporting_mac.cpp)
else()
list(APPEND SOURCES core/crashreporting_win.cpp)
endif()
else()
list(APPEND SOURCES core/crashreporting_empty.cpp)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
@ -1191,14 +1207,7 @@ if(HAVE_LIBINDICATE)
endif(HAVE_LIBINDICATE)
if(HAVE_BREAKPAD)
if (LINUX)
target_link_libraries(clementine_lib breakpad)
elseif (APPLE)
add_dependencies(clementine_lib breakpad)
target_link_libraries(clementine_lib
"-F${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/google-breakpad/client/mac/build/Release"
"-framework Breakpad")
endif (LINUX)
target_link_libraries(clementine_lib breakpad)
endif(HAVE_BREAKPAD)
if(HAVE_SPOTIFY)

View File

@ -20,7 +20,6 @@
#include "core/logging.h"
#include <QApplication>
#include <QDir>
#include <QFile>
#include <QMessageBox>
#include <QNetworkAccessManager>
@ -30,9 +29,8 @@
#include <QUrl>
#include <QtDebug>
#if defined(HAVE_BREAKPAD) and defined(Q_OS_LINUX)
# include "client/linux/handler/exception_handler.h"
# include "third_party/lss/linux_syscall_support.h"
#if QT_VERSION >= 0x040800
#include <QHttpMultiPart>
#endif
@ -40,16 +38,6 @@ const char* CrashSender::kUploadURL = "http://crashes.clementine-player.org/getu
const char* CrashReporting::kSendCrashReportOption = "--send-crash-report";
char* CrashReporting::sPath = NULL;
#if defined(HAVE_BREAKPAD) and defined(Q_OS_LINUX)
CrashReporting::CrashReporting()
: handler_(new google_breakpad::ExceptionHandler(
QDir::tempPath().toLocal8Bit().constData(), NULL,
CrashReporting::Handler, this, true)) {
}
CrashReporting::~CrashReporting() {
}
bool CrashReporting::SendCrashReport(int argc, char** argv) {
if (argc != 4 || strcmp(argv[1], kSendCrashReportOption) != 0) {
@ -70,33 +58,6 @@ void CrashReporting::SetApplicationPath(const QString& path) {
sPath = strdup(path.toLocal8Bit().constData());
}
void CrashReporting::Print(const char* message) {
if (message) {
sys_write(1, message, strlen(message));
}
}
bool CrashReporting::Handler(const char* dump_path,
const char* minidump_id,
void* context,
bool succeeded) {
Print("Clementine has crashed! A crash report has been saved to:\n ");
Print(dump_path);
Print("/");
Print(minidump_id);
Print("\n\nPlease send this to the developers so they can fix the problem:\n"
" http://code.google.com/p/clementine-player/issues/entry\n\n");
if (sPath) {
// We know the path to clementine, so exec it again to prompt the user to
// upload the report.
const char* argv[] = {sPath, kSendCrashReportOption, dump_path, minidump_id, NULL};
sys_execv(sPath, argv);
}
return true;
}
CrashSender::CrashSender(const QString& path)
: network_(new QNetworkAccessManager(this)),
@ -112,10 +73,10 @@ bool CrashSender::Start() {
}
// No tr() here.
QMessageBox prompt(QMessageBox::Critical, "Clementine has crashed!", QString(
"A crash report has been created and saved to '%1'. With your permission "
"it can be automatically sent to our server so the developers can find "
"out what happened.").arg(path_));
QMessageBox prompt(QMessageBox::Warning, "Clementine has crashed!",
"Clementine has crashed! A crash report has been created and saved to "
"disk. With your permission it can be automatically sent to our server "
"so the developers can find out what happened.");
prompt.addButton("Don't send", QMessageBox::RejectRole);
prompt.addButton("Send crash report", QMessageBox::AcceptRole);
if (prompt.exec() == QDialog::Rejected) {
@ -143,10 +104,27 @@ void CrashSender::RedirectFinished() {
QUrl url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
if (!url.isValid()) {
printf("Response didn't have a redirection target - HTTP %d\n",
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt());
progress_->close();
return;
}
printf("Uploading crash report to %s\n", url.toEncoded().constData());
QNetworkRequest req(url);
#if QT_VERSION >= 0x040800
QHttpPart part;
part.setHeader(QNetworkRequest::ContentDispositionHeader,
"form-data; name=\"data\", filename=\"data.dmp\"");
part.setBodyDevice(file_);
QHttpMultiPart* multi_part = new QHttpMultiPart(QHttpMultiPart::FormDataType);
multi_part->append(part);
reply = network_->post(req, multi_part);
#else
// Read the file's data
QByteArray file_data = file_->readAll();
@ -159,8 +137,8 @@ void CrashSender::RedirectFinished() {
}
}
QNetworkRequest req(url);
req.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=" + boundary);
req.setHeader(QNetworkRequest::ContentTypeHeader,
QString("multipart/form-data; boundary=" + boundary));
// Construct the multipart/form-data
QByteArray form_data;
@ -178,31 +156,13 @@ void CrashSender::RedirectFinished() {
// Upload the data
reply = network_->post(req, form_data);
connect(reply, SIGNAL(uploadProgress(qint64,qint64)), SLOT(UploadProgress(qint64)));
#endif
connect(reply, SIGNAL(uploadProgress(qint64,qint64)), SLOT(UploadProgress(qint64,qint64)));
connect(reply, SIGNAL(finished()), progress_, SLOT(close()));
}
void CrashSender::UploadProgress(qint64 bytes) {
void CrashSender::UploadProgress(qint64 bytes, qint64 total) {
printf("Uploaded %lld of %lld bytes\n", bytes, total);
progress_->setValue(bytes);
}
#else // HAVE_BREAKPAD
namespace google_breakpad {
class ExceptionHandler {};
}
CrashReporting::CrashReporting() {
}
CrashReporting::~CrashReporting() {
}
bool CrashReporting::SendCrashReport(int, char**) {
return false;
}
void CrashReporting::SetApplicationPath(const QString&) {
}
#endif // HAVE_BREAKPAD

View File

@ -82,7 +82,7 @@ public:
private slots:
void RedirectFinished();
void UploadProgress(qint64 bytes);
void UploadProgress(qint64 bytes, qint64 total);
private:
static const char* kUploadURL;

View File

@ -0,0 +1,38 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "crashreporting.h"
namespace google_breakpad {
class ExceptionHandler {};
}
CrashReporting::CrashReporting() {
}
CrashReporting::~CrashReporting() {
}
bool CrashReporting::Handler(const char* dump_path,
const char* minidump_id,
void* context,
bool succeeded) {
}
#endif // HAVE_BREAKPAD

View File

@ -0,0 +1,56 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "crashreporting.h"
#include "core/logging.h"
#include <QDir>
#include "client/linux/handler/exception_handler.h"
#include "third_party/lss/linux_syscall_support.h"
CrashReporting::CrashReporting()
: handler_(new google_breakpad::ExceptionHandler(
QDir::tempPath().toLocal8Bit().constData(), NULL,
CrashReporting::Handler, this, true)) {
}
CrashReporting::~CrashReporting() {
}
bool CrashReporting::Handler(const char* dump_path,
const char* minidump_id,
void* context,
bool succeeded) {
Print("Clementine has crashed! A crash report has been saved to:\n ");
Print(dump_path);
Print("/");
Print(minidump_id);
Print("\n\nPlease send this to the developers so they can fix the problem:\n"
" http://code.google.com/p/clementine-player/issues/entry\n\n");
if (sPath) {
// We know the path to clementine, so exec it again to prompt the user to
// upload the report.
const char* argv[] = {sPath, kSendCrashReportOption, dump_path, minidump_id, NULL};
sys_execv(sPath, argv);
}
return true;
}

View File

@ -0,0 +1,64 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "crashreporting.h"
#include "core/logging.h"
#include <sys/syscall.h>
#include <QDir>
#include "client/mac/handler/exception_handler.h"
CrashReporting::CrashReporting()
: handler_(new google_breakpad::ExceptionHandler(
QDir::tempPath().toLocal8Bit().constData(), NULL,
CrashReporting::Handler, this, true, NULL)) {
}
CrashReporting::~CrashReporting() {
}
void CrashReporting::Print(const char* message) {
if (message) {
syscall(SYS_write, 1, message, strlen(message));
}
}
bool CrashReporting::Handler(const char* dump_path,
const char* minidump_id,
void* context,
bool succeeded) {
Print("Clementine has crashed! A crash report has been saved to:\n ");
Print(dump_path);
Print("/");
Print(minidump_id);
Print("\n\nPlease send this to the developers so they can fix the problem:\n"
" http://code.google.com/p/clementine-player/issues/entry\n\n");
if (sPath) {
// We know the path to clementine, so exec it again to prompt the user to
// upload the report.
const char* argv[] = {sPath, kSendCrashReportOption, dump_path, minidump_id, NULL};
syscall(SYS_execve, sPath, argv, NULL);
}
return true;
}

View File

@ -4,7 +4,7 @@
#include "macglobalshortcutbackend.h"
#ifdef HAVE_BREAKPAD
#import <Breakpad/Breakpad.h>
#import <Framework/Breakpad.h>
#endif

View File

@ -100,7 +100,6 @@ static BreakpadRef InitBreakpad() {
breakpad = BreakpadCreate(plist);
BreakpadSetFilterCallback(breakpad, &BreakpadCallback, NULL);
}
[pool release];
return breakpad;
}
#endif // HAVE_BREAKPAD

View File

@ -406,6 +406,8 @@ int main(int argc, char *argv[]) {
qtsparkle::LoadTranslations(language);
#endif
*reinterpret_cast<int*>(0) = 0;
// Icons
IconLoader::Init();