| OLD | NEW |
| 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 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 report_disk->upload_attempts++; | 750 report_disk->upload_attempts++; |
| 726 report_disk->state = | 751 report_disk->state = |
| 727 successful ? ReportState::kCompleted : ReportState::kPending; | 752 successful ? ReportState::kCompleted : ReportState::kPending; |
| 728 | 753 |
| 729 if (!settings_.SetLastUploadAttemptTime(now)) | 754 if (!settings_.SetLastUploadAttemptTime(now)) |
| 730 return kDatabaseError; | 755 return kDatabaseError; |
| 731 | 756 |
| 732 return kNoError; | 757 return kNoError; |
| 733 } | 758 } |
| 734 | 759 |
| 760 OperationStatus CrashReportDatabaseWin::DeleteReport(const UUID& uuid) { |
| 761 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 762 |
| 763 scoped_ptr<Metadata> metadata(AcquireMetadata()); |
| 764 if (!metadata) |
| 765 return kDatabaseError; |
| 766 |
| 767 base::FilePath report_path; |
| 768 OperationStatus os = metadata->DeleteReport(uuid, &report_path); |
| 769 if (os != kNoError) |
| 770 return os; |
| 771 |
| 772 if (!DeleteFile(report_path.value().c_str())) { |
| 773 PLOG(ERROR) << "DeleteFile " |
| 774 << base::UTF16ToUTF8(report_path.value()); |
| 775 return kFileSystemError; |
| 776 } |
| 777 return kNoError; |
| 778 } |
| 779 |
| 735 OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) { | 780 OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) { |
| 736 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 781 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 737 | 782 |
| 738 scoped_ptr<Metadata> metadata(AcquireMetadata()); | 783 scoped_ptr<Metadata> metadata(AcquireMetadata()); |
| 739 if (!metadata) | 784 if (!metadata) |
| 740 return kDatabaseError; | 785 return kDatabaseError; |
| 741 ReportDisk* report_disk; | 786 ReportDisk* report_disk; |
| 742 OperationStatus os = metadata->FindSingleReportAndMarkDirty( | 787 OperationStatus os = metadata->FindSingleReportAndMarkDirty( |
| 743 uuid, ReportState::kPending, &report_disk); | 788 uuid, ReportState::kPending, &report_disk); |
| 744 if (os == kNoError) | 789 if (os == kNoError) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 756 // static | 801 // static |
| 757 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( | 802 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( |
| 758 const base::FilePath& path) { | 803 const base::FilePath& path) { |
| 759 scoped_ptr<CrashReportDatabaseWin> database_win( | 804 scoped_ptr<CrashReportDatabaseWin> database_win( |
| 760 new CrashReportDatabaseWin(path)); | 805 new CrashReportDatabaseWin(path)); |
| 761 return database_win->Initialize() ? database_win.Pass() | 806 return database_win->Initialize() ? database_win.Pass() |
| 762 : scoped_ptr<CrashReportDatabaseWin>(); | 807 : scoped_ptr<CrashReportDatabaseWin>(); |
| 763 } | 808 } |
| 764 | 809 |
| 765 } // namespace crashpad | 810 } // namespace crashpad |
| OLD | NEW |