OLD | NEW |
---|---|
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
Mark Mentovai
2015/10/07 19:13:05
Another thing that occurred to me, which can eithe
Robert Sesek
2015/10/07 20:34:52
That seems like a separate bug. https://code.googl
| |
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, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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_path The found report's file_path, valid only if | |
241 //! CrashReportDatabase::kNoError is returned. | |
242 OperationStatus DeleteReport(const UUID& uuid, | |
243 base::FilePath* report_path); | |
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 Loading... | |
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 base::FilePath* report_path) { | |
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_path = report_iter->file_path; | |
376 reports_.erase(report_iter); | |
377 dirty_ = true; | |
378 return CrashReportDatabase::kNoError; | |
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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 OperationStatus ErrorWritingCrashReport(NewReport* report) override; | 551 OperationStatus ErrorWritingCrashReport(NewReport* report) override; |
525 OperationStatus LookUpCrashReport(const UUID& uuid, Report* report) override; | 552 OperationStatus LookUpCrashReport(const UUID& uuid, Report* report) override; |
526 OperationStatus GetPendingReports(std::vector<Report>* reports) override; | 553 OperationStatus GetPendingReports(std::vector<Report>* reports) override; |
527 OperationStatus GetCompletedReports(std::vector<Report>* reports) override; | 554 OperationStatus GetCompletedReports(std::vector<Report>* reports) override; |
528 OperationStatus GetReportForUploading(const UUID& uuid, | 555 OperationStatus GetReportForUploading(const UUID& uuid, |
529 const Report** report) override; | 556 const Report** report) override; |
530 OperationStatus RecordUploadAttempt(const Report* report, | 557 OperationStatus RecordUploadAttempt(const Report* report, |
531 bool successful, | 558 bool successful, |
532 const std::string& id) override; | 559 const std::string& id) override; |
533 OperationStatus SkipReportUpload(const UUID& uuid) override; | 560 OperationStatus SkipReportUpload(const UUID& uuid) override; |
561 OperationStatus DeleteReport(const UUID& uuid) override; | |
534 | 562 |
535 private: | 563 private: |
536 scoped_ptr<Metadata> AcquireMetadata(); | 564 scoped_ptr<Metadata> AcquireMetadata(); |
537 | 565 |
538 base::FilePath base_dir_; | 566 base::FilePath base_dir_; |
539 Settings settings_; | 567 Settings settings_; |
540 InitializationStateDcheck initialized_; | 568 InitializationStateDcheck initialized_; |
541 | 569 |
542 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseWin); | 570 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseWin); |
543 }; | 571 }; |
544 | 572 |
545 CrashReportDatabaseWin::CrashReportDatabaseWin(const base::FilePath& path) | 573 CrashReportDatabaseWin::CrashReportDatabaseWin(const base::FilePath& path) |
546 : CrashReportDatabase(), | 574 : CrashReportDatabase(), |
547 base_dir_(path), | 575 base_dir_(path), |
548 settings_(base_dir_.Append(kSettings)), | 576 settings_(base_dir_.Append(kSettings)), |
549 initialized_() { | 577 initialized_() { |
550 } | 578 } |
551 | 579 |
552 CrashReportDatabaseWin::~CrashReportDatabaseWin() { | 580 CrashReportDatabaseWin::~CrashReportDatabaseWin() { |
553 } | 581 } |
554 | 582 |
555 bool CrashReportDatabaseWin::Initialize() { | 583 bool CrashReportDatabaseWin::Initialize() { |
556 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); | 584 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); |
557 | 585 |
558 // Ensure the database and report subdirectories exist. | 586 // Ensure the database and report subdirectories exist. |
559 if (!CreateDirectoryIfNecessary(base_dir_) || | 587 if (!CreateDirectoryIfNecessary(base_dir_) || |
560 !CreateDirectoryIfNecessary(base_dir_.Append(kReportsDirectory))) | 588 !CreateDirectoryIfNecessary(base_dir_.Append(kReportsDirectory))) |
561 return false; | 589 return false; |
562 | 590 |
563 // TODO(scottmg): When are completed reports pruned from disk? Delete here or | |
564 // maybe on AcquireMetadata(). | |
565 | |
566 if (!settings_.Initialize()) | 591 if (!settings_.Initialize()) |
567 return false; | 592 return false; |
568 | 593 |
569 INITIALIZATION_STATE_SET_VALID(initialized_); | 594 INITIALIZATION_STATE_SET_VALID(initialized_); |
570 return true; | 595 return true; |
571 } | 596 } |
572 | 597 |
573 Settings* CrashReportDatabaseWin::GetSettings() { | 598 Settings* CrashReportDatabaseWin::GetSettings() { |
574 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 599 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
575 return &settings_; | 600 return &settings_; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 report_disk->state = | 747 report_disk->state = |
723 successful ? ReportState::kCompleted : ReportState::kPending; | 748 successful ? ReportState::kCompleted : ReportState::kPending; |
724 } | 749 } |
725 | 750 |
726 // Call Settings::SetLastUploadAttemptTime(). | 751 // Call Settings::SetLastUploadAttemptTime(). |
727 // https://code.google.com/p/crashpad/issues/detail?id=13. | 752 // https://code.google.com/p/crashpad/issues/detail?id=13. |
728 | 753 |
729 return os; | 754 return os; |
730 } | 755 } |
731 | 756 |
757 OperationStatus CrashReportDatabaseWin::DeleteReport(const UUID& uuid) { | |
758 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
759 | |
760 scoped_ptr<Metadata> metadata(AcquireMetadata()); | |
761 if (!metadata) | |
762 return kDatabaseError; | |
763 | |
764 base::FilePath report_path; | |
765 OperationStatus os = metadata->DeleteReport(uuid, &report_path); | |
766 if (os != kNoError) | |
767 return os; | |
768 | |
769 if (!DeleteFile(report_path.value().c_str())) { | |
770 PLOG(ERROR) << "DeleteFile " | |
771 << base::UTF16ToUTF8(report_path.value()); | |
772 return kFileSystemError; | |
773 } | |
774 return kNoError; | |
775 } | |
776 | |
732 OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) { | 777 OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) { |
733 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 778 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
734 | 779 |
735 scoped_ptr<Metadata> metadata(AcquireMetadata()); | 780 scoped_ptr<Metadata> metadata(AcquireMetadata()); |
736 if (!metadata) | 781 if (!metadata) |
737 return kDatabaseError; | 782 return kDatabaseError; |
738 ReportDisk* report_disk; | 783 ReportDisk* report_disk; |
739 OperationStatus os = metadata->FindSingleReportAndMarkDirty( | 784 OperationStatus os = metadata->FindSingleReportAndMarkDirty( |
740 uuid, ReportState::kPending, &report_disk); | 785 uuid, ReportState::kPending, &report_disk); |
741 if (os == CrashReportDatabase::kNoError) | 786 if (os == CrashReportDatabase::kNoError) |
(...skipping 11 matching lines...) Expand all Loading... | |
753 // static | 798 // static |
754 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( | 799 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( |
755 const base::FilePath& path) { | 800 const base::FilePath& path) { |
756 scoped_ptr<CrashReportDatabaseWin> database_win( | 801 scoped_ptr<CrashReportDatabaseWin> database_win( |
757 new CrashReportDatabaseWin(path)); | 802 new CrashReportDatabaseWin(path)); |
758 return database_win->Initialize() ? database_win.Pass() | 803 return database_win->Initialize() ? database_win.Pass() |
759 : scoped_ptr<CrashReportDatabaseWin>(); | 804 : scoped_ptr<CrashReportDatabaseWin>(); |
760 } | 805 } |
761 | 806 |
762 } // namespace crashpad | 807 } // namespace crashpad |
OLD | NEW |