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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 //! This marks the metadata as dirty, and on destruction, changes will be 222 //! This marks the metadata as dirty, and on destruction, changes will be
223 //! written to disk via Write(). 223 //! written to disk via Write().
224 //! 224 //!
225 //! \return #kNoError on success. #kReportNotFound if there was no report with 225 //! \return #kNoError on success. #kReportNotFound if there was no report with
226 //! the specified UUID. #kBusyError if the report was not in the specified 226 //! the specified UUID. #kBusyError if the report was not in the specified
227 //! state. 227 //! state.
228 OperationStatus FindSingleReportAndMarkDirty(const UUID& uuid, 228 OperationStatus FindSingleReportAndMarkDirty(const UUID& uuid,
229 ReportState desired_state, 229 ReportState desired_state,
230 ReportDisk** report_disk); 230 ReportDisk** report_disk);
231 231
232 //! \brief Removes a report from the metadata database, without touching the
233 //! on-disk file.
234 //!
235 //! The returned report is only valid if CrashReportDatabase::kNoError is
236 //! returned. This will mark the database as dirty. Future metadata
237 //! operations for this report will not succeed.
238 //!
239 //! \param[in] uuid The report identifier to remove.
240 //! \param[out] report_disk The found report, valid only if
241 //! CrashReportDatabase::kNoError is returned.
242 OperationStatus DeleteReport(const UUID& uuid,
243 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.
244
232 private: 245 private:
233 Metadata(FileHandle handle, const base::FilePath& report_dir); 246 Metadata(FileHandle handle, const base::FilePath& report_dir);
234 247
235 bool Rewind(); 248 bool Rewind();
236 249
237 void Read(); 250 void Read();
238 void Write(); 251 void Write();
239 252
240 //! \brief Confirms that the corresponding report actually exists on disk 253 //! \brief Confirms that the corresponding report actually exists on disk
241 //! (that is, the dump file has not been removed), and that the report is 254 //! (that is, the dump file has not been removed), and that the report is
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 if (report_iter == reports_.end()) 357 if (report_iter == reports_.end())
345 return CrashReportDatabase::kReportNotFound; 358 return CrashReportDatabase::kReportNotFound;
346 OperationStatus os = VerifyReport(*report_iter, desired_state); 359 OperationStatus os = VerifyReport(*report_iter, desired_state);
347 if (os == CrashReportDatabase::kNoError) { 360 if (os == CrashReportDatabase::kNoError) {
348 dirty_ = true; 361 dirty_ = true;
349 *report_disk = &*report_iter; 362 *report_disk = &*report_iter;
350 } 363 }
351 return os; 364 return os;
352 } 365 }
353 366
367 OperationStatus Metadata::DeleteReport(const UUID& uuid,
368 CrashReportDatabase::Report* report) {
369 auto report_iter = std::find_if(
370 reports_.begin(), reports_.end(), [uuid](const ReportDisk& report) {
371 return report.uuid == uuid;
372 });
373 if (report_iter == reports_.end())
374 return CrashReportDatabase::kReportNotFound;
375 *report = *report_iter;
376 reports_.erase(report_iter);
377 dirty_ = true;
378 return kNoError;
scottmg 2015/10/06 22:22:07 This needs to be CrashReportDatabase::kNoError.
Robert Sesek 2015/10/07 16:24:34 Done.
379 }
380
354 Metadata::Metadata(FileHandle handle, const base::FilePath& report_dir) 381 Metadata::Metadata(FileHandle handle, const base::FilePath& report_dir)
355 : handle_(handle), report_dir_(report_dir), dirty_(false), reports_() { 382 : handle_(handle), report_dir_(report_dir), dirty_(false), reports_() {
356 } 383 }
357 384
358 bool Metadata::Rewind() { 385 bool Metadata::Rewind() {
359 FileOffset result = LoggingSeekFile(handle_.get(), 0, SEEK_SET); 386 FileOffset result = LoggingSeekFile(handle_.get(), 0, SEEK_SET);
360 DCHECK_EQ(result, 0); 387 DCHECK_EQ(result, 0);
361 return result == 0; 388 return result == 0;
362 } 389 }
363 390
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 report_disk->state = 749 report_disk->state =
723 successful ? ReportState::kCompleted : ReportState::kPending; 750 successful ? ReportState::kCompleted : ReportState::kPending;
724 } 751 }
725 752
726 // Call Settings::SetLastUploadAttemptTime(). 753 // Call Settings::SetLastUploadAttemptTime().
727 // https://code.google.com/p/crashpad/issues/detail?id=13. 754 // https://code.google.com/p/crashpad/issues/detail?id=13.
728 755
729 return os; 756 return os;
730 } 757 }
731 758
759 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.
760 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
761
762 scoped_ptr<Metadata> metadata(AcquireMetadata());
763 if (!metadata)
764 return kDatabaseError;
765
766 Report report;
767 OperationStatus os = metadata->DeleteReport(uuid, &report);
768 if (os != kNoError)
769 return os;
770
771 if (!DeleteFile(report.file_path.value().c_str())) {
772 PLOG(ERROR) << "DeleteFile "
773 << base::UTF16ToUTF8(report.file_path.value());
774 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.
775 }
776 return kNoError;
777 }
778
732 OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) { 779 OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) {
733 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 780 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
734 781
735 scoped_ptr<Metadata> metadata(AcquireMetadata()); 782 scoped_ptr<Metadata> metadata(AcquireMetadata());
736 if (!metadata) 783 if (!metadata)
737 return kDatabaseError; 784 return kDatabaseError;
738 ReportDisk* report_disk; 785 ReportDisk* report_disk;
739 OperationStatus os = metadata->FindSingleReportAndMarkDirty( 786 OperationStatus os = metadata->FindSingleReportAndMarkDirty(
740 uuid, ReportState::kPending, &report_disk); 787 uuid, ReportState::kPending, &report_disk);
741 if (os == CrashReportDatabase::kNoError) 788 if (os == CrashReportDatabase::kNoError)
(...skipping 11 matching lines...) Expand all
753 // static 800 // static
754 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( 801 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize(
755 const base::FilePath& path) { 802 const base::FilePath& path) {
756 scoped_ptr<CrashReportDatabaseWin> database_win( 803 scoped_ptr<CrashReportDatabaseWin> database_win(
757 new CrashReportDatabaseWin(path)); 804 new CrashReportDatabaseWin(path));
758 return database_win->Initialize() ? database_win.Pass() 805 return database_win->Initialize() ? database_win.Pass()
759 : scoped_ptr<CrashReportDatabaseWin>(); 806 : scoped_ptr<CrashReportDatabaseWin>();
760 } 807 }
761 808
762 } // namespace crashpad 809 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698