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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 bool Initialize(); | 106 bool Initialize(); |
107 | 107 |
108 // CrashReportDatabase: | 108 // CrashReportDatabase: |
109 OperationStatus PrepareNewCrashReport(NewReport** report) override; | 109 OperationStatus PrepareNewCrashReport(NewReport** report) override; |
110 OperationStatus FinishedWritingCrashReport(NewReport* report, | 110 OperationStatus FinishedWritingCrashReport(NewReport* report, |
111 UUID* uuid) override; | 111 UUID* uuid) override; |
112 OperationStatus ErrorWritingCrashReport(NewReport* report) override; | 112 OperationStatus ErrorWritingCrashReport(NewReport* report) override; |
113 OperationStatus LookUpCrashReport(const UUID& uuid, | 113 OperationStatus LookUpCrashReport(const UUID& uuid, |
114 Report* report) override; | 114 Report* report) override; |
115 OperationStatus GetPendingReports( | 115 OperationStatus GetPendingReports(std::vector<Report>* reports) override; |
116 std::vector<const Report>* reports) override; | 116 OperationStatus GetCompletedReports(std::vector<Report>* reports) override; |
117 OperationStatus GetCompletedReports( | |
118 std::vector<const Report>* reports) override; | |
119 OperationStatus GetReportForUploading(const UUID& uuid, | 117 OperationStatus GetReportForUploading(const UUID& uuid, |
120 const Report** report) override; | 118 const Report** report) override; |
121 OperationStatus RecordUploadAttempt(const Report* report, | 119 OperationStatus RecordUploadAttempt(const Report* report, |
122 bool successful, | 120 bool successful, |
123 const std::string& id) override; | 121 const std::string& id) override; |
124 OperationStatus SkipReportUpload(const UUID& uuid) override; | 122 OperationStatus SkipReportUpload(const UUID& uuid) override; |
125 | 123 |
126 private: | 124 private: |
127 //! \brief A private extension of the Report class that maintains bookkeeping | 125 //! \brief A private extension of the Report class that maintains bookkeeping |
128 //! information of the database. | 126 //! information of the database. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 Report* report); | 166 Report* report); |
169 | 167 |
170 //! \brief Reads the metadata from all the reports in a database subdirectory. | 168 //! \brief Reads the metadata from all the reports in a database subdirectory. |
171 //! Invalid reports are skipped. | 169 //! Invalid reports are skipped. |
172 //! | 170 //! |
173 //! \param[in] path The database subdirectory path. | 171 //! \param[in] path The database subdirectory path. |
174 //! \param[out] reports An empty vector of reports, which will be filled. | 172 //! \param[out] reports An empty vector of reports, which will be filled. |
175 //! | 173 //! |
176 //! \return The operation status code. | 174 //! \return The operation status code. |
177 static OperationStatus ReportsInDirectory(const base::FilePath& path, | 175 static OperationStatus ReportsInDirectory(const base::FilePath& path, |
178 std::vector<const Report>* reports); | 176 std::vector<Report>* reports); |
179 | 177 |
180 | 178 |
181 //! \brief Creates a database xattr name from the short constant name. | 179 //! \brief Creates a database xattr name from the short constant name. |
182 //! | 180 //! |
183 //! \param[in] name The short name of the extended attribute. | 181 //! \param[in] name The short name of the extended attribute. |
184 //! | 182 //! |
185 //! \return The long name of the extended attribute. | 183 //! \return The long name of the extended attribute. |
186 static std::string XattrName(const base::StringPiece& name); | 184 static std::string XattrName(const base::StringPiece& name); |
187 | 185 |
188 base::FilePath base_dir_; | 186 base::FilePath base_dir_; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 *report = Report(); | 310 *report = Report(); |
313 report->file_path = path; | 311 report->file_path = path; |
314 if (!ReadReportMetadataLocked(path, report)) | 312 if (!ReadReportMetadataLocked(path, report)) |
315 return kDatabaseError; | 313 return kDatabaseError; |
316 | 314 |
317 return kNoError; | 315 return kNoError; |
318 } | 316 } |
319 | 317 |
320 CrashReportDatabase::OperationStatus | 318 CrashReportDatabase::OperationStatus |
321 CrashReportDatabaseMac::GetPendingReports( | 319 CrashReportDatabaseMac::GetPendingReports( |
322 std::vector<const CrashReportDatabase::Report>* reports) { | 320 std::vector<CrashReportDatabase::Report>* reports) { |
323 return ReportsInDirectory(base_dir_.Append(kUploadPendingDirectory), reports); | 321 return ReportsInDirectory(base_dir_.Append(kUploadPendingDirectory), reports); |
324 } | 322 } |
325 | 323 |
326 CrashReportDatabase::OperationStatus | 324 CrashReportDatabase::OperationStatus |
327 CrashReportDatabaseMac::GetCompletedReports( | 325 CrashReportDatabaseMac::GetCompletedReports( |
328 std::vector<const CrashReportDatabase::Report>* reports) { | 326 std::vector<CrashReportDatabase::Report>* reports) { |
329 return ReportsInDirectory(base_dir_.Append(kCompletedDirectory), reports); | 327 return ReportsInDirectory(base_dir_.Append(kCompletedDirectory), reports); |
330 } | 328 } |
331 | 329 |
332 CrashReportDatabase::OperationStatus | 330 CrashReportDatabase::OperationStatus |
333 CrashReportDatabaseMac::GetReportForUploading(const UUID& uuid, | 331 CrashReportDatabaseMac::GetReportForUploading(const UUID& uuid, |
334 const Report** report) { | 332 const Report** report) { |
335 base::FilePath report_path = LocateCrashReport(uuid); | 333 base::FilePath report_path = LocateCrashReport(uuid); |
336 if (report_path.empty()) | 334 if (report_path.empty()) |
337 return kReportNotFound; | 335 return kReportNotFound; |
338 | 336 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 } | 446 } |
449 } | 447 } |
450 | 448 |
451 return base::FilePath(); | 449 return base::FilePath(); |
452 } | 450 } |
453 | 451 |
454 // static | 452 // static |
455 base::ScopedFD CrashReportDatabaseMac::ObtainReportLock( | 453 base::ScopedFD CrashReportDatabaseMac::ObtainReportLock( |
456 const base::FilePath& path) { | 454 const base::FilePath& path) { |
457 int fd = HANDLE_EINTR(open(path.value().c_str(), | 455 int fd = HANDLE_EINTR(open(path.value().c_str(), |
458 O_RDONLY | O_EXLOCK | O_CLOEXEC | O_NONBLOCK)); | 456 O_RDONLY | O_EXLOCK | O_NONBLOCK)); |
459 PLOG_IF(ERROR, fd < 0) << "open lock " << path.value(); | 457 PLOG_IF(ERROR, fd < 0) << "open lock " << path.value(); |
460 return base::ScopedFD(fd); | 458 return base::ScopedFD(fd); |
461 } | 459 } |
462 | 460 |
463 // static | 461 // static |
464 bool CrashReportDatabaseMac::ReadReportMetadataLocked( | 462 bool CrashReportDatabaseMac::ReadReportMetadataLocked( |
465 const base::FilePath& path, Report* report) { | 463 const base::FilePath& path, Report* report) { |
466 std::string uuid_string; | 464 std::string uuid_string; |
467 if (ReadXattr(path, XattrName(kXattrUUID), | 465 if (ReadXattr(path, XattrName(kXattrUUID), |
468 &uuid_string) != XattrStatus::kOK || | 466 &uuid_string) != XattrStatus::kOK || |
(...skipping 30 matching lines...) Expand all Loading... |
499 &report->upload_attempts) == XattrStatus::kOtherError) { | 497 &report->upload_attempts) == XattrStatus::kOtherError) { |
500 return false; | 498 return false; |
501 } | 499 } |
502 | 500 |
503 return true; | 501 return true; |
504 } | 502 } |
505 | 503 |
506 // static | 504 // static |
507 CrashReportDatabase::OperationStatus CrashReportDatabaseMac::ReportsInDirectory( | 505 CrashReportDatabase::OperationStatus CrashReportDatabaseMac::ReportsInDirectory( |
508 const base::FilePath& path, | 506 const base::FilePath& path, |
509 std::vector<const CrashReportDatabase::Report>* reports) { | 507 std::vector<CrashReportDatabase::Report>* reports) { |
510 DCHECK(reports->empty()); | 508 DCHECK(reports->empty()); |
511 | 509 |
512 NSError* error = nil; | 510 NSError* error = nil; |
513 NSArray* paths = [[NSFileManager defaultManager] | 511 NSArray* paths = [[NSFileManager defaultManager] |
514 contentsOfDirectoryAtPath:base::SysUTF8ToNSString(path.value()) | 512 contentsOfDirectoryAtPath:base::SysUTF8ToNSString(path.value()) |
515 error:&error]; | 513 error:&error]; |
516 if (error) { | 514 if (error) { |
517 LOG(ERROR) << "Failed to enumerate reports in directory " << path.value() | 515 LOG(ERROR) << "Failed to enumerate reports in directory " << path.value() |
518 << ": " << [[error description] UTF8String]; | 516 << ": " << [[error description] UTF8String]; |
519 return kFileSystemError; | 517 return kFileSystemError; |
(...skipping 30 matching lines...) Expand all Loading... |
550 const base::FilePath& path) { | 548 const base::FilePath& path) { |
551 scoped_ptr<CrashReportDatabaseMac> database_mac( | 549 scoped_ptr<CrashReportDatabaseMac> database_mac( |
552 new CrashReportDatabaseMac(path.Append(kDatabaseDirectoryName))); | 550 new CrashReportDatabaseMac(path.Append(kDatabaseDirectoryName))); |
553 if (!database_mac->Initialize()) | 551 if (!database_mac->Initialize()) |
554 database_mac.reset(); | 552 database_mac.reset(); |
555 | 553 |
556 return scoped_ptr<CrashReportDatabase>(database_mac.release()); | 554 return scoped_ptr<CrashReportDatabase>(database_mac.release()); |
557 } | 555 } |
558 | 556 |
559 } // namespace crashpad | 557 } // namespace crashpad |
OLD | NEW |