Chromium Code Reviews| 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, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "client/crash_report_database.h" | 15 #include "client/crash_report_database.h" |
| 16 | 16 |
| 17 #include <errno.h> | 17 #include <errno.h> |
| 18 #include <fcntl.h> | 18 #include <fcntl.h> |
| 19 #import <Foundation/Foundation.h> | 19 #import <Foundation/Foundation.h> |
| 20 #include <stdio.h> | 20 #include <stdio.h> |
| 21 #include <sys/stat.h> | 21 #include <sys/stat.h> |
| 22 #include <sys/types.h> | 22 #include <sys/types.h> |
| 23 #include <time.h> | |
| 23 #include <unistd.h> | 24 #include <unistd.h> |
| 24 #include <uuid/uuid.h> | 25 #include <uuid/uuid.h> |
| 25 | 26 |
| 26 #include "base/logging.h" | 27 #include "base/logging.h" |
| 27 #include "base/mac/scoped_nsautorelease_pool.h" | 28 #include "base/mac/scoped_nsautorelease_pool.h" |
| 28 #include "base/posix/eintr_wrapper.h" | 29 #include "base/posix/eintr_wrapper.h" |
| 29 #include "base/scoped_generic.h" | 30 #include "base/scoped_generic.h" |
| 30 #include "base/strings/string_piece.h" | 31 #include "base/strings/string_piece.h" |
| 31 #include "base/strings/stringprintf.h" | 32 #include "base/strings/stringprintf.h" |
| 32 #include "base/strings/sys_string_conversions.h" | 33 #include "base/strings/sys_string_conversions.h" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 } | 393 } |
| 393 report_path = new_path; | 394 report_path = new_path; |
| 394 } | 395 } |
| 395 | 396 |
| 396 if (!WriteXattrBool(report_path, XattrName(kXattrIsUploaded), successful)) { | 397 if (!WriteXattrBool(report_path, XattrName(kXattrIsUploaded), successful)) { |
| 397 return kDatabaseError; | 398 return kDatabaseError; |
| 398 } | 399 } |
| 399 if (!WriteXattr(report_path, XattrName(kXattrCollectorID), id)) { | 400 if (!WriteXattr(report_path, XattrName(kXattrCollectorID), id)) { |
| 400 return kDatabaseError; | 401 return kDatabaseError; |
| 401 } | 402 } |
| 402 if (!WriteXattrTimeT(report_path, | 403 |
| 403 XattrName(kXattrLastUploadTime), | 404 time_t now = time(nullptr); |
| 404 time(nullptr))) { | 405 if (!WriteXattrTimeT(report_path, XattrName(kXattrLastUploadTime), now)) { |
| 405 return kDatabaseError; | 406 return kDatabaseError; |
| 406 } | 407 } |
| 407 | 408 |
| 408 int upload_attempts = 0; | 409 int upload_attempts = 0; |
| 409 std::string name = XattrName(kXattrUploadAttemptCount); | 410 std::string name = XattrName(kXattrUploadAttemptCount); |
| 410 if (ReadXattrInt(report_path, name, &upload_attempts) == | 411 if (ReadXattrInt(report_path, name, &upload_attempts) == |
| 411 XattrStatus::kOtherError) { | 412 XattrStatus::kOtherError) { |
| 412 return kDatabaseError; | 413 return kDatabaseError; |
| 413 } | 414 } |
| 414 if (!WriteXattrInt(report_path, name, ++upload_attempts)) { | 415 if (!WriteXattrInt(report_path, name, ++upload_attempts)) { |
| 415 return kDatabaseError; | 416 return kDatabaseError; |
| 416 } | 417 } |
| 417 | 418 |
| 419 if (!settings_.SetLastUploadAttemptTime(now)) { | |
| 420 return kDatabaseError; | |
|
Mark Mentovai
2015/03/10 16:02:57
We could also come up with a new enum value just f
Robert Sesek
2015/03/10 16:13:10
I think this is fine.
| |
| 421 } | |
| 422 | |
| 418 return kNoError; | 423 return kNoError; |
| 419 } | 424 } |
| 420 | 425 |
| 421 CrashReportDatabase::OperationStatus CrashReportDatabaseMac::SkipReportUpload( | 426 CrashReportDatabase::OperationStatus CrashReportDatabaseMac::SkipReportUpload( |
| 422 const UUID& uuid) { | 427 const UUID& uuid) { |
| 423 base::FilePath report_path = LocateCrashReport(uuid); | 428 base::FilePath report_path = LocateCrashReport(uuid); |
| 424 if (report_path.empty()) | 429 if (report_path.empty()) |
| 425 return kReportNotFound; | 430 return kReportNotFound; |
| 426 | 431 |
| 427 base::ScopedFD lock(ObtainReportLock(report_path)); | 432 base::ScopedFD lock(ObtainReportLock(report_path)); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 const base::FilePath& path) { | 570 const base::FilePath& path) { |
| 566 scoped_ptr<CrashReportDatabaseMac> database_mac( | 571 scoped_ptr<CrashReportDatabaseMac> database_mac( |
| 567 new CrashReportDatabaseMac(path.Append(kDatabaseDirectoryName))); | 572 new CrashReportDatabaseMac(path.Append(kDatabaseDirectoryName))); |
| 568 if (!database_mac->Initialize()) | 573 if (!database_mac->Initialize()) |
| 569 database_mac.reset(); | 574 database_mac.reset(); |
| 570 | 575 |
| 571 return scoped_ptr<CrashReportDatabase>(database_mac.release()); | 576 return scoped_ptr<CrashReportDatabase>(database_mac.release()); |
| 572 } | 577 } |
| 573 | 578 |
| 574 } // namespace crashpad | 579 } // namespace crashpad |
| OLD | NEW |