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