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

Side by Side Diff: client/crash_report_database_mac.mm

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
« no previous file with comments | « client/crash_report_database.h ('k') | client/crash_report_database_test.cc » ('j') | 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 OperationStatus LookUpCrashReport(const UUID& uuid, 118 OperationStatus LookUpCrashReport(const UUID& uuid,
119 Report* report) override; 119 Report* report) override;
120 OperationStatus GetPendingReports(std::vector<Report>* reports) override; 120 OperationStatus GetPendingReports(std::vector<Report>* reports) override;
121 OperationStatus GetCompletedReports(std::vector<Report>* reports) override; 121 OperationStatus GetCompletedReports(std::vector<Report>* reports) override;
122 OperationStatus GetReportForUploading(const UUID& uuid, 122 OperationStatus GetReportForUploading(const UUID& uuid,
123 const Report** report) override; 123 const Report** report) override;
124 OperationStatus RecordUploadAttempt(const Report* report, 124 OperationStatus RecordUploadAttempt(const Report* report,
125 bool successful, 125 bool successful,
126 const std::string& id) override; 126 const std::string& id) override;
127 OperationStatus SkipReportUpload(const UUID& uuid) override; 127 OperationStatus SkipReportUpload(const UUID& uuid) override;
128 OperationStatus DeleteReport(const UUID& uuid) override;
128 129
129 private: 130 private:
130 //! \brief A private extension of the Report class that maintains bookkeeping 131 //! \brief A private extension of the Report class that maintains bookkeeping
131 //! information of the database. 132 //! information of the database.
132 struct UploadReport : public Report { 133 struct UploadReport : public Report {
133 //! \brief Stores the flock of the file for the duration of 134 //! \brief Stores the flock of the file for the duration of
134 //! GetReportForUploading() and RecordUploadAttempt(). 135 //! GetReportForUploading() and RecordUploadAttempt().
135 int lock_fd; 136 int lock_fd;
136 }; 137 };
137 138
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 base_dir_.Append(kCompletedDirectory).Append(report_path.BaseName()); 470 base_dir_.Append(kCompletedDirectory).Append(report_path.BaseName());
470 if (rename(report_path.value().c_str(), new_path.value().c_str()) != 0) { 471 if (rename(report_path.value().c_str(), new_path.value().c_str()) != 0) {
471 PLOG(ERROR) << "rename " << report_path.value() << " to " 472 PLOG(ERROR) << "rename " << report_path.value() << " to "
472 << new_path.value(); 473 << new_path.value();
473 return kFileSystemError; 474 return kFileSystemError;
474 } 475 }
475 476
476 return kNoError; 477 return kNoError;
477 } 478 }
478 479
480 CrashReportDatabase::OperationStatus CrashReportDatabaseMac::DeleteReport(
481 const UUID& uuid) {
482 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
483
484 base::FilePath report_path = LocateCrashReport(uuid);
485 if (report_path.empty())
486 return kReportNotFound;
487
488 base::ScopedFD lock(ObtainReportLock(report_path));
489 if (!lock.is_valid())
490 return kBusyError;
491
492 if (unlink(report_path.value().c_str()) != 0) {
493 PLOG(ERROR) << "unlink " << report_path.value();
494 return kFileSystemError;
495 }
496
497 return kNoError;
498 }
499
479 base::FilePath CrashReportDatabaseMac::LocateCrashReport(const UUID& uuid) { 500 base::FilePath CrashReportDatabaseMac::LocateCrashReport(const UUID& uuid) {
480 const std::string target_uuid = uuid.ToString(); 501 const std::string target_uuid = uuid.ToString();
481 for (size_t i = 0; i < arraysize(kReportDirectories); ++i) { 502 for (size_t i = 0; i < arraysize(kReportDirectories); ++i) {
482 base::FilePath path = 503 base::FilePath path =
483 base_dir_.Append(kReportDirectories[i]) 504 base_dir_.Append(kReportDirectories[i])
484 .Append(target_uuid + "." + kCrashReportFileExtension); 505 .Append(target_uuid + "." + kCrashReportFileExtension);
485 506
486 // Test if the path exists. 507 // Test if the path exists.
487 struct stat st; 508 struct stat st;
488 if (lstat(path.value().c_str(), &st)) { 509 if (lstat(path.value().c_str(), &st)) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 const base::FilePath& path) { 623 const base::FilePath& path) {
603 scoped_ptr<CrashReportDatabaseMac> database_mac( 624 scoped_ptr<CrashReportDatabaseMac> database_mac(
604 new CrashReportDatabaseMac(path)); 625 new CrashReportDatabaseMac(path));
605 if (!database_mac->Initialize()) 626 if (!database_mac->Initialize())
606 database_mac.reset(); 627 database_mac.reset();
607 628
608 return scoped_ptr<CrashReportDatabase>(database_mac.release()); 629 return scoped_ptr<CrashReportDatabase>(database_mac.release());
609 } 630 }
610 631
611 } // namespace crashpad 632 } // namespace crashpad
OLDNEW
« no previous file with comments | « client/crash_report_database.h ('k') | client/crash_report_database_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698