| 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 <string.h> | 17 #include <string.h> |
| 18 #include <time.h> | 18 #include <time.h> |
| 19 #include <windows.h> | 19 #include <windows.h> |
| 20 | 20 |
| 21 #include "base/logging.h" | 21 #include "base/logging.h" |
| 22 #include "base/numerics/safe_math.h" | 22 #include "base/numerics/safe_math.h" |
| 23 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
| 24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "client/settings.h" |
| 26 #include "util/misc/initialization_state_dcheck.h" | 27 #include "util/misc/initialization_state_dcheck.h" |
| 27 | 28 |
| 28 namespace crashpad { | 29 namespace crashpad { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 const wchar_t kReportsDirectory[] = L"reports"; | 33 const wchar_t kReportsDirectory[] = L"reports"; |
| 33 const wchar_t kMetadataFileName[] = L"metadata"; | 34 const wchar_t kMetadataFileName[] = L"metadata"; |
| 34 | 35 |
| 36 const wchar_t kSettings[] = L"settings.dat"; |
| 37 |
| 35 const wchar_t kCrashReportFileExtension[] = L"dmp"; | 38 const wchar_t kCrashReportFileExtension[] = L"dmp"; |
| 36 | 39 |
| 37 const uint32_t kMetadataFileHeaderMagic = 'CPAD'; | 40 const uint32_t kMetadataFileHeaderMagic = 'CPAD'; |
| 38 const uint32_t kMetadataFileVersion = 1; | 41 const uint32_t kMetadataFileVersion = 1; |
| 39 | 42 |
| 40 using OperationStatus = CrashReportDatabase::OperationStatus; | 43 using OperationStatus = CrashReportDatabase::OperationStatus; |
| 41 | 44 |
| 42 // Helpers --------------------------------------------------------------------- | 45 // Helpers --------------------------------------------------------------------- |
| 43 | 46 |
| 44 // Adds a string to the string table and returns the byte index where it was | 47 // Adds a string to the string table and returns the byte index where it was |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 const Report** report) override; | 529 const Report** report) override; |
| 527 OperationStatus RecordUploadAttempt(const Report* report, | 530 OperationStatus RecordUploadAttempt(const Report* report, |
| 528 bool successful, | 531 bool successful, |
| 529 const std::string& id) override; | 532 const std::string& id) override; |
| 530 OperationStatus SkipReportUpload(const UUID& uuid) override; | 533 OperationStatus SkipReportUpload(const UUID& uuid) override; |
| 531 | 534 |
| 532 private: | 535 private: |
| 533 scoped_ptr<Metadata> AcquireMetadata(); | 536 scoped_ptr<Metadata> AcquireMetadata(); |
| 534 | 537 |
| 535 base::FilePath base_dir_; | 538 base::FilePath base_dir_; |
| 539 Settings settings_; |
| 536 InitializationStateDcheck initialized_; | 540 InitializationStateDcheck initialized_; |
| 537 | 541 |
| 538 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseWin); | 542 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseWin); |
| 539 }; | 543 }; |
| 540 | 544 |
| 541 CrashReportDatabaseWin::CrashReportDatabaseWin(const base::FilePath& path) | 545 CrashReportDatabaseWin::CrashReportDatabaseWin(const base::FilePath& path) |
| 542 : CrashReportDatabase(), base_dir_(path), initialized_() { | 546 : CrashReportDatabase(), |
| 547 base_dir_(path), |
| 548 settings_(base_dir_.Append(kSettings)), |
| 549 initialized_() { |
| 543 } | 550 } |
| 544 | 551 |
| 545 CrashReportDatabaseWin::~CrashReportDatabaseWin() { | 552 CrashReportDatabaseWin::~CrashReportDatabaseWin() { |
| 546 } | 553 } |
| 547 | 554 |
| 548 bool CrashReportDatabaseWin::Initialize() { | 555 bool CrashReportDatabaseWin::Initialize() { |
| 549 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); | 556 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); |
| 550 | 557 |
| 551 // Ensure the database and report subdirectories exist. | 558 // Ensure the database and report subdirectories exist. |
| 552 if (!CreateDirectoryIfNecessary(base_dir_) || | 559 if (!CreateDirectoryIfNecessary(base_dir_) || |
| 553 !CreateDirectoryIfNecessary(base_dir_.Append(kReportsDirectory))) | 560 !CreateDirectoryIfNecessary(base_dir_.Append(kReportsDirectory))) |
| 554 return false; | 561 return false; |
| 555 | 562 |
| 556 // TODO(scottmg): When are completed reports pruned from disk? Delete here or | 563 // TODO(scottmg): When are completed reports pruned from disk? Delete here or |
| 557 // maybe on AcquireMetadata(). | 564 // maybe on AcquireMetadata(). |
| 558 | 565 |
| 559 INITIALIZATION_STATE_SET_VALID(initialized_); | 566 INITIALIZATION_STATE_SET_VALID(initialized_); |
| 560 return true; | 567 return true; |
| 561 } | 568 } |
| 562 | 569 |
| 563 Settings* CrashReportDatabaseWin::GetSettings() { | 570 Settings* CrashReportDatabaseWin::GetSettings() { |
| 564 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 571 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 565 | 572 return &settings_; |
| 566 // Port to Win https://code.google.com/p/crashpad/issues/detail?id=13. | |
| 567 NOTREACHED(); | |
| 568 return nullptr; | |
| 569 } | 573 } |
| 570 | 574 |
| 571 OperationStatus CrashReportDatabaseWin::PrepareNewCrashReport( | 575 OperationStatus CrashReportDatabaseWin::PrepareNewCrashReport( |
| 572 NewReport** report) { | 576 NewReport** report) { |
| 573 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 577 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 574 | 578 |
| 575 scoped_ptr<NewReport> new_report(new NewReport()); | 579 scoped_ptr<NewReport> new_report(new NewReport()); |
| 576 if (!new_report->uuid.InitializeWithNew()) | 580 if (!new_report->uuid.InitializeWithNew()) |
| 577 return kFileSystemError; | 581 return kFileSystemError; |
| 578 new_report->path = base_dir_.Append(kReportsDirectory) | 582 new_report->path = base_dir_.Append(kReportsDirectory) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 // static | 749 // static |
| 746 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( | 750 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( |
| 747 const base::FilePath& path) { | 751 const base::FilePath& path) { |
| 748 scoped_ptr<CrashReportDatabaseWin> database_win( | 752 scoped_ptr<CrashReportDatabaseWin> database_win( |
| 749 new CrashReportDatabaseWin(path)); | 753 new CrashReportDatabaseWin(path)); |
| 750 return database_win->Initialize() ? database_win.Pass() | 754 return database_win->Initialize() ? database_win.Pass() |
| 751 : scoped_ptr<CrashReportDatabaseWin>(); | 755 : scoped_ptr<CrashReportDatabaseWin>(); |
| 752 } | 756 } |
| 753 | 757 |
| 754 } // namespace crashpad | 758 } // namespace crashpad |
| OLD | NEW |