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 11 matching lines...) Expand all Loading... | |
22 #include <sys/types.h> | 22 #include <sys/types.h> |
23 #include <unistd.h> | 23 #include <unistd.h> |
24 #include <uuid/uuid.h> | 24 #include <uuid/uuid.h> |
25 | 25 |
26 #include "base/logging.h" | 26 #include "base/logging.h" |
27 #include "base/posix/eintr_wrapper.h" | 27 #include "base/posix/eintr_wrapper.h" |
28 #include "base/scoped_generic.h" | 28 #include "base/scoped_generic.h" |
29 #include "base/strings/string_piece.h" | 29 #include "base/strings/string_piece.h" |
30 #include "base/strings/stringprintf.h" | 30 #include "base/strings/stringprintf.h" |
31 #include "base/strings/sys_string_conversions.h" | 31 #include "base/strings/sys_string_conversions.h" |
32 #include "client/settings_mac.h" | |
32 #include "util/file/file_io.h" | 33 #include "util/file/file_io.h" |
33 #include "util/mac/xattr.h" | 34 #include "util/mac/xattr.h" |
34 | 35 |
35 namespace crashpad { | 36 namespace crashpad { |
36 | 37 |
37 namespace { | 38 namespace { |
38 | 39 |
39 const char kDatabaseDirectoryName[] = "Crashpad"; | 40 const char kDatabaseDirectoryName[] = "Crashpad"; |
40 | 41 |
41 const char kWriteDirectory[] = "new"; | 42 const char kWriteDirectory[] = "new"; |
42 const char kUploadPendingDirectory[] = "pending"; | 43 const char kUploadPendingDirectory[] = "pending"; |
43 const char kCompletedDirectory[] = "completed"; | 44 const char kCompletedDirectory[] = "completed"; |
44 | 45 |
46 const char kSettings[] = "settings.plist"; | |
47 | |
45 const char* const kReportDirectories[] = { | 48 const char* const kReportDirectories[] = { |
46 kWriteDirectory, | 49 kWriteDirectory, |
47 kUploadPendingDirectory, | 50 kUploadPendingDirectory, |
48 kCompletedDirectory, | 51 kCompletedDirectory, |
49 }; | 52 }; |
50 | 53 |
51 const char kCrashReportFileExtension[] = "dmp"; | 54 const char kCrashReportFileExtension[] = "dmp"; |
52 | 55 |
53 const char kXattrUUID[] = "uuid"; | 56 const char kXattrUUID[] = "uuid"; |
54 const char kXattrCollectorID[] = "id"; | 57 const char kXattrCollectorID[] = "id"; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 //! extended attribute operations. The lock should be obtained using | 102 //! extended attribute operations. The lock should be obtained using |
100 //! ObtainReportLock(). | 103 //! ObtainReportLock(). |
101 class CrashReportDatabaseMac : public CrashReportDatabase { | 104 class CrashReportDatabaseMac : public CrashReportDatabase { |
102 public: | 105 public: |
103 explicit CrashReportDatabaseMac(const base::FilePath& path); | 106 explicit CrashReportDatabaseMac(const base::FilePath& path); |
104 virtual ~CrashReportDatabaseMac(); | 107 virtual ~CrashReportDatabaseMac(); |
105 | 108 |
106 bool Initialize(); | 109 bool Initialize(); |
107 | 110 |
108 // CrashReportDatabase: | 111 // CrashReportDatabase: |
112 Settings* GetSettings() override; | |
109 OperationStatus PrepareNewCrashReport(NewReport** report) override; | 113 OperationStatus PrepareNewCrashReport(NewReport** report) override; |
110 OperationStatus FinishedWritingCrashReport(NewReport* report, | 114 OperationStatus FinishedWritingCrashReport(NewReport* report, |
111 UUID* uuid) override; | 115 UUID* uuid) override; |
112 OperationStatus ErrorWritingCrashReport(NewReport* report) override; | 116 OperationStatus ErrorWritingCrashReport(NewReport* report) override; |
113 OperationStatus LookUpCrashReport(const UUID& uuid, | 117 OperationStatus LookUpCrashReport(const UUID& uuid, |
114 Report* report) override; | 118 Report* report) override; |
115 OperationStatus GetPendingReports( | 119 OperationStatus GetPendingReports( |
116 std::vector<const Report>* reports) override; | 120 std::vector<const Report>* reports) override; |
117 OperationStatus GetCompletedReports( | 121 OperationStatus GetCompletedReports( |
118 std::vector<const Report>* reports) override; | 122 std::vector<const Report>* reports) override; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 | 183 |
180 | 184 |
181 //! \brief Creates a database xattr name from the short constant name. | 185 //! \brief Creates a database xattr name from the short constant name. |
182 //! | 186 //! |
183 //! \param[in] name The short name of the extended attribute. | 187 //! \param[in] name The short name of the extended attribute. |
184 //! | 188 //! |
185 //! \return The long name of the extended attribute. | 189 //! \return The long name of the extended attribute. |
186 static std::string XattrName(const base::StringPiece& name); | 190 static std::string XattrName(const base::StringPiece& name); |
187 | 191 |
188 base::FilePath base_dir_; | 192 base::FilePath base_dir_; |
193 internal::SettingsMac settings_; | |
189 | 194 |
190 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseMac); | 195 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseMac); |
191 }; | 196 }; |
192 | 197 |
193 CrashReportDatabaseMac::CrashReportDatabaseMac(const base::FilePath& path) | 198 CrashReportDatabaseMac::CrashReportDatabaseMac(const base::FilePath& path) |
194 : CrashReportDatabase(), base_dir_(path) { | 199 : CrashReportDatabase(), |
200 base_dir_(path), | |
201 settings_(base_dir_.Append(kSettings)) { | |
195 } | 202 } |
196 | 203 |
197 CrashReportDatabaseMac::~CrashReportDatabaseMac() {} | 204 CrashReportDatabaseMac::~CrashReportDatabaseMac() {} |
198 | 205 |
199 bool CrashReportDatabaseMac::Initialize() { | 206 bool CrashReportDatabaseMac::Initialize() { |
200 // Check if the database already exists. | 207 // Check if the database already exists. |
201 if (!CreateOrEnsureDirectoryExists(base_dir_)) | 208 if (!CreateOrEnsureDirectoryExists(base_dir_)) |
202 return false; | 209 return false; |
203 | 210 |
204 // Create the three processing directories for the database. | 211 // Create the three processing directories for the database. |
205 for (size_t i = 0; i < arraysize(kReportDirectories); ++i) { | 212 for (size_t i = 0; i < arraysize(kReportDirectories); ++i) { |
206 if (!CreateOrEnsureDirectoryExists(base_dir_.Append(kReportDirectories[i]))) | 213 if (!CreateOrEnsureDirectoryExists(base_dir_.Append(kReportDirectories[i]))) |
207 return false; | 214 return false; |
208 } | 215 } |
209 | 216 |
217 if (!settings_.Initialize()) | |
218 return false; | |
219 | |
210 // Write an xattr as the last step, to ensure the filesystem has support for | 220 // Write an xattr as the last step, to ensure the filesystem has support for |
211 // them. This attribute will never be read. | 221 // them. This attribute will never be read. |
212 return WriteXattrBool(base_dir_, XattrName(kXattrDatabaseInitialized), true); | 222 return WriteXattrBool(base_dir_, XattrName(kXattrDatabaseInitialized), true); |
213 } | 223 } |
214 | 224 |
225 Settings* CrashReportDatabaseMac::GetSettings() { | |
226 return &settings_; | |
227 } | |
228 | |
215 CrashReportDatabase::OperationStatus | 229 CrashReportDatabase::OperationStatus |
216 CrashReportDatabaseMac::PrepareNewCrashReport(NewReport** out_report) { | 230 CrashReportDatabaseMac::PrepareNewCrashReport(NewReport** out_report) { |
217 uuid_t uuid_gen; | 231 uuid_t uuid_gen; |
218 uuid_generate(uuid_gen); | 232 uuid_generate(uuid_gen); |
219 UUID uuid(uuid_gen); | 233 UUID uuid(uuid_gen); |
220 | 234 |
221 scoped_ptr<NewReport> report(new NewReport()); | 235 scoped_ptr<NewReport> report(new NewReport()); |
222 | 236 |
223 report->path = | 237 report->path = |
224 base_dir_.Append(kWriteDirectory) | 238 base_dir_.Append(kWriteDirectory) |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 return true; | 517 return true; |
504 } | 518 } |
505 | 519 |
506 // static | 520 // static |
507 CrashReportDatabase::OperationStatus CrashReportDatabaseMac::ReportsInDirectory( | 521 CrashReportDatabase::OperationStatus CrashReportDatabaseMac::ReportsInDirectory( |
508 const base::FilePath& path, | 522 const base::FilePath& path, |
509 std::vector<const CrashReportDatabase::Report>* reports) { | 523 std::vector<const CrashReportDatabase::Report>* reports) { |
510 DCHECK(reports->empty()); | 524 DCHECK(reports->empty()); |
511 | 525 |
512 NSError* error = nil; | 526 NSError* error = nil; |
513 NSArray* paths = [[NSFileManager defaultManager] | 527 NSArray* paths = [[NSFileManager defaultManager] |
Mark Mentovai
2015/03/09 14:01:23
This talk of the autorelease pool in Settings prom
| |
514 contentsOfDirectoryAtPath:base::SysUTF8ToNSString(path.value()) | 528 contentsOfDirectoryAtPath:base::SysUTF8ToNSString(path.value()) |
515 error:&error]; | 529 error:&error]; |
516 if (error) { | 530 if (error) { |
517 LOG(ERROR) << "Failed to enumerate reports in directory " << path.value() | 531 LOG(ERROR) << "Failed to enumerate reports in directory " << path.value() |
518 << ": " << [[error description] UTF8String]; | 532 << ": " << [[error description] UTF8String]; |
519 return kFileSystemError; | 533 return kFileSystemError; |
520 } | 534 } |
521 | 535 |
522 reports->reserve([paths count]); | 536 reports->reserve([paths count]); |
523 for (NSString* entry in paths) { | 537 for (NSString* entry in paths) { |
(...skipping 26 matching lines...) Expand all Loading... | |
550 const base::FilePath& path) { | 564 const base::FilePath& path) { |
551 scoped_ptr<CrashReportDatabaseMac> database_mac( | 565 scoped_ptr<CrashReportDatabaseMac> database_mac( |
552 new CrashReportDatabaseMac(path.Append(kDatabaseDirectoryName))); | 566 new CrashReportDatabaseMac(path.Append(kDatabaseDirectoryName))); |
553 if (!database_mac->Initialize()) | 567 if (!database_mac->Initialize()) |
554 database_mac.reset(); | 568 database_mac.reset(); |
555 | 569 |
556 return scoped_ptr<CrashReportDatabase>(database_mac.release()); | 570 return scoped_ptr<CrashReportDatabase>(database_mac.release()); |
557 } | 571 } |
558 | 572 |
559 } // namespace crashpad | 573 } // namespace crashpad |
OLD | NEW |