Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: client/crash_report_database_mac.mm

Issue 988063003: Define the Settings interface for a CrashReportDatabase and provide a Mac implementation. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: INITIALIZATION_STATE_DCHECK Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(std::vector<Report>* reports) override; 120 OperationStatus GetPendingReports(std::vector<Report>* reports) override;
116 OperationStatus GetCompletedReports(std::vector<Report>* reports) override; 121 OperationStatus GetCompletedReports(std::vector<Report>* reports) override;
117 OperationStatus GetReportForUploading(const UUID& uuid, 122 OperationStatus GetReportForUploading(const UUID& uuid,
118 const Report** report) override; 123 const Report** report) override;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 182
178 183
179 //! \brief Creates a database xattr name from the short constant name. 184 //! \brief Creates a database xattr name from the short constant name.
180 //! 185 //!
181 //! \param[in] name The short name of the extended attribute. 186 //! \param[in] name The short name of the extended attribute.
182 //! 187 //!
183 //! \return The long name of the extended attribute. 188 //! \return The long name of the extended attribute.
184 static std::string XattrName(const base::StringPiece& name); 189 static std::string XattrName(const base::StringPiece& name);
185 190
186 base::FilePath base_dir_; 191 base::FilePath base_dir_;
192 Settings settings_;
187 193
188 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseMac); 194 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseMac);
189 }; 195 };
190 196
191 CrashReportDatabaseMac::CrashReportDatabaseMac(const base::FilePath& path) 197 CrashReportDatabaseMac::CrashReportDatabaseMac(const base::FilePath& path)
192 : CrashReportDatabase(), base_dir_(path) { 198 : CrashReportDatabase(),
199 base_dir_(path),
200 settings_(base_dir_.Append(kSettings)) {
193 } 201 }
194 202
195 CrashReportDatabaseMac::~CrashReportDatabaseMac() {} 203 CrashReportDatabaseMac::~CrashReportDatabaseMac() {}
196 204
197 bool CrashReportDatabaseMac::Initialize() { 205 bool CrashReportDatabaseMac::Initialize() {
198 // Check if the database already exists. 206 // Check if the database already exists.
199 if (!CreateOrEnsureDirectoryExists(base_dir_)) 207 if (!CreateOrEnsureDirectoryExists(base_dir_))
200 return false; 208 return false;
201 209
202 // Create the three processing directories for the database. 210 // Create the three processing directories for the database.
203 for (size_t i = 0; i < arraysize(kReportDirectories); ++i) { 211 for (size_t i = 0; i < arraysize(kReportDirectories); ++i) {
204 if (!CreateOrEnsureDirectoryExists(base_dir_.Append(kReportDirectories[i]))) 212 if (!CreateOrEnsureDirectoryExists(base_dir_.Append(kReportDirectories[i])))
205 return false; 213 return false;
206 } 214 }
207 215
216 if (!settings_.Initialize())
217 return false;
218
208 // Write an xattr as the last step, to ensure the filesystem has support for 219 // Write an xattr as the last step, to ensure the filesystem has support for
209 // them. This attribute will never be read. 220 // them. This attribute will never be read.
210 return WriteXattrBool(base_dir_, XattrName(kXattrDatabaseInitialized), true); 221 return WriteXattrBool(base_dir_, XattrName(kXattrDatabaseInitialized), true);
211 } 222 }
212 223
224 Settings* CrashReportDatabaseMac::GetSettings() {
225 return &settings_;
226 }
227
213 CrashReportDatabase::OperationStatus 228 CrashReportDatabase::OperationStatus
214 CrashReportDatabaseMac::PrepareNewCrashReport(NewReport** out_report) { 229 CrashReportDatabaseMac::PrepareNewCrashReport(NewReport** out_report) {
215 uuid_t uuid_gen; 230 uuid_t uuid_gen;
216 uuid_generate(uuid_gen); 231 uuid_generate(uuid_gen);
217 UUID uuid(uuid_gen); 232 UUID uuid(uuid_gen);
218 233
219 scoped_ptr<NewReport> report(new NewReport()); 234 scoped_ptr<NewReport> report(new NewReport());
220 235
221 report->path = 236 report->path =
222 base_dir_.Append(kWriteDirectory) 237 base_dir_.Append(kWriteDirectory)
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 return false; 513 return false;
499 } 514 }
500 515
501 return true; 516 return true;
502 } 517 }
503 518
504 // static 519 // static
505 CrashReportDatabase::OperationStatus CrashReportDatabaseMac::ReportsInDirectory( 520 CrashReportDatabase::OperationStatus CrashReportDatabaseMac::ReportsInDirectory(
506 const base::FilePath& path, 521 const base::FilePath& path,
507 std::vector<CrashReportDatabase::Report>* reports) { 522 std::vector<CrashReportDatabase::Report>* reports) {
523 base::mac::ScopedNSAutoreleasePool pool;
524
508 DCHECK(reports->empty()); 525 DCHECK(reports->empty());
509 526
510 NSError* error = nil; 527 NSError* error = nil;
511 NSArray* paths = [[NSFileManager defaultManager] 528 NSArray* paths = [[NSFileManager defaultManager]
512 contentsOfDirectoryAtPath:base::SysUTF8ToNSString(path.value()) 529 contentsOfDirectoryAtPath:base::SysUTF8ToNSString(path.value())
513 error:&error]; 530 error:&error];
514 if (error) { 531 if (error) {
515 LOG(ERROR) << "Failed to enumerate reports in directory " << path.value() 532 LOG(ERROR) << "Failed to enumerate reports in directory " << path.value()
516 << ": " << [[error description] UTF8String]; 533 << ": " << [[error description] UTF8String];
517 return kFileSystemError; 534 return kFileSystemError;
(...skipping 30 matching lines...) Expand all
548 const base::FilePath& path) { 565 const base::FilePath& path) {
549 scoped_ptr<CrashReportDatabaseMac> database_mac( 566 scoped_ptr<CrashReportDatabaseMac> database_mac(
550 new CrashReportDatabaseMac(path.Append(kDatabaseDirectoryName))); 567 new CrashReportDatabaseMac(path.Append(kDatabaseDirectoryName)));
551 if (!database_mac->Initialize()) 568 if (!database_mac->Initialize())
552 database_mac.reset(); 569 database_mac.reset();
553 570
554 return scoped_ptr<CrashReportDatabase>(database_mac.release()); 571 return scoped_ptr<CrashReportDatabase>(database_mac.release());
555 } 572 }
556 573
557 } // namespace crashpad 574 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698