Skip to content

Commit

Permalink
Add support for attachments to generic crash report database
Browse files Browse the repository at this point in the history
This is the beginning of support for attachments at the process level
being stored alongside a report. Attachments will be uploaded by key as
part of the multipart http upload. There's no interface at the client
level yet to pass these through.

As this is intended for Fuchsia, this is not yet implemented for the
Mac/Windows database implementations.

Bug: crashpad:196
Change-Id: Ieaf580675164b631d313193f97375710979ba2a9
Reviewed-on: https://chromium-review.googlesource.com/1060419
Commit-Queue: Scott Graham <[email protected]>
Reviewed-by: Joshua Peraza <[email protected]>
  • Loading branch information
sgraham authored and Commit Bot committed May 18, 2018
1 parent 75b672b commit 1f3052c
Show file tree
Hide file tree
Showing 10 changed files with 380 additions and 15 deletions.
18 changes: 16 additions & 2 deletions client/crash_report_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "client/crash_report_database.h"

#include "base/logging.h"
#include "build/build_config.h"

namespace crashpad {
Expand All @@ -29,13 +30,21 @@ CrashReportDatabase::Report::Report()
upload_explicitly_requested(false) {}

CrashReportDatabase::NewReport::NewReport()
: writer_(std::make_unique<FileWriter>()), uuid_(), file_remover_() {}
: writer_(std::make_unique<FileWriter>()),
file_remover_(),
attachment_writers_(),
attachment_removers_(),
uuid_(),
database_() {}

CrashReportDatabase::NewReport::~NewReport() = default;

bool CrashReportDatabase::NewReport::Initialize(
CrashReportDatabase* database,
const base::FilePath& directory,
const base::FilePath::StringType& extension) {
database_ = database;

if (!uuid_.InitializeWithNew()) {
return false;
}
Expand All @@ -56,7 +65,11 @@ bool CrashReportDatabase::NewReport::Initialize(
}

CrashReportDatabase::UploadReport::UploadReport()
: Report(), reader_(std::make_unique<FileReader>()), database_(nullptr) {}
: Report(),
reader_(std::make_unique<FileReader>()),
database_(nullptr),
attachment_readers_(),
attachment_map_() {}

CrashReportDatabase::UploadReport::~UploadReport() {
if (database_) {
Expand All @@ -67,6 +80,7 @@ CrashReportDatabase::UploadReport::~UploadReport() {
bool CrashReportDatabase::UploadReport::Initialize(const base::FilePath path,
CrashReportDatabase* db) {
database_ = db;
InitializeAttachments();
return reader_->Open(path);
}

Expand Down
36 changes: 32 additions & 4 deletions client/crash_report_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <time.h>

#include <map>
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -112,19 +113,35 @@ class CrashReportDatabase {

//! A unique identifier by which this report will always be known to the
//! database.
const UUID& ReportID() { return uuid_; }
const UUID& ReportID() const { return uuid_; }

//! \brief Adds an attachment to the report.
//!
//! \note This function is not yet implemented on macOS or Windows.
//!
//! \param[in] name The key and name for the attachment, which will be
//! included in the http upload. The attachment will not appear in the
//! minidump report. \a name should only use characters from the set
//! `[a-zA-Z0-9._-]`.
//! \return A FileWriter that the caller should use to write the contents of
//! the attachment, or `nullptr` on failure with an error logged.
FileWriter* AddAttachment(const std::string& name);

private:
friend class CrashReportDatabaseGeneric;
friend class CrashReportDatabaseMac;
friend class CrashReportDatabaseWin;

bool Initialize(const base::FilePath& directory,
bool Initialize(CrashReportDatabase* database,
const base::FilePath& directory,
const base::FilePath::StringType& extension);

std::unique_ptr<FileWriter> writer_;
UUID uuid_;
ScopedRemoveFile file_remover_;
std::vector<std::unique_ptr<FileWriter>> attachment_writers_;
std::vector<ScopedRemoveFile> attachment_removers_;
UUID uuid_;
CrashReportDatabase* database_;

DISALLOW_COPY_AND_ASSIGN(NewReport);
};
Expand All @@ -137,19 +154,30 @@ class CrashReportDatabase {
UploadReport();
virtual ~UploadReport();

// An open FileReader with which to read the report.
//! \brief An open FileReader with which to read the report.
FileReader* Reader() const { return reader_.get(); }

//! \brief Obtains a mapping of names to file readers for any attachments
//! for the report.
//!
//! This is not implemented on macOS or Windows.
std::map<std::string, FileReader*> GetAttachments() const {
return attachment_map_;
};

private:
friend class CrashReportDatabase;
friend class CrashReportDatabaseGeneric;
friend class CrashReportDatabaseMac;
friend class CrashReportDatabaseWin;

bool Initialize(const base::FilePath path, CrashReportDatabase* database);
void InitializeAttachments();

std::unique_ptr<FileReader> reader_;
CrashReportDatabase* database_;
std::vector<std::unique_ptr<FileReader>> attachment_readers_;
std::map<std::string, FileReader*> attachment_map_;

DISALLOW_COPY_AND_ASSIGN(UploadReport);
};
Expand Down
Loading

0 comments on commit 1f3052c

Please sign in to comment.