Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1701)

Unified Diff: client/crash_report_database_win.cc

Issue 1392653002: Add functionality to prune old crash reports from the database. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/crash_report_database_win.cc
diff --git a/client/crash_report_database_win.cc b/client/crash_report_database_win.cc
index aea0642154566b46efb4443d9bd2036ac719bdeb..751bdac96ae57a362f9c5615f48e1a42da1ba1d8 100644
--- a/client/crash_report_database_win.cc
+++ b/client/crash_report_database_win.cc
@@ -229,6 +229,19 @@ class Metadata {
ReportState desired_state,
ReportDisk** report_disk);
+ //! \brief Removes a report from the metadata database, without touching the
+ //! on-disk file.
+ //!
+ //! The returned report is only valid if CrashReportDatabase::kNoError is
+ //! returned. This will mark the database as dirty. Future metadata
+ //! operations for this report will not succeed.
+ //!
+ //! \param[in] uuid The report identifier to remove.
+ //! \param[out] report_disk The found report, valid only if
+ //! CrashReportDatabase::kNoError is returned.
+ OperationStatus DeleteReport(const UUID& uuid,
+ CrashReportDatabase::Report* report);
Mark Mentovai 2015/10/07 03:54:27 Returning a CrashReportDatabase::Report for someth
Robert Sesek 2015/10/07 16:24:34 Done.
+
private:
Metadata(FileHandle handle, const base::FilePath& report_dir);
@@ -351,6 +364,20 @@ OperationStatus Metadata::FindSingleReportAndMarkDirty(
return os;
}
+OperationStatus Metadata::DeleteReport(const UUID& uuid,
+ CrashReportDatabase::Report* report) {
+ auto report_iter = std::find_if(
+ reports_.begin(), reports_.end(), [uuid](const ReportDisk& report) {
+ return report.uuid == uuid;
+ });
+ if (report_iter == reports_.end())
+ return CrashReportDatabase::kReportNotFound;
+ *report = *report_iter;
+ reports_.erase(report_iter);
+ dirty_ = true;
+ return kNoError;
scottmg 2015/10/06 22:22:07 This needs to be CrashReportDatabase::kNoError.
Robert Sesek 2015/10/07 16:24:34 Done.
+}
+
Metadata::Metadata(FileHandle handle, const base::FilePath& report_dir)
: handle_(handle), report_dir_(report_dir), dirty_(false), reports_() {
}
@@ -729,6 +756,26 @@ OperationStatus CrashReportDatabaseWin::RecordUploadAttempt(
return os;
}
+OperationStatus CrashReportDatabaseWin::DeleteReport(const UUID& uuid) {
scottmg 2015/10/06 22:22:07 There's no declaration for this method.
Robert Sesek 2015/10/07 16:24:34 Done.
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+
+ scoped_ptr<Metadata> metadata(AcquireMetadata());
+ if (!metadata)
+ return kDatabaseError;
+
+ Report report;
+ OperationStatus os = metadata->DeleteReport(uuid, &report);
+ if (os != kNoError)
+ return os;
+
+ if (!DeleteFile(report.file_path.value().c_str())) {
+ PLOG(ERROR) << "DeleteFile "
+ << base::UTF16ToUTF8(report.file_path.value());
+ return CrashReportDatabase::kFileSystemError;
Mark Mentovai 2015/10/07 03:54:27 You don’t need CrashReportDatabase:: here.
Robert Sesek 2015/10/07 16:24:34 Done.
+ }
+ return kNoError;
+}
+
OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);

Powered by Google App Engine
This is Rietveld 408576698