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

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
« no previous file with comments | « client/crash_report_database_test.cc ('k') | client/prune_crash_reports.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/crash_report_database_win.cc
diff --git a/client/crash_report_database_win.cc b/client/crash_report_database_win.cc
index f270530b70fdd54fedba79a1708924aa244291ea..6d2bf1afc83dc25cb18a900dcbb61457e8c617f8 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_path The found report's file_path, valid only if
+ //! CrashReportDatabase::kNoError is returned.
+ OperationStatus DeleteReport(const UUID& uuid,
+ base::FilePath* report_path);
+
private:
Metadata(FileHandle handle, const base::FilePath& report_dir);
@@ -351,6 +364,20 @@ OperationStatus Metadata::FindSingleReportAndMarkDirty(
return os;
}
+OperationStatus Metadata::DeleteReport(const UUID& uuid,
+ base::FilePath* report_path) {
+ 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_path = report_iter->file_path;
+ reports_.erase(report_iter);
+ dirty_ = true;
+ return CrashReportDatabase::kNoError;
+}
+
Metadata::Metadata(FileHandle handle, const base::FilePath& report_dir)
: handle_(handle), report_dir_(report_dir), dirty_(false), reports_() {
}
@@ -531,6 +558,7 @@ class CrashReportDatabaseWin : public CrashReportDatabase {
bool successful,
const std::string& id) override;
OperationStatus SkipReportUpload(const UUID& uuid) override;
+ OperationStatus DeleteReport(const UUID& uuid) override;
private:
scoped_ptr<Metadata> AcquireMetadata();
@@ -560,9 +588,6 @@ bool CrashReportDatabaseWin::Initialize() {
!CreateDirectoryIfNecessary(base_dir_.Append(kReportsDirectory)))
return false;
- // TODO(scottmg): When are completed reports pruned from disk? Delete here or
- // maybe on AcquireMetadata().
-
if (!settings_.Initialize())
return false;
@@ -732,6 +757,26 @@ OperationStatus CrashReportDatabaseWin::RecordUploadAttempt(
return kNoError;
}
+OperationStatus CrashReportDatabaseWin::DeleteReport(const UUID& uuid) {
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+
+ scoped_ptr<Metadata> metadata(AcquireMetadata());
+ if (!metadata)
+ return kDatabaseError;
+
+ base::FilePath report_path;
+ OperationStatus os = metadata->DeleteReport(uuid, &report_path);
+ if (os != kNoError)
+ return os;
+
+ if (!DeleteFile(report_path.value().c_str())) {
+ PLOG(ERROR) << "DeleteFile "
+ << base::UTF16ToUTF8(report_path.value());
+ return kFileSystemError;
+ }
+ return kNoError;
+}
+
OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
« no previous file with comments | « client/crash_report_database_test.cc ('k') | client/prune_crash_reports.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698