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

Side by Side Diff: client/crash_report_database_win.cc

Issue 1391993002: win: Set last-upload-attempt time in CrashReportDatabaseWin (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
« no previous file with comments | « client/crash_report_database_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 scoped_ptr<NewReport> scoped_report(report); 624 scoped_ptr<NewReport> scoped_report(report);
625 625
626 // Close the outstanding handle. 626 // Close the outstanding handle.
627 LoggingCloseFile(report->handle); 627 LoggingCloseFile(report->handle);
628 628
629 // We failed to write, so remove the dump file. There's no entry in the 629 // We failed to write, so remove the dump file. There's no entry in the
630 // metadata table yet. 630 // metadata table yet.
631 if (!DeleteFile(scoped_report->path.value().c_str())) { 631 if (!DeleteFile(scoped_report->path.value().c_str())) {
632 PLOG(ERROR) << "DeleteFile " 632 PLOG(ERROR) << "DeleteFile "
633 << base::UTF16ToUTF8(scoped_report->path.value()); 633 << base::UTF16ToUTF8(scoped_report->path.value());
634 return CrashReportDatabase::kFileSystemError; 634 return kFileSystemError;
635 } 635 }
636 636
637 return kNoError; 637 return kNoError;
638 } 638 }
639 639
640 OperationStatus CrashReportDatabaseWin::LookUpCrashReport(const UUID& uuid, 640 OperationStatus CrashReportDatabaseWin::LookUpCrashReport(const UUID& uuid,
641 Report* report) { 641 Report* report) {
642 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 642 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
643 643
644 scoped_ptr<Metadata> metadata(AcquireMetadata()); 644 scoped_ptr<Metadata> metadata(AcquireMetadata());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 // one possibility would be to change the interface to be FileHandle based, so 684 // one possibility would be to change the interface to be FileHandle based, so
685 // that instead of giving the file_path back to the client and changing state 685 // that instead of giving the file_path back to the client and changing state
686 // to kUploading, we return an exclusive access handle, and use that as the 686 // to kUploading, we return an exclusive access handle, and use that as the
687 // signal that the upload is pending, rather than an update to state in the 687 // signal that the upload is pending, rather than an update to state in the
688 // metadata. Alternatively, there could be a "garbage collection" at startup 688 // metadata. Alternatively, there could be a "garbage collection" at startup
689 // where any reports that are orphaned in the kUploading state are either 689 // where any reports that are orphaned in the kUploading state are either
690 // reset to kPending to retry, or discarded. 690 // reset to kPending to retry, or discarded.
691 ReportDisk* report_disk; 691 ReportDisk* report_disk;
692 OperationStatus os = metadata->FindSingleReportAndMarkDirty( 692 OperationStatus os = metadata->FindSingleReportAndMarkDirty(
693 uuid, ReportState::kPending, &report_disk); 693 uuid, ReportState::kPending, &report_disk);
694 if (os == CrashReportDatabase::kNoError) { 694 if (os == kNoError) {
695 report_disk->state = ReportState::kUploading; 695 report_disk->state = ReportState::kUploading;
696 // Create a copy for passing back to client. This will be freed in 696 // Create a copy for passing back to client. This will be freed in
697 // RecordUploadAttempt. 697 // RecordUploadAttempt.
698 *report = new Report(*report_disk); 698 *report = new Report(*report_disk);
699 } 699 }
700 return os; 700 return os;
701 } 701 }
702 702
703 OperationStatus CrashReportDatabaseWin::RecordUploadAttempt( 703 OperationStatus CrashReportDatabaseWin::RecordUploadAttempt(
704 const Report* report, 704 const Report* report,
705 bool successful, 705 bool successful,
706 const std::string& id) { 706 const std::string& id) {
707 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 707 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
708 708
709 // Take ownership, allocated in GetReportForUploading. 709 // Take ownership, allocated in GetReportForUploading.
710 scoped_ptr<const Report> upload_report(report); 710 scoped_ptr<const Report> upload_report(report);
711 scoped_ptr<Metadata> metadata(AcquireMetadata()); 711 scoped_ptr<Metadata> metadata(AcquireMetadata());
712 if (!metadata) 712 if (!metadata)
713 return kDatabaseError; 713 return kDatabaseError;
714 ReportDisk* report_disk; 714 ReportDisk* report_disk;
715 OperationStatus os = metadata->FindSingleReportAndMarkDirty( 715 OperationStatus os = metadata->FindSingleReportAndMarkDirty(
716 report->uuid, ReportState::kUploading, &report_disk); 716 report->uuid, ReportState::kUploading, &report_disk);
717 if (os == CrashReportDatabaseWin::kNoError) { 717 if (os != kNoError)
718 report_disk->uploaded = successful; 718 return os;
719 report_disk->id = id;
720 report_disk->last_upload_attempt_time = time(nullptr);
721 report_disk->upload_attempts++;
722 report_disk->state =
723 successful ? ReportState::kCompleted : ReportState::kPending;
724 }
725 719
726 // Call Settings::SetLastUploadAttemptTime(). 720 time_t now = time(nullptr);
727 // https://code.google.com/p/crashpad/issues/detail?id=13.
728 721
729 return os; 722 report_disk->uploaded = successful;
723 report_disk->id = id;
724 report_disk->last_upload_attempt_time = now;
725 report_disk->upload_attempts++;
726 report_disk->state =
727 successful ? ReportState::kCompleted : ReportState::kPending;
728
729 if (!settings_.SetLastUploadAttemptTime(now))
730 return kDatabaseError;
731
732 return kNoError;
730 } 733 }
731 734
732 OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) { 735 OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) {
733 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 736 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
734 737
735 scoped_ptr<Metadata> metadata(AcquireMetadata()); 738 scoped_ptr<Metadata> metadata(AcquireMetadata());
736 if (!metadata) 739 if (!metadata)
737 return kDatabaseError; 740 return kDatabaseError;
738 ReportDisk* report_disk; 741 ReportDisk* report_disk;
739 OperationStatus os = metadata->FindSingleReportAndMarkDirty( 742 OperationStatus os = metadata->FindSingleReportAndMarkDirty(
740 uuid, ReportState::kPending, &report_disk); 743 uuid, ReportState::kPending, &report_disk);
741 if (os == CrashReportDatabase::kNoError) 744 if (os == kNoError)
742 report_disk->state = ReportState::kCompleted; 745 report_disk->state = ReportState::kCompleted;
743 return os; 746 return os;
744 } 747 }
745 748
746 scoped_ptr<Metadata> CrashReportDatabaseWin::AcquireMetadata() { 749 scoped_ptr<Metadata> CrashReportDatabaseWin::AcquireMetadata() {
747 base::FilePath metadata_file = base_dir_.Append(kMetadataFileName); 750 base::FilePath metadata_file = base_dir_.Append(kMetadataFileName);
748 return Metadata::Create(metadata_file, base_dir_.Append(kReportsDirectory)); 751 return Metadata::Create(metadata_file, base_dir_.Append(kReportsDirectory));
749 } 752 }
750 753
751 } // namespace 754 } // namespace
752 755
753 // static 756 // static
754 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( 757 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize(
755 const base::FilePath& path) { 758 const base::FilePath& path) {
756 scoped_ptr<CrashReportDatabaseWin> database_win( 759 scoped_ptr<CrashReportDatabaseWin> database_win(
757 new CrashReportDatabaseWin(path)); 760 new CrashReportDatabaseWin(path));
758 return database_win->Initialize() ? database_win.Pass() 761 return database_win->Initialize() ? database_win.Pass()
759 : scoped_ptr<CrashReportDatabaseWin>(); 762 : scoped_ptr<CrashReportDatabaseWin>();
760 } 763 }
761 764
762 } // namespace crashpad 765 } // namespace crashpad
OLDNEW
« no previous file with comments | « client/crash_report_database_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698