2022-09-06 19:14:07 -04:00
|
|
|
|
// Copyright 2015 The Crashpad Authors
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
#ifndef CRASHPAD_CLIENT_CRASH_REPORT_DATABASE_H_
|
|
|
|
|
#define CRASHPAD_CLIENT_CRASH_REPORT_DATABASE_H_
|
|
|
|
|
|
2019-03-13 14:53:16 -07:00
|
|
|
|
#include <stdint.h>
|
2015-01-26 15:59:01 -05:00
|
|
|
|
#include <time.h>
|
|
|
|
|
|
2018-05-18 15:53:54 -07:00
|
|
|
|
#include <map>
|
2016-04-25 12:13:07 -07:00
|
|
|
|
#include <memory>
|
2015-01-26 15:59:01 -05:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
|
#include "util/file/file_io.h"
|
2018-02-15 08:17:12 -08:00
|
|
|
|
#include "util/file/file_reader.h"
|
2018-02-13 17:28:11 -08:00
|
|
|
|
#include "util/file/file_writer.h"
|
|
|
|
|
#include "util/file/scoped_remove_file.h"
|
2016-09-26 15:06:19 -07:00
|
|
|
|
#include "util/misc/metrics.h"
|
2015-01-26 15:59:01 -05:00
|
|
|
|
#include "util/misc/uuid.h"
|
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
2015-03-09 18:47:52 -04:00
|
|
|
|
class Settings;
|
|
|
|
|
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//! \brief An interface for managing a collection of crash report files and
|
|
|
|
|
//! metadata associated with the crash reports.
|
|
|
|
|
//!
|
|
|
|
|
//! All Report objects that are returned by this class are logically const.
|
|
|
|
|
//! They are snapshots of the database at the time the query was run, and the
|
|
|
|
|
//! data returned is liable to change after the query is executed.
|
|
|
|
|
//!
|
|
|
|
|
//! The lifecycle of a crash report has three stages:
|
|
|
|
|
//!
|
|
|
|
|
//! 1. New: A crash report is created with PrepareNewCrashReport(), the
|
|
|
|
|
//! the client then writes the report, and then calls
|
|
|
|
|
//! FinishedWritingCrashReport() to make the report Pending.
|
|
|
|
|
//! 2. Pending: The report has been written but has not been locally
|
2016-08-24 15:37:46 -04:00
|
|
|
|
//! processed, or it was has been brought back from 'Completed' state by
|
|
|
|
|
//! user request.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//! 3. Completed: The report has been locally processed, either by uploading
|
2018-02-15 08:17:12 -08:00
|
|
|
|
//! it to a collection server and calling RecordUploadComplete(), or by
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//! calling SkipReportUpload().
|
|
|
|
|
class CrashReportDatabase {
|
|
|
|
|
public:
|
|
|
|
|
//! \brief A crash report record.
|
|
|
|
|
//!
|
|
|
|
|
//! This represents the metadata for a crash report, as well as the location
|
|
|
|
|
//! of the report itself. A CrashReportDatabase maintains at least this
|
|
|
|
|
//! information.
|
|
|
|
|
struct Report {
|
|
|
|
|
Report();
|
|
|
|
|
|
|
|
|
|
//! A unique identifier by which this report will always be known to the
|
|
|
|
|
//! database.
|
|
|
|
|
UUID uuid;
|
|
|
|
|
|
|
|
|
|
//! The current location of the crash report on the client’s filesystem.
|
|
|
|
|
//! The location of a crash report may change over time, so the UUID should
|
|
|
|
|
//! be used as the canonical identifier.
|
|
|
|
|
base::FilePath file_path;
|
|
|
|
|
|
|
|
|
|
//! An identifier issued to this crash report by a collection server.
|
|
|
|
|
std::string id;
|
|
|
|
|
|
|
|
|
|
//! The time at which the report was generated.
|
|
|
|
|
time_t creation_time;
|
|
|
|
|
|
|
|
|
|
//! Whether this crash report was successfully uploaded to a collection
|
|
|
|
|
//! server.
|
|
|
|
|
bool uploaded;
|
|
|
|
|
|
|
|
|
|
//! The last timestamp at which an attempt was made to submit this crash
|
|
|
|
|
//! report to a collection server. If this is zero, then the report has
|
|
|
|
|
//! never been uploaded. If #uploaded is true, then this timestamp is the
|
|
|
|
|
//! time at which the report was uploaded, and no other attempts to upload
|
|
|
|
|
//! this report will be made.
|
|
|
|
|
time_t last_upload_attempt_time;
|
|
|
|
|
|
|
|
|
|
//! The number of times an attempt was made to submit this report to
|
|
|
|
|
//! a collection server. If this is more than zero, then
|
|
|
|
|
//! #last_upload_attempt_time will be set to the timestamp of the most
|
|
|
|
|
//! recent attempt.
|
|
|
|
|
int upload_attempts;
|
2016-08-24 15:37:46 -04:00
|
|
|
|
|
|
|
|
|
//! Whether this crash report was explicitly requested by user to be
|
|
|
|
|
//! uploaded. This can be true only if report is in the 'pending' state.
|
|
|
|
|
bool upload_explicitly_requested;
|
2019-03-13 14:53:16 -07:00
|
|
|
|
|
|
|
|
|
//! The total size in bytes taken by the report, including any potential
|
|
|
|
|
//! attachments.
|
|
|
|
|
uint64_t total_size;
|
2015-01-26 15:59:01 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//! \brief A crash report that is in the process of being written.
|
|
|
|
|
//!
|
2018-02-15 08:17:12 -08:00
|
|
|
|
//! An instance of this class should be created via PrepareNewCrashReport().
|
2018-02-13 17:28:11 -08:00
|
|
|
|
class NewReport {
|
|
|
|
|
public:
|
|
|
|
|
NewReport();
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
|
|
NewReport(const NewReport&) = delete;
|
|
|
|
|
NewReport& operator=(const NewReport&) = delete;
|
|
|
|
|
|
2018-02-13 17:28:11 -08:00
|
|
|
|
~NewReport();
|
|
|
|
|
|
2020-01-24 10:36:14 -08:00
|
|
|
|
//! \brief An open FileWriter with which to write the report.
|
2018-02-13 17:28:11 -08:00
|
|
|
|
FileWriter* Writer() const { return writer_.get(); }
|
2015-01-26 15:59:01 -05:00
|
|
|
|
|
2020-01-24 10:36:14 -08:00
|
|
|
|
//! \brief Returns a FileReaderInterface to the report, or `nullptr` with a
|
|
|
|
|
//! message logged.
|
|
|
|
|
FileReaderInterface* Reader();
|
|
|
|
|
|
2015-03-13 13:00:56 -04:00
|
|
|
|
//! A unique identifier by which this report will always be known to the
|
|
|
|
|
//! database.
|
2018-05-18 15:53:54 -07:00
|
|
|
|
const UUID& ReportID() const { return uuid_; }
|
|
|
|
|
|
|
|
|
|
//! \brief Adds an attachment to the report.
|
|
|
|
|
//!
|
|
|
|
|
//! \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);
|
2015-01-26 15:59:01 -05:00
|
|
|
|
|
2018-02-13 17:28:11 -08:00
|
|
|
|
private:
|
2018-02-15 11:10:10 -08:00
|
|
|
|
friend class CrashReportDatabaseGeneric;
|
2018-02-13 17:28:11 -08:00
|
|
|
|
friend class CrashReportDatabaseMac;
|
|
|
|
|
friend class CrashReportDatabaseWin;
|
2015-04-03 18:57:01 -04:00
|
|
|
|
|
2018-05-18 15:53:54 -07:00
|
|
|
|
bool Initialize(CrashReportDatabase* database,
|
|
|
|
|
const base::FilePath& directory,
|
2018-02-13 17:28:11 -08:00
|
|
|
|
const base::FilePath::StringType& extension);
|
2015-04-03 18:57:01 -04:00
|
|
|
|
|
2018-02-13 17:28:11 -08:00
|
|
|
|
std::unique_ptr<FileWriter> writer_;
|
2020-01-24 10:36:14 -08:00
|
|
|
|
std::unique_ptr<FileReader> reader_;
|
2018-02-13 17:28:11 -08:00
|
|
|
|
ScopedRemoveFile file_remover_;
|
2018-05-18 15:53:54 -07:00
|
|
|
|
std::vector<std::unique_ptr<FileWriter>> attachment_writers_;
|
|
|
|
|
std::vector<ScopedRemoveFile> attachment_removers_;
|
|
|
|
|
UUID uuid_;
|
|
|
|
|
CrashReportDatabase* database_;
|
2015-04-03 18:57:01 -04:00
|
|
|
|
};
|
|
|
|
|
|
2018-02-15 08:17:12 -08:00
|
|
|
|
//! \brief A crash report that is in the process of being uploaded.
|
|
|
|
|
//!
|
|
|
|
|
//! An instance of this class should be created via GetReportForUploading().
|
|
|
|
|
class UploadReport : public Report {
|
|
|
|
|
public:
|
|
|
|
|
UploadReport();
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
|
|
UploadReport(const UploadReport&) = delete;
|
|
|
|
|
UploadReport& operator=(const UploadReport&) = delete;
|
|
|
|
|
|
2018-02-15 08:17:12 -08:00
|
|
|
|
virtual ~UploadReport();
|
|
|
|
|
|
2018-05-18 15:53:54 -07:00
|
|
|
|
//! \brief An open FileReader with which to read the report.
|
2018-02-15 08:17:12 -08:00
|
|
|
|
FileReader* Reader() const { return reader_.get(); }
|
|
|
|
|
|
2018-05-18 15:53:54 -07:00
|
|
|
|
//! \brief Obtains a mapping of names to file readers for any attachments
|
|
|
|
|
//! for the report.
|
|
|
|
|
std::map<std::string, FileReader*> GetAttachments() const {
|
|
|
|
|
return attachment_map_;
|
2019-02-21 10:41:28 -05:00
|
|
|
|
}
|
2018-05-18 15:53:54 -07:00
|
|
|
|
|
2018-02-15 08:17:12 -08:00
|
|
|
|
private:
|
|
|
|
|
friend class CrashReportDatabase;
|
2018-02-15 11:10:10 -08:00
|
|
|
|
friend class CrashReportDatabaseGeneric;
|
2018-02-15 08:17:12 -08:00
|
|
|
|
friend class CrashReportDatabaseMac;
|
|
|
|
|
friend class CrashReportDatabaseWin;
|
|
|
|
|
|
2021-05-27 11:35:47 -04:00
|
|
|
|
bool Initialize(const base::FilePath& path, CrashReportDatabase* database);
|
2018-05-18 15:53:54 -07:00
|
|
|
|
void InitializeAttachments();
|
2018-02-15 08:17:12 -08:00
|
|
|
|
|
|
|
|
|
std::unique_ptr<FileReader> reader_;
|
|
|
|
|
CrashReportDatabase* database_;
|
2018-05-18 15:53:54 -07:00
|
|
|
|
std::vector<std::unique_ptr<FileReader>> attachment_readers_;
|
|
|
|
|
std::map<std::string, FileReader*> attachment_map_;
|
2018-07-24 09:13:49 -07:00
|
|
|
|
bool report_metrics_;
|
2018-02-15 08:17:12 -08:00
|
|
|
|
};
|
|
|
|
|
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//! \brief The result code for operations performed on a database.
|
|
|
|
|
enum OperationStatus {
|
|
|
|
|
//! \brief No error occurred.
|
|
|
|
|
kNoError = 0,
|
|
|
|
|
|
|
|
|
|
//! \brief The report that was requested could not be located.
|
2017-04-13 10:12:28 -04:00
|
|
|
|
//!
|
|
|
|
|
//! This may occur when the report is present in the database but not in a
|
|
|
|
|
//! state appropriate for the requested operation, for example, if
|
|
|
|
|
//! GetReportForUploading() is called to obtain report that’s already in the
|
|
|
|
|
//! completed state.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
kReportNotFound,
|
|
|
|
|
|
|
|
|
|
//! \brief An error occured while performing a file operation on a crash
|
|
|
|
|
//! report.
|
|
|
|
|
//!
|
|
|
|
|
//! A database is responsible for managing both the metadata about a report
|
|
|
|
|
//! and the actual crash report itself. This error is returned when an
|
|
|
|
|
//! error occurred when managing the report file. Additional information
|
|
|
|
|
//! will be logged.
|
|
|
|
|
kFileSystemError,
|
|
|
|
|
|
2015-03-10 12:22:31 -04:00
|
|
|
|
//! \brief An error occured while recording metadata for a crash report or
|
|
|
|
|
//! database-wide settings.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
|
|
|
|
//! A database is responsible for managing both the metadata about a report
|
|
|
|
|
//! and the actual crash report itself. This error is returned when an
|
2015-03-10 12:22:31 -04:00
|
|
|
|
//! error occurred when managing the metadata about a crash report or
|
|
|
|
|
//! database-wide settings. Additional information will be logged.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
kDatabaseError,
|
|
|
|
|
|
|
|
|
|
//! \brief The operation could not be completed because a concurrent
|
|
|
|
|
//! operation affecting the report is occurring.
|
|
|
|
|
kBusyError,
|
2016-08-24 15:37:46 -04:00
|
|
|
|
|
|
|
|
|
//! \brief The report cannot be uploaded by user request as it has already
|
|
|
|
|
//! been uploaded.
|
|
|
|
|
kCannotRequestUpload,
|
2015-01-26 15:59:01 -05:00
|
|
|
|
};
|
|
|
|
|
|
2021-09-20 12:55:12 -07:00
|
|
|
|
CrashReportDatabase(const CrashReportDatabase&) = delete;
|
|
|
|
|
CrashReportDatabase& operator=(const CrashReportDatabase&) = delete;
|
|
|
|
|
|
2015-01-26 15:59:01 -05:00
|
|
|
|
virtual ~CrashReportDatabase() {}
|
|
|
|
|
|
2015-10-08 13:10:02 -04:00
|
|
|
|
//! \brief Opens a database of crash reports, possibly creating it.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
2015-10-08 13:10:02 -04:00
|
|
|
|
//! \param[in] path A path to the database to be created or opened. If the
|
|
|
|
|
//! database does not yet exist, it will be created if possible. Note that
|
|
|
|
|
//! for databases implemented as directory structures, existence refers
|
|
|
|
|
//! solely to the outermost directory.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
|
|
|
|
//! \return A database object on success, `nullptr` on failure with an error
|
|
|
|
|
//! logged.
|
2015-10-08 13:10:02 -04:00
|
|
|
|
//!
|
|
|
|
|
//! \sa InitializeWithoutCreating
|
2016-04-25 12:13:07 -07:00
|
|
|
|
static std::unique_ptr<CrashReportDatabase> Initialize(
|
|
|
|
|
const base::FilePath& path);
|
2015-01-26 15:59:01 -05:00
|
|
|
|
|
2015-10-08 13:10:02 -04:00
|
|
|
|
//! \brief Opens an existing database of crash reports.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] path A path to the database to be opened. If the database does
|
|
|
|
|
//! not yet exist, it will not be created. Note that for databases
|
|
|
|
|
//! implemented as directory structures, existence refers solely to the
|
|
|
|
|
//! outermost directory. On such databases, as long as the outermost
|
|
|
|
|
//! directory is present, this method will create the inner structure.
|
|
|
|
|
//!
|
|
|
|
|
//! \return A database object on success, `nullptr` on failure with an error
|
|
|
|
|
//! logged.
|
|
|
|
|
//!
|
|
|
|
|
//! \sa Initialize
|
2016-04-25 12:13:07 -07:00
|
|
|
|
static std::unique_ptr<CrashReportDatabase> InitializeWithoutCreating(
|
2015-10-08 13:10:02 -04:00
|
|
|
|
const base::FilePath& path);
|
|
|
|
|
|
2015-03-09 18:47:52 -04:00
|
|
|
|
//! \brief Returns the Settings object for this database.
|
|
|
|
|
//!
|
|
|
|
|
//! \return A weak pointer to the Settings object, which is owned by the
|
|
|
|
|
//! database.
|
|
|
|
|
virtual Settings* GetSettings() = 0;
|
|
|
|
|
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//! \brief Creates a record of a new crash report.
|
|
|
|
|
//!
|
2018-02-13 17:28:11 -08:00
|
|
|
|
//! Callers should write the crash report using the FileWriter provided.
|
|
|
|
|
//! Callers should then call FinishedWritingCrashReport() to complete report
|
|
|
|
|
//! creation. If an error is encountered while writing the crash report, no
|
|
|
|
|
//! special action needs to be taken. If FinishedWritingCrashReport() is not
|
|
|
|
|
//! called, the report will be removed from the database when \a report is
|
|
|
|
|
//! destroyed.
|
2015-04-03 18:57:01 -04:00
|
|
|
|
//!
|
2018-02-13 17:28:11 -08:00
|
|
|
|
//! \param[out] report A NewReport object containing a FileWriter with which
|
|
|
|
|
//! to write the report data. Only valid if this returns #kNoError.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
2018-02-13 17:28:11 -08:00
|
|
|
|
virtual OperationStatus PrepareNewCrashReport(
|
|
|
|
|
std::unique_ptr<NewReport>* report) = 0;
|
2015-01-26 15:59:01 -05:00
|
|
|
|
|
2018-02-13 17:28:11 -08:00
|
|
|
|
//! \brief Informs the database that a crash report has been successfully
|
|
|
|
|
//! written.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
2015-04-03 18:57:01 -04:00
|
|
|
|
//! \param[in] report A NewReport obtained with PrepareNewCrashReport(). The
|
2018-02-13 17:28:11 -08:00
|
|
|
|
//! NewReport object will be invalidated as part of this call.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//! \param[out] uuid The UUID of this crash report.
|
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
2018-02-13 17:28:11 -08:00
|
|
|
|
virtual OperationStatus FinishedWritingCrashReport(
|
|
|
|
|
std::unique_ptr<NewReport> report,
|
|
|
|
|
UUID* uuid) = 0;
|
2015-02-04 16:33:15 -05:00
|
|
|
|
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//! \brief Returns the crash report record for the unique identifier.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] uuid The crash report record unique identifier.
|
|
|
|
|
//! \param[out] report A crash report record. Only valid if this returns
|
|
|
|
|
//! #kNoError.
|
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
|
|
|
|
virtual OperationStatus LookUpCrashReport(const UUID& uuid,
|
|
|
|
|
Report* report) = 0;
|
|
|
|
|
|
|
|
|
|
//! \brief Returns a list of crash report records that have not been uploaded.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[out] reports A list of crash report record objects. This must be
|
|
|
|
|
//! empty on entry. Only valid if this returns #kNoError.
|
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
2015-03-06 18:43:28 -05:00
|
|
|
|
virtual OperationStatus GetPendingReports(std::vector<Report>* reports) = 0;
|
2015-01-26 15:59:01 -05:00
|
|
|
|
|
|
|
|
|
//! \brief Returns a list of crash report records that have been completed,
|
|
|
|
|
//! either by being uploaded or by skipping upload.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[out] reports A list of crash report record objects. This must be
|
|
|
|
|
//! empty on entry. Only valid if this returns #kNoError.
|
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
2015-03-06 18:43:28 -05:00
|
|
|
|
virtual OperationStatus GetCompletedReports(std::vector<Report>* reports) = 0;
|
2015-01-26 15:59:01 -05:00
|
|
|
|
|
2018-02-15 08:17:12 -08:00
|
|
|
|
//! \brief Obtains and locks a report object for uploading to a collection
|
2022-07-14 11:00:29 -04:00
|
|
|
|
//! server. On iOS the file lock is released and mutual-exclusion is kept
|
|
|
|
|
//! via a file attribute.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
2018-02-15 08:17:12 -08:00
|
|
|
|
//! Callers should upload the crash report using the FileReader provided.
|
|
|
|
|
//! Callers should then call RecordUploadComplete() to record a successful
|
|
|
|
|
//! upload. If RecordUploadComplete() is not called, the upload attempt will
|
|
|
|
|
//! be recorded as unsuccessful and the report lock released when \a report is
|
|
|
|
|
//! destroyed.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
2022-07-14 11:00:29 -04:00
|
|
|
|
//! On iOS, holding a lock during a slow upload can lead to watchdog kills if
|
|
|
|
|
//! the app is suspended mid-upload. Instead, if the client can obtain the
|
|
|
|
|
//! lock, the database sets a lock-time file attribute and releases the lock.
|
|
|
|
|
//! The attribute is cleared when the upload is completed. The lock-time
|
|
|
|
|
//! attribute can be used to prevent file access from other processes, or to
|
|
|
|
|
//! discard reports that likely were terminated mid-upload.
|
|
|
|
|
//!
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//! \param[in] uuid The unique identifier for the crash report record.
|
|
|
|
|
//! \param[out] report A crash report record for the report to be uploaded.
|
2018-02-15 08:17:12 -08:00
|
|
|
|
//! Only valid if this returns #kNoError.
|
2018-07-24 09:13:49 -07:00
|
|
|
|
//! \param[in] report_metrics If `false`, metrics will not be recorded for
|
|
|
|
|
//! this upload attempt when RecordUploadComplete() is called or \a report
|
|
|
|
|
//! is destroyed. Metadata for the upload attempt will still be recorded
|
|
|
|
|
//! in the database.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
2018-02-15 08:17:12 -08:00
|
|
|
|
virtual OperationStatus GetReportForUploading(
|
|
|
|
|
const UUID& uuid,
|
2018-07-24 09:13:49 -07:00
|
|
|
|
std::unique_ptr<const UploadReport>* report,
|
|
|
|
|
bool report_metrics = true) = 0;
|
2015-01-26 15:59:01 -05:00
|
|
|
|
|
2018-02-15 08:17:12 -08:00
|
|
|
|
//! \brief Records a successful upload for a report and updates the last
|
|
|
|
|
//! upload attempt time as returned by
|
2015-03-10 12:22:31 -04:00
|
|
|
|
//! Settings::GetLastUploadAttemptTime().
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
2018-02-15 08:17:12 -08:00
|
|
|
|
//! \param[in] report A UploadReport object obtained from
|
|
|
|
|
//! GetReportForUploading(). The UploadReport object will be invalidated
|
|
|
|
|
//! and the report unlocked as part of this call.
|
|
|
|
|
//! \param[in] id The possibly empty identifier assigned to this crash report
|
|
|
|
|
//! by the collection server.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
2018-02-15 08:17:12 -08:00
|
|
|
|
OperationStatus RecordUploadComplete(
|
|
|
|
|
std::unique_ptr<const UploadReport> report,
|
|
|
|
|
const std::string& id);
|
2015-01-26 15:59:01 -05:00
|
|
|
|
|
|
|
|
|
//! \brief Moves a report from the pending state to the completed state, but
|
|
|
|
|
//! without the report being uploaded.
|
|
|
|
|
//!
|
|
|
|
|
//! This can be used if the user has disabled crash report collection, but
|
|
|
|
|
//! crash generation is still enabled in the product.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] uuid The unique identifier for the crash report record.
|
2016-09-26 15:06:19 -07:00
|
|
|
|
//! \param[in] reason The reason the report upload is being skipped for
|
|
|
|
|
//! metrics tracking purposes.
|
2015-01-26 15:59:01 -05:00
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
2016-09-26 15:06:19 -07:00
|
|
|
|
virtual OperationStatus SkipReportUpload(
|
|
|
|
|
const UUID& uuid,
|
|
|
|
|
Metrics::CrashSkippedReason reason) = 0;
|
2015-01-26 15:59:01 -05:00
|
|
|
|
|
2015-10-07 17:01:47 -04:00
|
|
|
|
//! \brief Deletes a crash report file and its associated metadata.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] uuid The UUID of the report to delete.
|
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
|
|
|
|
virtual OperationStatus DeleteReport(const UUID& uuid) = 0;
|
|
|
|
|
|
2016-08-24 15:37:46 -04:00
|
|
|
|
//! \brief Marks a crash report as explicitly requested to be uploaded by the
|
|
|
|
|
//! user and moves it to 'pending' state.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] uuid The unique identifier for the crash report record.
|
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
|
|
|
|
virtual OperationStatus RequestUpload(const UUID& uuid) = 0;
|
|
|
|
|
|
2018-02-15 11:10:10 -08:00
|
|
|
|
//! \brief Cleans the database of expired lockfiles, metadata without report
|
2021-11-02 10:50:42 +01:00
|
|
|
|
//! files, report files without metadata, and attachments without report
|
|
|
|
|
//! files.
|
2018-02-15 11:10:10 -08:00
|
|
|
|
//!
|
2021-11-02 10:50:42 +01:00
|
|
|
|
//! As the macOS implementation does not use lock or metadata files, the
|
|
|
|
|
//! cleaning is limited to attachments without report files.
|
2018-02-15 11:10:10 -08:00
|
|
|
|
//!
|
|
|
|
|
//! \param[in] lockfile_ttl The number of seconds at which lockfiles or new
|
|
|
|
|
//! report files are considered expired.
|
|
|
|
|
//! \return The number of reports cleaned.
|
|
|
|
|
virtual int CleanDatabase(time_t lockfile_ttl) { return 0; }
|
|
|
|
|
|
2015-01-26 15:59:01 -05:00
|
|
|
|
protected:
|
|
|
|
|
CrashReportDatabase() {}
|
|
|
|
|
|
2021-11-02 10:50:42 +01:00
|
|
|
|
//! \brief The path to the database passed to Initialize.
|
|
|
|
|
//!
|
|
|
|
|
//! \return The filepath of the database;
|
|
|
|
|
virtual base::FilePath DatabasePath() = 0;
|
|
|
|
|
|
|
|
|
|
//! \brief Build a filepath for the root attachments directory.
|
|
|
|
|
//!
|
|
|
|
|
//! \return The filepath to the attachments directory.
|
|
|
|
|
base::FilePath AttachmentsRootPath();
|
|
|
|
|
|
|
|
|
|
//! \brief Build a filepath for the directory for the report to hold
|
|
|
|
|
//! attachments.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] uuid The unique identifier for the crash report record.
|
|
|
|
|
//!
|
|
|
|
|
//! \return The filepath to the report attachments directory.
|
|
|
|
|
base::FilePath AttachmentsPath(const UUID& uuid);
|
|
|
|
|
|
|
|
|
|
//! \brief Attempts to remove any attachments associated with the given
|
|
|
|
|
//! report UUID. There may not be any, so failing is not an error.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] uuid The unique identifier for the crash report record.
|
|
|
|
|
void RemoveAttachmentsByUUID(const UUID& uuid);
|
|
|
|
|
|
2015-01-26 15:59:01 -05:00
|
|
|
|
private:
|
2018-02-15 08:17:12 -08:00
|
|
|
|
//! \brief Adjusts a crash report record’s metadata to account for an upload
|
|
|
|
|
//! attempt, and updates the last upload attempt time as returned by
|
|
|
|
|
//! Settings::GetLastUploadAttemptTime().
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] report The report object obtained from
|
|
|
|
|
//! GetReportForUploading().
|
|
|
|
|
//! \param[in] successful Whether the upload attempt was successful.
|
|
|
|
|
//! \param[in] id The identifier assigned to this crash report by the
|
|
|
|
|
//! collection server. Must be empty if \a successful is `false`; may be
|
|
|
|
|
//! empty if it is `true`.
|
|
|
|
|
//!
|
|
|
|
|
//! \return The operation status code.
|
|
|
|
|
virtual OperationStatus RecordUploadAttempt(UploadReport* report,
|
|
|
|
|
bool successful,
|
|
|
|
|
const std::string& id) = 0;
|
2015-01-26 15:59:01 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace crashpad
|
|
|
|
|
|
|
|
|
|
#endif // CRASHPAD_CLIENT_CRASH_REPORT_DATABASE_H_
|