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 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 const wchar_t kDatabaseDirectoryName[] = L"Crashpad"; | 31 const wchar_t kDatabaseDirectoryName[] = L"Crashpad"; |
32 | 32 |
33 const wchar_t kReportsDirectory[] = L"reports"; | 33 const wchar_t kReportsDirectory[] = L"reports"; |
34 const wchar_t kMetadataFileName[] = L"metadata"; | 34 const wchar_t kMetadataFileName[] = L"metadata"; |
35 | 35 |
36 const wchar_t kCrashReportFileExtension[] = L"dmp"; | 36 const wchar_t kCrashReportFileExtension[] = L"dmp"; |
37 | 37 |
38 enum class ReportState : int { | 38 enum class ReportState : int { |
Peter Kasting
2015/02/13 00:32:39
Seems like this should be "int32_t" rather than "i
scottmg
2015/02/13 06:34:05
This one isn't used directly for serialization, so
| |
39 //! \brief Created and filled out by caller, owned by database. | 39 //! \brief Created and filled out by caller, owned by database. |
40 kPending, | 40 kPending, |
41 //! \brief In the process of uploading, owned by caller. | 41 //! \brief In the process of uploading, owned by caller. |
42 kUploading, | 42 kUploading, |
43 //! \brief Upload completed or skipped, owned by database. | 43 //! \brief Upload completed or skipped, owned by database. |
44 kCompleted, | 44 kCompleted, |
45 }; | 45 }; |
46 | 46 |
47 using OperationStatus = CrashReportDatabase::OperationStatus; | 47 using OperationStatus = CrashReportDatabase::OperationStatus; |
48 | 48 |
49 //! \brief Ensures that the node at path is a directory, and creates it if it | 49 //! \brief Ensures that the node at path is a directory, and creates it if it |
50 //! does not exist. | 50 //! does not exist. |
51 //! | 51 //! |
52 //! \return If the path points to a file, rather than a directory, or the | 52 //! \return If the path points to a file, rather than a directory, or the |
53 //! directory could not be created, returns `false`. Otherwise, returns | 53 //! directory could not be created, returns `false`. Otherwise, returns |
54 //! `true`, indicating that path already was or now is a directory. | 54 //! `true`, indicating that path already was or now is a directory. |
55 bool CreateOrEnsureDirectoryExists(const base::FilePath& path) { | 55 bool CreateOrEnsureDirectoryExists(const base::FilePath& path) { |
Peter Kasting
2015/02/13 00:32:39
Nit: "EnsureDirectoryExists" or "CreateDirectoryIf
scottmg
2015/02/13 06:34:02
Done.
| |
56 if (CreateDirectory(path.value().c_str(), nullptr)) { | 56 if (CreateDirectory(path.value().c_str(), nullptr)) { |
57 return true; | 57 return true; |
58 } else if (GetLastError() == ERROR_ALREADY_EXISTS) { | 58 } else if (GetLastError() == ERROR_ALREADY_EXISTS) { |
Peter Kasting
2015/02/13 00:32:39
Don't use "else" after "return"; see http://dev.ch
scottmg
2015/02/13 06:34:03
Done. (!= ERROR_ALREADY_EXISTS above)
| |
59 DWORD fileattr = GetFileAttributes(path.value().c_str()); | 59 DWORD fileattr = GetFileAttributes(path.value().c_str()); |
60 if (fileattr == INVALID_FILE_ATTRIBUTES) { | 60 if (fileattr == INVALID_FILE_ATTRIBUTES) { |
61 PLOG(ERROR) << "GetFileAttributes"; | 61 PLOG(ERROR) << "GetFileAttributes"; |
Peter Kasting
2015/02/13 00:32:39
Unless you have a way of collecting and analyzing
scottmg
2015/02/13 06:34:02
Noted the general preference to avoid bloat in log
Peter Kasting
2015/02/13 22:30:33
Ack. I wonder if that decision should be captured
| |
62 return false; | 62 return false; |
63 } | 63 } |
64 if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) | 64 if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) |
65 return true; | 65 return true; |
66 LOG(ERROR) << "not a directory"; | 66 LOG(ERROR) << "not a directory"; |
67 return false; | 67 return false; |
68 } else { | 68 } else { |
69 PLOG(ERROR) << "CreateDirectory"; | 69 PLOG(ERROR) << "CreateDirectory"; |
70 return false; | 70 return false; |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 //! \brief A private extension of the Report class that includes additional data | 74 //! \brief A private extension of the Report class that includes additional data |
75 //! that's stored on disk in the metadata file. | 75 //! that's stored on disk in the metadata file. |
76 struct ReportDisk : public CrashReportDatabase::Report { | 76 struct ReportDisk : public CrashReportDatabase::Report { |
77 //! \brief The current state of the report. | 77 //! \brief The current state of the report. |
78 ReportState state; | 78 ReportState state; |
79 }; | 79 }; |
80 | 80 |
81 //! \brief A private extension of the NewReport class to hold the UUID during | 81 //! \brief A private extension of the NewReport class to hold the UUID during |
82 //! initial write. We don't store metadata in dump's file attributes, and | 82 //! initial write. We don't store metadata in dump's file attributes, and |
Peter Kasting
2015/02/13 00:32:39
Nit: "and" -> "so we"? (Unsure)
scottmg
2015/02/13 06:34:03
Done.
| |
83 //! use the UUID to identify the dump on write completion. | 83 //! use the UUID to identify the dump on write completion. |
84 struct NewReportDisk : public CrashReportDatabase::NewReport { | 84 struct NewReportDisk : public CrashReportDatabase::NewReport { |
85 //! \brief The UUID for this crash report. | 85 //! \brief The UUID for this crash report. |
86 UUID uuid; | 86 UUID uuid; |
87 }; | 87 }; |
88 | 88 |
89 //! \brief Manages the metadata for the set of reports, handling serialization | 89 //! \brief Manages the metadata for the set of reports, handling serialization |
Peter Kasting
2015/02/13 00:32:40
Consider pulling this Metadata class and the assoc
scottmg
2015/02/13 06:34:04
I would prefer not to. I agree it would be a bit e
Peter Kasting
2015/02/13 22:30:33
In principle, why couldn't it be available for sta
scottmg
2015/02/13 23:37:16
It's not important to prevent it, it just wasn't i
| |
90 //! to disk, and queries. Instances of this class should be created by using | 90 //! to disk, and queries. Instances of this class should be created by using |
91 //! CrashReportDatabaseWin::AcquireMetadata(). | 91 //! CrashReportDatabaseWin::AcquireMetadata(). |
92 class Metadata { | 92 class Metadata { |
93 public: | 93 public: |
94 //! \brief Writes any changes if necessary, unlocks and closes the file | 94 //! \brief Writes any changes if necessary, unlocks and closes the file |
95 //! handle. | 95 //! handle. |
96 ~Metadata(); | 96 ~Metadata(); |
97 | 97 |
98 //! \brief Adds a new report to the set. | 98 //! \brief Adds a new report to the set. |
99 //! | 99 //! |
100 //! \param[in] new_report_disk The record to add. The #state field must be set | 100 //! \param[in] new_report_disk The record to add. The #state field must be set |
101 //! to kPending. | 101 //! to kPending. |
102 void AddNewRecord(const ReportDisk& new_report_disk); | 102 void AddNewRecord(const ReportDisk& new_report_disk); |
103 | 103 |
104 //! \brief Finds all reports in a given state. The \a reports vector is only | 104 //! \brief Finds all reports in a given state. The \a reports vector is only |
105 //! valid when CrashReportDatabase::kNoError is returned. | 105 //! valid when CrashReportDatabase::kNoError is returned. |
106 //! | 106 //! |
107 //! \param[in] desired_state The state to match. | 107 //! \param[in] desired_state The state to match. |
108 //! \param[out] reports Matching reports, must be empty on entry. | 108 //! \param[out] reports Matching reports, must be empty on entry. |
109 OperationStatus FindReports( | 109 OperationStatus FindReports( |
110 ReportState desired_state, | 110 ReportState desired_state, |
111 std::vector<const CrashReportDatabase::Report>* reports); | 111 std::vector<const CrashReportDatabase::Report>* reports); |
Peter Kasting
2015/02/13 00:32:38
This function can be const.
scottmg
2015/02/13 06:34:04
Done.
| |
112 | 112 |
113 //! \brief Finds the report matching the given UUID. | 113 //! \brief Finds the report matching the given UUID. |
114 //! | 114 //! |
115 //! The returned report is only valid if CrashReportDatabase::kNoError is | 115 //! The returned report is only valid if CrashReportDatabase::kNoError is |
116 //! returned. | 116 //! returned. |
117 //! | 117 //! |
118 //! \param[in] uuid The report identifier. | 118 //! \param[in] uuid The report identifier. |
119 //! \param[out] report_disk The found report, valid only if | 119 //! \param[out] report_disk The found report, valid only if |
120 //! CrashReportDatabase::kNoError is returned. Ownership is not | 120 //! CrashReportDatabase::kNoError is returned. Ownership is not |
121 //! transferred to the caller, and the report may not be modified. | 121 //! transferred to the caller, and the report may not be modified. |
122 OperationStatus FindSingleReport(const UUID& uuid, | 122 OperationStatus FindSingleReport(const UUID& uuid, |
123 const ReportDisk** report_disk); | 123 const ReportDisk** report_disk); |
Peter Kasting
2015/02/13 00:32:39
This function can be const (but see comment below)
scottmg
2015/02/13 06:34:02
Done.
| |
124 | 124 |
125 //! \brief Finds a single report matching the given UUID and in the desired | 125 //! \brief Finds a single report matching the given UUID and in the desired |
126 //! state and calls the client-supplied mutator to modify the report. | 126 //! state and calls the client-supplied mutator to modify the report. |
127 //! | 127 //! |
128 //! The mutator object must have an operator()(ReportDisk*) which makes the | 128 //! The mutator object must have an operator()(ReportDisk*) which makes the |
129 //! desired changes. | 129 //! desired changes. |
130 //! | 130 //! |
131 //! \return #kNoError on success. #kReportNotFound if there was no report with | 131 //! \return #kNoError on success. #kReportNotFound if there was no report with |
132 //! the specified UUID. #kBusyError if the report was not in the specified | 132 //! the specified UUID. #kBusyError if the report was not in the specified |
133 //! state. | 133 //! state. |
134 template <class T> | 134 template <class T> |
135 OperationStatus MutateSingleReport(const UUID& uuid, | 135 OperationStatus MutateSingleReport(const UUID& uuid, |
136 ReportState desired_state, | 136 ReportState desired_state, |
137 const T& mutator); | 137 const T& mutator); |
Peter Kasting
2015/02/13 00:32:39
Taking a mutator and passing in lambdas is very cl
scottmg
2015/02/13 06:34:04
Aha! That was how I initially wrote it. (Around ps
Peter Kasting
2015/02/13 22:30:32
Yeah, I think that's fine. It's OK with me for th
scottmg
2015/02/13 23:37:17
Acknowledged.
| |
138 | 138 |
139 private: | 139 private: |
140 static scoped_ptr<Metadata> Create(const base::FilePath& metadata_file, | 140 static scoped_ptr<Metadata> Create(const base::FilePath& metadata_file, |
Peter Kasting
2015/02/13 00:32:38
Static methods go below the constructor; see http:
scottmg
2015/02/13 06:34:01
Done.
| |
141 const base::FilePath& report_dir); | 141 const base::FilePath& report_dir); |
142 friend class CrashReportDatabaseWin; | 142 friend class CrashReportDatabaseWin; |
Peter Kasting
2015/02/13 00:32:40
Is there really much benefit in making the constru
scottmg
2015/02/13 06:34:04
Done.
| |
143 | 143 |
144 Metadata(FileHandle handle, const base::FilePath& report_dir); | 144 Metadata(FileHandle handle, const base::FilePath& report_dir); |
145 | 145 |
146 bool Rewind(); | 146 bool Rewind(); |
147 | 147 |
148 void Read(); | 148 void Read(); |
149 void Write(); | 149 void Write(); |
150 | 150 |
151 //! \brief Confirms that the corresponding report actually exists on disk | 151 //! \brief Confirms that the corresponding report actually exists on disk |
152 //! (that is, the dump file has not been removed), that the report is in | 152 //! (that is, the dump file has not been removed), that the report is in |
Peter Kasting
2015/02/13 00:32:39
Nit: that the -> and that the
scottmg
2015/02/13 06:34:02
Done.
| |
153 //! the given state. | 153 //! the given state. |
154 static OperationStatus VerifyReport(const ReportDisk& report_disk, | 154 static OperationStatus VerifyReport(const ReportDisk& report_disk, |
155 ReportState desired_state); | 155 ReportState desired_state); |
156 //! \brief Confirms that the corresponding report actually exists on disk | 156 //! \brief Confirms that the corresponding report actually exists on disk |
157 //! (that is, the dump file has not been removed). | 157 //! (that is, the dump file has not been removed). |
158 static OperationStatus VerifyReportAnyState(const ReportDisk& report_disk); | 158 static OperationStatus VerifyReportAnyState(const ReportDisk& report_disk); |
159 | 159 |
160 ScopedFileHandle handle_; | 160 ScopedFileHandle handle_; |
161 const base::FilePath report_dir_; | 161 const base::FilePath report_dir_; |
162 bool dirty_; //! \brief Is a Write() required on destruction? | 162 bool dirty_; //! \brief Is a Write() required on destruction? |
Peter Kasting
2015/02/13 00:32:40
Nit: Clearer that you're not uncertain yourself: "
scottmg
2015/02/13 06:34:03
Done.
| |
163 std::vector<ReportDisk> reports_; | 163 std::vector<ReportDisk> reports_; |
164 | 164 |
165 DISALLOW_COPY_AND_ASSIGN(Metadata); | 165 DISALLOW_COPY_AND_ASSIGN(Metadata); |
166 }; | 166 }; |
167 | 167 |
168 Metadata::Metadata(FileHandle handle, const base::FilePath& report_dir) | 168 Metadata::Metadata(FileHandle handle, const base::FilePath& report_dir) |
Peter Kasting
2015/02/13 00:32:39
Define functions (including class members) in the
scottmg
2015/02/13 06:34:05
Done.
| |
169 : handle_(handle), report_dir_(report_dir), dirty_(false), reports_() { | 169 : handle_(handle), report_dir_(report_dir), dirty_(false), reports_() { |
170 } | 170 } |
171 | 171 |
172 Metadata::~Metadata() { | 172 Metadata::~Metadata() { |
173 if (dirty_) | 173 if (dirty_) |
174 Write(); | 174 Write(); |
175 // Not actually async, UnlockFileEx requires the Offset fields. | 175 // Not actually async, UnlockFileEx requires the Offset fields. |
176 OVERLAPPED overlapped = {0}; | 176 OVERLAPPED overlapped = {0}; |
177 if (!UnlockFileEx(handle_.get(), 0, MAXDWORD, MAXDWORD, &overlapped)) | 177 if (!UnlockFileEx(handle_.get(), 0, MAXDWORD, MAXDWORD, &overlapped)) |
178 PLOG(ERROR) << "UnlockFileEx"; | 178 PLOG(ERROR) << "UnlockFileEx"; |
179 } | 179 } |
180 | 180 |
181 // The format of the metadata file is a MetadataFileHeader, followed by a | 181 // The format of the metadata file is a MetadataFileHeader, followed by a |
Peter Kasting
2015/02/13 00:32:40
This is a good comment but it seems like it should
scottmg
2015/02/13 06:34:05
The idea was that there's a small subsection here,
Peter Kasting
2015/02/13 22:30:32
Hmm. I think that connection is not terribly appa
scottmg
2015/02/13 23:37:16
Done.
| |
182 // number of fixed size records of MetadataFileReportRecord, followed by a | 182 // number of fixed size records of MetadataFileReportRecord, followed by a |
183 // string table in UTF8 format, where each string is \0 terminated. | 183 // string table in UTF8 format, where each string is \0 terminated. |
184 | 184 |
185 #pragma pack(push, 1) | 185 #pragma pack(push, 1) |
Peter Kasting
2015/02/13 00:32:39
I don't think this should actually do anything giv
scottmg
2015/02/13 06:34:03
Done.
| |
186 | 186 |
187 struct MetadataFileHeader { | 187 struct MetadataFileHeader { |
188 uint32_t magic; | 188 uint32_t magic; |
189 uint32_t version; | 189 uint32_t version; |
190 uint32_t num_records; | 190 uint32_t num_records; |
191 uint32_t padding; | 191 uint32_t padding; |
192 }; | 192 }; |
193 | 193 |
194 struct MetadataFileReportRecord { | 194 struct MetadataFileReportRecord { |
195 UUID uuid; // UUID is a 16 byte, standard layout structure. | 195 UUID uuid; // UUID is a 16 byte, standard layout structure. |
196 uint32_t file_path_index; // Index into string table. File name is relative | 196 uint32_t file_path_index; // Index into string table. File name is relative |
197 // to the reports directory when on disk. | 197 // to the reports directory when on disk. |
198 uint32_t id_index; // Index into string table. | 198 uint32_t id_index; // Index into string table. |
199 int64_t creation_time; // Holds a time_t. | 199 int64_t creation_time; // Holds a time_t. |
200 int64_t last_upload_attempt_time; // Holds a time_t. | 200 int64_t last_upload_attempt_time; // Holds a time_t. |
201 int32_t upload_attempts; | 201 int32_t upload_attempts; |
202 int32_t state; // A ReportState. | 202 int32_t state; // A ReportState. |
203 uint8_t uploaded; // Boolean, 0 or 1. | 203 uint8_t uploaded; // Boolean, 0 or 1. |
204 uint8_t padding[7]; | 204 uint8_t padding[7]; |
205 }; | 205 }; |
206 | 206 |
207 const uint32_t kMetadataFileHeaderMagic = 'CPAD'; | 207 const uint32_t kMetadataFileHeaderMagic = 'CPAD'; |
208 const uint32_t kMetadataFileVersion = 1; | 208 const uint32_t kMetadataFileVersion = 1; |
Peter Kasting
2015/02/13 00:32:39
Nit: Seems like these should perhaps be up with kM
scottmg
2015/02/13 06:34:04
I would prefer to keep them next to MetadataFileHe
| |
209 | 209 |
210 #pragma pack(pop) | 210 #pragma pack(pop) |
211 | 211 |
212 // Reads from the current file position to EOF and returns as uint8_t[]. | 212 // Reads from the current file position to EOF and returns as uint8_t[]. |
Peter Kasting
2015/02/13 00:32:39
Nit: Since this doesn't actually return a uint8_t[
scottmg
2015/02/13 06:34:02
Oops, done.
| |
213 std::string ReadRestOfFileAsString(FileHandle file) { | 213 std::string ReadRestOfFileAsString(FileHandle file) { |
214 FileOffset read_from = LoggingSeekFile(file, 0, SEEK_CUR); | 214 FileOffset read_from = LoggingSeekFile(file, 0, SEEK_CUR); |
215 FileOffset end = LoggingSeekFile(file, 0, SEEK_END); | 215 FileOffset end = LoggingSeekFile(file, 0, SEEK_END); |
216 FileOffset original = LoggingSeekFile(file, read_from, SEEK_SET); | 216 FileOffset original = LoggingSeekFile(file, read_from, SEEK_SET); |
217 if (read_from == -1 || end == -1 || original == -1) | 217 if (read_from == -1 || end == -1 || original == -1) |
218 return std::string(); | 218 return std::string(); |
219 DCHECK_EQ(read_from, original); | 219 DCHECK_EQ(read_from, original); |
220 DCHECK_GE(end, read_from); | 220 DCHECK_GE(end, read_from); |
Peter Kasting
2015/02/13 00:32:40
Nit: If there's 0 space left in the file, you can
scottmg
2015/02/13 06:34:02
Done.
| |
221 size_t data_length = static_cast<size_t>(end - read_from); | 221 size_t data_length = static_cast<size_t>(end - read_from); |
222 std::string buffer(data_length, '\0'); | 222 std::string buffer(data_length, '\0'); |
223 if (!LoggingReadFile(file, &buffer[0], data_length)) | 223 if (!LoggingReadFile(file, &buffer[0], data_length)) |
224 return std::string(); | 224 return std::string(); |
225 return buffer; | 225 return buffer; |
Peter Kasting
2015/02/13 00:32:38
Nit: Optional shorter method:
return LoggingRea
scottmg
2015/02/13 06:34:02
Done.
| |
226 } | 226 } |
227 | 227 |
228 uint32_t AddStringToTable(std::string* string_table, const std::string& str) { | 228 uint32_t AddStringToTable(std::string* string_table, const std::string& str) { |
Peter Kasting
2015/02/13 00:32:39
Please add a comment above this function indicatin
scottmg
2015/02/13 06:34:05
Done.
| |
229 uint32_t offset = base::checked_cast<uint32_t>(string_table->size()); | 229 uint32_t offset = base::checked_cast<uint32_t>(string_table->size()); |
230 *string_table += str; | 230 *string_table += str; |
231 *string_table += '\0'; | 231 *string_table += '\0'; |
232 return offset; | 232 return offset; |
233 } | 233 } |
234 | 234 |
235 uint32_t AddStringToTable(std::string* string_table, const std::wstring& str) { | 235 uint32_t AddStringToTable(std::string* string_table, const std::wstring& str) { |
Peter Kasting
2015/02/13 00:32:39
Nit: I'm not 100% certain but I believe we're now
scottmg
2015/02/13 06:34:02
Done.
| |
236 return AddStringToTable(string_table, base::UTF16ToUTF8(str)); | 236 return AddStringToTable(string_table, base::UTF16ToUTF8(str)); |
237 } | 237 } |
238 | 238 |
239 // static | 239 // static |
240 scoped_ptr<Metadata> Metadata::Create(const base::FilePath& metadata_file, | 240 scoped_ptr<Metadata> Metadata::Create(const base::FilePath& metadata_file, |
241 const base::FilePath& report_dir) { | 241 const base::FilePath& report_dir) { |
242 // It is important that dwShareMode be non-zero so that concurrent access to | 242 // It is important that dwShareMode be non-zero so that concurrent access to |
243 // this file results in a successful open. This allows us to get to LockFileEx | 243 // this file results in a successful open. This allows us to get to LockFileEx |
244 // which then blocks to guard access. | 244 // which then blocks to guard access. |
245 FileHandle handle = CreateFile(metadata_file.value().c_str(), | 245 FileHandle handle = CreateFile(metadata_file.value().c_str(), |
(...skipping 21 matching lines...) Expand all Loading... | |
267 // If Read() fails, for whatever reason (corruption, etc.) metadata will not | 267 // If Read() fails, for whatever reason (corruption, etc.) metadata will not |
268 // have been modified and will be in a clean empty state. We continue on and | 268 // have been modified and will be in a clean empty state. We continue on and |
269 // return an empty database to hopefully recover. This means that existing | 269 // return an empty database to hopefully recover. This means that existing |
270 // crash reports have been orphaned. | 270 // crash reports have been orphaned. |
271 metadata->Read(); | 271 metadata->Read(); |
272 return metadata; | 272 return metadata; |
273 } | 273 } |
274 | 274 |
275 bool Metadata::Rewind() { | 275 bool Metadata::Rewind() { |
276 FileOffset result = LoggingSeekFile(handle_.get(), 0, SEEK_SET); | 276 FileOffset result = LoggingSeekFile(handle_.get(), 0, SEEK_SET); |
277 DCHECK_EQ(result, 0); | 277 DCHECK_EQ(result, 0); |
Peter Kasting
2015/02/13 00:32:39
Nit: While not required, typical Chromium style fo
scottmg
2015/02/13 06:34:03
Done.
Mark Mentovai
2015/02/13 14:12:46
Peter Kasting wrote:
scottmg
2015/02/13 17:26:41
Rolled back.
Peter Kasting
2015/02/13 22:30:33
Good to know. That's what should be done here too
| |
278 return result == 0; | 278 return result == 0; |
279 } | 279 } |
280 | 280 |
281 void Metadata::Read() { | 281 void Metadata::Read() { |
282 FileOffset length = LoggingSeekFile(handle_.get(), 0, SEEK_END); | 282 FileOffset length = LoggingSeekFile(handle_.get(), 0, SEEK_END); |
283 if (length <= 0) // Failed, or empty: Abort. | 283 if (length <= 0) // Failed, or empty: Abort. |
284 return; | 284 return; |
285 if (!Rewind()) { | 285 if (!Rewind()) { |
286 LOG(ERROR) << "failed to rewind to read"; | 286 LOG(ERROR) << "failed to rewind to read"; |
287 return; | 287 return; |
288 } | 288 } |
289 | 289 |
290 MetadataFileHeader header; | 290 MetadataFileHeader header; |
291 if (!LoggingReadFile(handle_.get(), &header, sizeof(header))) { | 291 if (!LoggingReadFile(handle_.get(), &header, sizeof(header))) { |
292 LOG(ERROR) << "failed to read header"; | 292 LOG(ERROR) << "failed to read header"; |
293 return; | 293 return; |
294 } | 294 } |
295 if (header.magic != kMetadataFileHeaderMagic || | 295 if (header.magic != kMetadataFileHeaderMagic || |
296 header.version != kMetadataFileVersion) { | 296 header.version != kMetadataFileVersion) { |
297 LOG(ERROR) << "unexpected header"; | 297 LOG(ERROR) << "unexpected header"; |
298 return; | 298 return; |
299 } | 299 } |
300 | 300 |
301 auto records_size = base::CheckedNumeric<uint32_t>(header.num_records) * | 301 auto records_size = base::CheckedNumeric<uint32_t>(header.num_records) * |
Peter Kasting
2015/02/13 00:32:40
I'm not sure "auto" is best here, mainly because i
scottmg
2015/02/13 06:34:04
That was by request. :) But done.
| |
302 sizeof(MetadataFileReportRecord); | 302 sizeof(MetadataFileReportRecord); |
303 if (!records_size.IsValid()) { | 303 if (!records_size.IsValid()) { |
304 LOG(ERROR) << "record size out of range"; | 304 LOG(ERROR) << "record size out of range"; |
305 return; | 305 return; |
306 } | 306 } |
307 | 307 |
308 scoped_ptr<MetadataFileReportRecord[]> records( | 308 scoped_ptr<MetadataFileReportRecord[]> records( |
309 new MetadataFileReportRecord[header.num_records]); | 309 new MetadataFileReportRecord[header.num_records]); |
Peter Kasting
2015/02/13 00:32:38
Can this be done with a vector<MetadataFileReportR
scottmg
2015/02/13 06:34:03
Done.
| |
310 if (!LoggingReadFile( | 310 if (!LoggingReadFile( |
311 handle_.get(), records.get(), records_size.ValueOrDie())) { | 311 handle_.get(), records.get(), records_size.ValueOrDie())) { |
312 LOG(ERROR) << "failed to read records"; | 312 LOG(ERROR) << "failed to read records"; |
313 return; | 313 return; |
314 } | 314 } |
315 | 315 |
316 std::string string_table = ReadRestOfFileAsString(handle_.get()); | 316 std::string string_table = ReadRestOfFileAsString(handle_.get()); |
317 if (string_table.empty() || string_table.back() != '\0') { | 317 if (string_table.empty() || string_table.back() != '\0') { |
318 LOG(ERROR) << "bad string table"; | 318 LOG(ERROR) << "bad string table"; |
319 return; | 319 return; |
320 } | 320 } |
321 for (uint32_t i = 0; i < header.num_records; ++i) { | 321 for (uint32_t i = 0; i < header.num_records; ++i) { |
Peter Kasting
2015/02/13 00:32:39
Assuming you changed to a vector above, prefer to
scottmg
2015/02/13 06:34:03
Done.
| |
322 ReportDisk r; | 322 ReportDisk r; |
Peter Kasting
2015/02/13 00:32:40
Perhaps ReportDisk should define a constructor tha
scottmg
2015/02/13 06:34:03
It needs the string table and report_dir FilePath
Peter Kasting
2015/02/13 22:30:32
I'm OK with either. I don't feel any oddness abou
scottmg
2015/02/13 23:37:16
OK, switched to constructor.
| |
323 const MetadataFileReportRecord* record = &records[i]; | 323 const MetadataFileReportRecord* record = &records[i]; |
Peter Kasting
2015/02/13 00:32:40
Nit: Why not a const&?
scottmg
2015/02/13 06:34:04
Done (via const auto&).
| |
324 r.uuid = record->uuid; | 324 r.uuid = record->uuid; |
325 if (record->file_path_index >= string_table.size() || | 325 if (record->file_path_index >= string_table.size() || |
326 record->id_index >= string_table.size()) { | 326 record->id_index >= string_table.size()) { |
327 reports_.clear(); | 327 reports_.clear(); |
Peter Kasting
2015/02/13 00:32:40
Avoid this clear() call by using a temporary of th
scottmg
2015/02/13 06:34:04
Done.
| |
328 LOG(ERROR) << "invalid string table index"; | 328 LOG(ERROR) << "invalid string table index"; |
329 return; | 329 return; |
330 } | 330 } |
331 r.file_path = report_dir_.Append( | 331 r.file_path = report_dir_.Append( |
332 base::UTF8ToUTF16(&string_table[record->file_path_index])); | 332 base::UTF8ToUTF16(&string_table[record->file_path_index])); |
333 r.id = &string_table[record->id_index]; | 333 r.id = &string_table[record->id_index]; |
334 r.creation_time = record->creation_time; | 334 r.creation_time = record->creation_time; |
335 r.uploaded = record->uploaded; | 335 r.uploaded = record->uploaded; |
336 r.last_upload_attempt_time = record->last_upload_attempt_time; | 336 r.last_upload_attempt_time = record->last_upload_attempt_time; |
337 r.upload_attempts = record->upload_attempts; | 337 r.upload_attempts = record->upload_attempts; |
(...skipping 23 matching lines...) Expand all Loading... | |
361 header.version = kMetadataFileVersion; | 361 header.version = kMetadataFileVersion; |
362 header.num_records = base::checked_cast<uint32_t>(num_records); | 362 header.num_records = base::checked_cast<uint32_t>(num_records); |
363 if (!LoggingWriteFile(handle_.get(), &header, sizeof(header))) { | 363 if (!LoggingWriteFile(handle_.get(), &header, sizeof(header))) { |
364 LOG(ERROR) << "failed to write header"; | 364 LOG(ERROR) << "failed to write header"; |
365 return; | 365 return; |
366 } | 366 } |
367 | 367 |
368 // Build the records and string table we're going to write. | 368 // Build the records and string table we're going to write. |
369 std::string string_table; | 369 std::string string_table; |
370 scoped_ptr<MetadataFileReportRecord[]> records( | 370 scoped_ptr<MetadataFileReportRecord[]> records( |
371 new MetadataFileReportRecord[num_records]); | 371 new MetadataFileReportRecord[num_records]); |
Peter Kasting
2015/02/13 00:32:40
Again, if you can use a vector here, do so; this a
scottmg
2015/02/13 06:34:03
Done.
| |
372 memset(records.get(), 0, sizeof(MetadataFileReportRecord) * num_records); | 372 memset(records.get(), 0, sizeof(MetadataFileReportRecord) * num_records); |
373 for (size_t i = 0; i < num_records; ++i) { | 373 for (size_t i = 0; i < num_records; ++i) { |
374 const ReportDisk& report = reports_[i]; | 374 const ReportDisk& report = reports_[i]; |
375 MetadataFileReportRecord& record = records[i]; | 375 MetadataFileReportRecord& record = records[i]; |
Peter Kasting
2015/02/13 00:32:40
Nit: While not entirely banned, non-const refs are
scottmg
2015/02/13 06:34:02
Done.
| |
376 record.uuid = report.uuid; | 376 record.uuid = report.uuid; |
377 const base::FilePath& path = report.file_path; | 377 const base::FilePath& path = report.file_path; |
378 if (path.DirName() != report_dir_) { | 378 if (path.DirName() != report_dir_) { |
379 LOG(ERROR) << path.value().c_str() << " expected to start with " | 379 LOG(ERROR) << path.value().c_str() << " expected to start with " |
380 << report_dir_.value().c_str(); | 380 << report_dir_.value().c_str(); |
Peter Kasting
2015/02/13 00:32:39
Don't use c_str() with <<; it's unnecessary.
scottmg
2015/02/13 06:34:03
There's no operator<< for wstring/string16 in <ost
Peter Kasting
2015/02/13 22:30:33
Hmm. The overload for string16 (in string16.h) is
scottmg
2015/02/13 23:37:16
Yeah, I could take a look. In this case though, I
Peter Kasting
2015/02/13 23:45:10
Yeah, we should fix FilePath to use string16 in pl
| |
381 return; | 381 return; |
382 } | 382 } |
383 record.file_path_index = | 383 record.file_path_index = |
384 AddStringToTable(&string_table, path.BaseName().value().c_str()); | 384 AddStringToTable(&string_table, path.BaseName().value().c_str()); |
Peter Kasting
2015/02/13 00:32:39
Remove this c_str() call, which will simply add an
scottmg
2015/02/13 06:34:04
Done.
| |
385 record.id_index = AddStringToTable(&string_table, report.id); | 385 record.id_index = AddStringToTable(&string_table, report.id); |
386 record.creation_time = report.creation_time; | 386 record.creation_time = report.creation_time; |
387 record.uploaded = report.uploaded; | 387 record.uploaded = report.uploaded; |
388 record.last_upload_attempt_time = report.last_upload_attempt_time; | 388 record.last_upload_attempt_time = report.last_upload_attempt_time; |
389 record.upload_attempts = report.upload_attempts; | 389 record.upload_attempts = report.upload_attempts; |
390 record.state = static_cast<uint32_t>(report.state); | 390 record.state = static_cast<uint32_t>(report.state); |
391 } | 391 } |
392 | 392 |
393 if (!LoggingWriteFile(handle_.get(), | 393 if (!LoggingWriteFile(handle_.get(), |
394 records.get(), | 394 records.get(), |
395 num_records * sizeof(MetadataFileReportRecord))) { | 395 num_records * sizeof(MetadataFileReportRecord))) { |
Peter Kasting
2015/02/13 00:32:39
Nit: If you use a vector as suggested above, chang
scottmg
2015/02/13 06:34:03
Done.
| |
396 LOG(ERROR) << "failed to write records"; | 396 LOG(ERROR) << "failed to write records"; |
397 return; | 397 return; |
398 } | 398 } |
399 if (!LoggingWriteFile( | 399 if (!LoggingWriteFile( |
400 handle_.get(), string_table.c_str(), string_table.size())) { | 400 handle_.get(), string_table.c_str(), string_table.size())) { |
401 LOG(ERROR) << "failed to write string table"; | 401 LOG(ERROR) << "failed to write string table"; |
402 return; | 402 return; |
403 } | 403 } |
404 } | 404 } |
405 | 405 |
406 void Metadata::AddNewRecord(const ReportDisk& new_report_disk) { | 406 void Metadata::AddNewRecord(const ReportDisk& new_report_disk) { |
407 DCHECK(new_report_disk.state == ReportState::kPending); | 407 DCHECK(new_report_disk.state == ReportState::kPending); |
Peter Kasting
2015/02/13 00:32:40
Nit: DCHECK_EQ
scottmg
2015/02/13 06:34:05
That doesn't compile because ReportState is "enum
Peter Kasting
2015/02/13 22:30:32
Since you removed the explicit type on the enum cl
scottmg
2015/02/13 23:37:16
The primary benefit here is that the enumeration v
Peter Kasting
2015/02/13 23:45:10
But the enum is file-scoped anyway, so we're unlik
Mark Mentovai
2015/02/13 23:58:51
I do like the naming advantage of enum class, but
scottmg
2015/02/14 00:00:47
That's true. I think it's also preferable for them
| |
408 reports_.push_back(new_report_disk); | 408 reports_.push_back(new_report_disk); |
409 dirty_ = true; | 409 dirty_ = true; |
410 } | 410 } |
411 | 411 |
412 OperationStatus Metadata::FindReports( | 412 OperationStatus Metadata::FindReports( |
413 ReportState desired_state, | 413 ReportState desired_state, |
414 std::vector<const CrashReportDatabase::Report>* reports) { | 414 std::vector<const CrashReportDatabase::Report>* reports) { |
415 DCHECK(reports->empty()); | 415 DCHECK(reports->empty()); |
416 for (const auto& report : reports_) { | 416 for (const auto& report : reports_) { |
417 if (report.state == desired_state) { | 417 if (report.state == desired_state) { |
418 if (VerifyReport(report, desired_state) != CrashReportDatabase::kNoError) | 418 if (VerifyReport(report, desired_state) != CrashReportDatabase::kNoError) |
419 continue; | 419 continue; |
420 reports->push_back(report); | 420 reports->push_back(report); |
Peter Kasting
2015/02/13 00:32:40
Nit: Why not just:
if ((report.state == desir
scottmg
2015/02/13 06:34:03
Done.
| |
421 } | 421 } |
422 } | 422 } |
423 return CrashReportDatabase::kNoError; | 423 return CrashReportDatabase::kNoError; |
424 } | 424 } |
425 | 425 |
426 OperationStatus Metadata::FindSingleReport(const UUID& uuid, | 426 OperationStatus Metadata::FindSingleReport(const UUID& uuid, |
427 const ReportDisk** out_report) { | 427 const ReportDisk** out_report) { |
428 for (size_t i = 0; i < reports_.size(); ++i) { | 428 for (size_t i = 0; i < reports_.size(); ++i) { |
Peter Kasting
2015/02/13 00:32:40
Nit: Now that we have C++11 lambdas, use std::find
scottmg
2015/02/13 06:34:05
Done.
| |
429 if (reports_[i].uuid == uuid) { | 429 if (reports_[i].uuid == uuid) { |
430 OperationStatus os = VerifyReportAnyState(reports_[i]); | 430 OperationStatus os = VerifyReportAnyState(reports_[i]); |
431 if (os != CrashReportDatabase::kNoError) | 431 if (os != CrashReportDatabase::kNoError) |
432 return os; | 432 return os; |
433 *out_report = &reports_[i]; | 433 *out_report = &reports_[i]; |
434 return CrashReportDatabase::kNoError; | 434 return CrashReportDatabase::kNoError; |
Peter Kasting
2015/02/13 00:32:39
Nit: Simpler:
if (os == CrashReportDatabase
scottmg
2015/02/13 06:34:02
To me that feels more complicated. Previously it r
Peter Kasting
2015/02/13 22:30:32
That's a legit reading. I read the intent of the
scottmg
2015/02/13 23:37:16
Acknowledged.
| |
435 } | 435 } |
436 } | 436 } |
437 return CrashReportDatabase::kReportNotFound; | 437 return CrashReportDatabase::kReportNotFound; |
438 } | 438 } |
439 | 439 |
440 template <class T> | 440 template <class T> |
441 OperationStatus Metadata::MutateSingleReport( | 441 OperationStatus Metadata::MutateSingleReport( |
442 const UUID& uuid, | 442 const UUID& uuid, |
443 ReportState desired_state, | 443 ReportState desired_state, |
444 const T& mutator) { | 444 const T& mutator) { |
(...skipping 10 matching lines...) Expand all Loading... | |
455 return CrashReportDatabase::kReportNotFound; | 455 return CrashReportDatabase::kReportNotFound; |
456 } | 456 } |
457 | 457 |
458 // static | 458 // static |
459 OperationStatus Metadata::VerifyReportAnyState(const ReportDisk& report_disk) { | 459 OperationStatus Metadata::VerifyReportAnyState(const ReportDisk& report_disk) { |
460 DWORD fileattr = GetFileAttributes(report_disk.file_path.value().c_str()); | 460 DWORD fileattr = GetFileAttributes(report_disk.file_path.value().c_str()); |
461 if (fileattr == INVALID_FILE_ATTRIBUTES) | 461 if (fileattr == INVALID_FILE_ATTRIBUTES) |
462 return CrashReportDatabase::kReportNotFound; | 462 return CrashReportDatabase::kReportNotFound; |
463 if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) | 463 if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) |
464 return CrashReportDatabase::kFileSystemError; | 464 return CrashReportDatabase::kFileSystemError; |
465 return CrashReportDatabase::kNoError; | 465 return CrashReportDatabase::kNoError; |
Peter Kasting
2015/02/13 00:32:40
Nit: Shorter:
return (fileattr & FILE_ATTRIBUTE
scottmg
2015/02/13 06:34:02
Done.
| |
466 } | 466 } |
467 | 467 |
468 // static | 468 // static |
469 OperationStatus Metadata::VerifyReport(const ReportDisk& report_disk, | 469 OperationStatus Metadata::VerifyReport(const ReportDisk& report_disk, |
470 ReportState desired_state) { | 470 ReportState desired_state) { |
471 if (report_disk.state != desired_state) | 471 if (report_disk.state != desired_state) |
472 return CrashReportDatabase::kBusyError; | 472 return CrashReportDatabase::kBusyError; |
473 return VerifyReportAnyState(report_disk); | 473 return VerifyReportAnyState(report_disk); |
Peter Kasting
2015/02/13 00:32:40
Nit: Shorter:
return (report_disk.state == desi
scottmg
2015/02/13 06:34:04
Done.
| |
474 } | 474 } |
475 | 475 |
476 class CrashReportDatabaseWin : public CrashReportDatabase { | 476 class CrashReportDatabaseWin : public CrashReportDatabase { |
477 public: | 477 public: |
478 explicit CrashReportDatabaseWin(const base::FilePath& path); | 478 explicit CrashReportDatabaseWin(const base::FilePath& path); |
479 ~CrashReportDatabaseWin() override; | 479 ~CrashReportDatabaseWin() override; |
480 | 480 |
481 bool Initialize(); | 481 bool Initialize(); |
482 | 482 |
483 // CrashReportDatabase: | 483 // CrashReportDatabase: |
484 OperationStatus PrepareNewCrashReport(NewReport** report) override; | 484 OperationStatus PrepareNewCrashReport(NewReport** report) override; |
Peter Kasting
2015/02/13 00:32:40
This is out-of-scope for the current CL, but consi
scottmg
2015/02/13 06:34:05
That seems like a good idea.
| |
485 OperationStatus FinishedWritingCrashReport(NewReport* report, | 485 OperationStatus FinishedWritingCrashReport(NewReport* report, |
486 UUID* uuid) override; | 486 UUID* uuid) override; |
487 OperationStatus ErrorWritingCrashReport(NewReport* report) override; | 487 OperationStatus ErrorWritingCrashReport(NewReport* report) override; |
488 OperationStatus LookUpCrashReport(const UUID& uuid, Report* report) override; | 488 OperationStatus LookUpCrashReport(const UUID& uuid, Report* report) override; |
489 OperationStatus GetPendingReports( | 489 OperationStatus GetPendingReports( |
490 std::vector<const Report>* reports) override; | 490 std::vector<const Report>* reports) override; |
491 OperationStatus GetCompletedReports( | 491 OperationStatus GetCompletedReports( |
492 std::vector<const Report>* reports) override; | 492 std::vector<const Report>* reports) override; |
493 OperationStatus GetReportForUploading(const UUID& uuid, | 493 OperationStatus GetReportForUploading(const UUID& uuid, |
494 const Report** report) override; | 494 const Report** report) override; |
(...skipping 16 matching lines...) Expand all Loading... | |
511 | 511 |
512 CrashReportDatabaseWin::~CrashReportDatabaseWin() { | 512 CrashReportDatabaseWin::~CrashReportDatabaseWin() { |
513 } | 513 } |
514 | 514 |
515 bool CrashReportDatabaseWin::Initialize() { | 515 bool CrashReportDatabaseWin::Initialize() { |
516 // Check if the database already exists. | 516 // Check if the database already exists. |
517 if (!CreateOrEnsureDirectoryExists(base_dir_)) | 517 if (!CreateOrEnsureDirectoryExists(base_dir_)) |
518 return false; | 518 return false; |
519 | 519 |
520 // Create our reports subdirectory. | 520 // Create our reports subdirectory. |
521 if (!CreateOrEnsureDirectoryExists(base_dir_.Append(kReportsDirectory))) | 521 if (!CreateOrEnsureDirectoryExists(base_dir_.Append(kReportsDirectory))) |
Peter Kasting
2015/02/13 00:32:38
Nit: These conditionals (and their comments) could
scottmg
2015/02/13 06:34:05
Done.
| |
522 return false; | 522 return false; |
523 | 523 |
524 // TODO(scottmg): When are completed reports pruned from disk? Delete here or | 524 // TODO(scottmg): When are completed reports pruned from disk? Delete here or |
525 // maybe on AcquireMetadata(). | 525 // maybe on AcquireMetadata(). |
526 | 526 |
527 return true; | 527 return true; |
528 } | 528 } |
529 | 529 |
530 OperationStatus CrashReportDatabaseWin::PrepareNewCrashReport( | 530 OperationStatus CrashReportDatabaseWin::PrepareNewCrashReport( |
531 NewReport** out_report) { | 531 NewReport** out_report) { |
Peter Kasting
2015/02/13 00:32:40
Argument names should match between function decla
scottmg
2015/02/13 06:34:05
Done.
| |
532 scoped_ptr<NewReportDisk> report(new NewReportDisk()); | 532 scoped_ptr<NewReportDisk> report(new NewReportDisk()); |
Peter Kasting
2015/02/13 00:32:39
Declare this below, as close to the first use as p
scottmg
2015/02/13 06:34:05
Done.
| |
533 | 533 |
534 ::UUID system_uuid; | 534 ::UUID system_uuid; |
Peter Kasting
2015/02/13 00:32:39
Oh man, are ::UUID and UUID different types? How
scottmg
2015/02/13 06:34:05
Yeah, partially due to initial implementation bein
| |
535 if (UuidCreate(&system_uuid) != RPC_S_OK) { | 535 if (UuidCreate(&system_uuid) != RPC_S_OK) { |
Peter Kasting
2015/02/13 00:32:40
Be consistent about {} on one-line conditional bod
scottmg
2015/02/13 06:34:04
Done.
| |
536 return kFileSystemError; | 536 return kFileSystemError; |
537 } | 537 } |
538 static_assert(sizeof(system_uuid) == 16, "unexpected system uuid size"); | 538 static_assert(sizeof(system_uuid) == 16, "unexpected system uuid size"); |
539 static_assert(offsetof(::UUID, Data1) == 0, "unexpected uuid layout"); | 539 static_assert(offsetof(::UUID, Data1) == 0, "unexpected uuid layout"); |
540 UUID uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); | 540 UUID uuid(reinterpret_cast<const uint8_t*>(&system_uuid.Data1)); |
541 | 541 |
542 report->uuid = uuid; | 542 report->uuid = uuid; |
543 report->path = | 543 report->path = |
544 base_dir_.Append(kReportsDirectory) | 544 base_dir_.Append(kReportsDirectory) |
545 .Append(uuid.ToWideString() + L"." + kCrashReportFileExtension); | 545 .Append(uuid.ToWideString() + L"." + kCrashReportFileExtension); |
(...skipping 10 matching lines...) Expand all Loading... | |
556 NewReport* report, | 556 NewReport* report, |
557 UUID* uuid) { | 557 UUID* uuid) { |
558 // Take ownership of the report, and cast to our private version with UUID. | 558 // Take ownership of the report, and cast to our private version with UUID. |
559 scoped_ptr<NewReportDisk> scoped_report(static_cast<NewReportDisk*>(report)); | 559 scoped_ptr<NewReportDisk> scoped_report(static_cast<NewReportDisk*>(report)); |
560 // Take ownership of the file handle. | 560 // Take ownership of the file handle. |
561 ScopedFileHandle handle(report->handle); | 561 ScopedFileHandle handle(report->handle); |
562 | 562 |
563 scoped_ptr<Metadata> metadata(AcquireMetadata()); | 563 scoped_ptr<Metadata> metadata(AcquireMetadata()); |
564 if (!metadata) | 564 if (!metadata) |
565 return kDatabaseError; | 565 return kDatabaseError; |
566 ReportDisk report_disk; | 566 ReportDisk report_disk; |
Peter Kasting
2015/02/13 00:32:38
Nit: Consider adding a constructor for this that w
scottmg
2015/02/13 06:34:03
I did this as a ReportDisk constructor, but then u
Peter Kasting
2015/02/13 22:30:32
What about just something like:
ReportDisk::Rep
Peter Kasting
2015/02/13 23:45:10
(I think this is the only comment you didn't reply
scottmg
2015/02/14 00:00:47
Sorry, missed clicking done. Done as suggested.
| |
567 report_disk.uuid = scoped_report->uuid; | 567 report_disk.uuid = scoped_report->uuid; |
568 report_disk.file_path = scoped_report->path; | 568 report_disk.file_path = scoped_report->path; |
569 report_disk.creation_time = time(nullptr); | 569 report_disk.creation_time = time(nullptr); |
570 report_disk.state = ReportState::kPending; | 570 report_disk.state = ReportState::kPending; |
571 metadata->AddNewRecord(report_disk); | 571 metadata->AddNewRecord(report_disk); |
572 *uuid = report_disk.uuid; | 572 *uuid = report_disk.uuid; |
Peter Kasting
2015/02/13 00:32:38
Nit: If you use new_report->uuid here, and follow
scottmg
2015/02/13 06:34:02
Acknowledged.
| |
573 return kNoError; | 573 return kNoError; |
574 } | 574 } |
575 | 575 |
576 OperationStatus CrashReportDatabaseWin::ErrorWritingCrashReport( | 576 OperationStatus CrashReportDatabaseWin::ErrorWritingCrashReport( |
577 NewReport* report) { | 577 NewReport* report) { |
578 // Take ownership of the report, and cast to our private version with UUID. | 578 // Take ownership of the report, and cast to our private version with UUID. |
579 scoped_ptr<NewReportDisk> scoped_report(static_cast<NewReportDisk*>(report)); | 579 scoped_ptr<NewReportDisk> scoped_report(static_cast<NewReportDisk*>(report)); |
580 | 580 |
581 // Close the outstanding handle. | 581 // Close the outstanding handle. |
582 LoggingCloseFile(report->handle); | 582 LoggingCloseFile(report->handle); |
583 | 583 |
584 // We failed to write, so remove the dump file. There's no entry in the | 584 // We failed to write, so remove the dump file. There's no entry in the |
585 // metadata table yet. | 585 // metadata table yet. |
586 if (!DeleteFile(scoped_report->path.value().c_str())) { | 586 if (!DeleteFile(scoped_report->path.value().c_str())) { |
587 PLOG(ERROR) << "DeleteFile " << scoped_report->path.value().c_str(); | 587 PLOG(ERROR) << "DeleteFile " << scoped_report->path.value().c_str(); |
Peter Kasting
2015/02/13 00:32:40
Don't use c_str() here.
scottmg
2015/02/13 06:34:02
See above.
| |
588 return CrashReportDatabase::kFileSystemError; | 588 return CrashReportDatabase::kFileSystemError; |
589 } | 589 } |
590 | 590 |
591 return kNoError; | 591 return kNoError; |
592 } | 592 } |
593 | 593 |
594 OperationStatus CrashReportDatabaseWin::LookUpCrashReport(const UUID& uuid, | 594 OperationStatus CrashReportDatabaseWin::LookUpCrashReport(const UUID& uuid, |
595 Report* report) { | 595 Report* report) { |
596 scoped_ptr<Metadata> metadata(AcquireMetadata()); | 596 scoped_ptr<Metadata> metadata(AcquireMetadata()); |
597 if (!metadata) | 597 if (!metadata) |
598 return kDatabaseError; | 598 return kDatabaseError; |
599 // Find and return a copy of the matching report. | 599 // Find and return a copy of the matching report. |
600 const ReportDisk* report_disk; | 600 const ReportDisk* report_disk; |
601 OperationStatus os = metadata->FindSingleReport(uuid, &report_disk); | 601 OperationStatus os = metadata->FindSingleReport(uuid, &report_disk); |
602 if (os != kNoError) | 602 if (os != kNoError) |
603 return os; | 603 return os; |
604 *report = *report_disk; | 604 *report = *report_disk; |
605 return kNoError; | 605 return kNoError; |
Peter Kasting
2015/02/13 00:32:38
Nit: Simpler:
if (os == kNoError)
*report =
scottmg
2015/02/13 06:34:04
Done.
| |
606 } | 606 } |
607 | 607 |
608 OperationStatus CrashReportDatabaseWin::GetPendingReports( | 608 OperationStatus CrashReportDatabaseWin::GetPendingReports( |
609 std::vector<const Report>* reports) { | 609 std::vector<const Report>* reports) { |
610 scoped_ptr<Metadata> metadata(AcquireMetadata()); | 610 scoped_ptr<Metadata> metadata(AcquireMetadata()); |
611 if (!metadata) | 611 if (!metadata) |
612 return kDatabaseError; | 612 return kDatabaseError; |
613 return metadata->FindReports(ReportState::kPending, reports); | 613 return metadata->FindReports(ReportState::kPending, reports); |
Peter Kasting
2015/02/13 00:32:38
Nit: Shorter:
return metadata ?
metadata-
scottmg
2015/02/13 06:34:02
Done.
| |
614 } | 614 } |
615 | 615 |
616 OperationStatus CrashReportDatabaseWin::GetCompletedReports( | 616 OperationStatus CrashReportDatabaseWin::GetCompletedReports( |
617 std::vector<const Report>* reports) { | 617 std::vector<const Report>* reports) { |
618 scoped_ptr<Metadata> metadata(AcquireMetadata()); | 618 scoped_ptr<Metadata> metadata(AcquireMetadata()); |
619 if (!metadata) | 619 if (!metadata) |
620 return kDatabaseError; | 620 return kDatabaseError; |
621 return metadata->FindReports(ReportState::kCompleted, reports); | 621 return metadata->FindReports(ReportState::kCompleted, reports); |
Peter Kasting
2015/02/13 00:32:38
Nit: Shorter:
return metadata ?
metadata-
scottmg
2015/02/13 06:34:04
Done.
| |
622 } | 622 } |
623 | 623 |
624 OperationStatus CrashReportDatabaseWin::GetReportForUploading( | 624 OperationStatus CrashReportDatabaseWin::GetReportForUploading( |
625 const UUID& uuid, | 625 const UUID& uuid, |
626 const Report** report) { | 626 const Report** report) { |
627 scoped_ptr<Metadata> metadata(AcquireMetadata()); | 627 scoped_ptr<Metadata> metadata(AcquireMetadata()); |
628 if (!metadata) | 628 if (!metadata) |
629 return kDatabaseError; | 629 return kDatabaseError; |
630 // TODO(scottmg): After returning this report to the client, there is no way | 630 // TODO(scottmg): After returning this report to the client, there is no way |
631 // to reap this report if the uploader fails to call RecordUploadAttempt() or | 631 // to reap this report if the uploader fails to call RecordUploadAttempt() or |
(...skipping 19 matching lines...) Expand all Loading... | |
651 bool successful, | 651 bool successful, |
652 const std::string& id) { | 652 const std::string& id) { |
653 // Take ownership, allocated in GetReportForUploading. | 653 // Take ownership, allocated in GetReportForUploading. |
654 scoped_ptr<const Report> upload_report(report); | 654 scoped_ptr<const Report> upload_report(report); |
655 scoped_ptr<Metadata> metadata(AcquireMetadata()); | 655 scoped_ptr<Metadata> metadata(AcquireMetadata()); |
656 if (!metadata) | 656 if (!metadata) |
657 return kDatabaseError; | 657 return kDatabaseError; |
658 return metadata->MutateSingleReport( | 658 return metadata->MutateSingleReport( |
659 report->uuid, | 659 report->uuid, |
660 ReportState::kUploading, | 660 ReportState::kUploading, |
661 [successful, id](ReportDisk* report_disk) { | 661 [successful, id](ReportDisk* report_disk) { |
Peter Kasting
2015/02/13 00:32:39
This lambda is skirting the border of "too long" -
scottmg
2015/02/13 06:34:03
Done.
| |
662 report_disk->uploaded = successful; | 662 report_disk->uploaded = successful; |
663 report_disk->id = id; | 663 report_disk->id = id; |
664 report_disk->last_upload_attempt_time = time(nullptr); | 664 report_disk->last_upload_attempt_time = time(nullptr); |
665 report_disk->upload_attempts++; | 665 report_disk->upload_attempts++; |
666 report_disk->state = | 666 report_disk->state = |
667 successful ? ReportState::kCompleted : ReportState::kPending; | 667 successful ? ReportState::kCompleted : ReportState::kPending; |
668 }); | 668 }); |
669 } | 669 } |
670 | 670 |
671 OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) { | 671 OperationStatus CrashReportDatabaseWin::SkipReportUpload(const UUID& uuid) { |
(...skipping 12 matching lines...) Expand all Loading... | |
684 } | 684 } |
685 | 685 |
686 } // namespace | 686 } // namespace |
687 | 687 |
688 // static | 688 // static |
689 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( | 689 scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( |
690 const base::FilePath& path) { | 690 const base::FilePath& path) { |
691 scoped_ptr<CrashReportDatabaseWin> database_win( | 691 scoped_ptr<CrashReportDatabaseWin> database_win( |
692 new CrashReportDatabaseWin(path.Append(kDatabaseDirectoryName))); | 692 new CrashReportDatabaseWin(path.Append(kDatabaseDirectoryName))); |
693 if (!database_win->Initialize()) | 693 if (!database_win->Initialize()) |
694 database_win.reset(); | 694 database_win.reset(); |
Peter Kasting
2015/02/13 00:32:39
Nit: If you do this:
if (!database_win->Initial
scottmg
2015/02/13 06:34:05
Done.
| |
695 | 695 |
696 return scoped_ptr<CrashReportDatabase>(database_win.release()); | 696 return scoped_ptr<CrashReportDatabase>(database_win.release()); |
Peter Kasting
2015/02/13 00:32:40
Simply:
return database_win.Pass();
Pass() can
scottmg
2015/02/13 06:34:02
Done.
| |
697 } | 697 } |
698 | 698 |
699 } // namespace crashpad | 699 } // namespace crashpad |
700 // EOF comment added for readability review. | |
OLD | NEW |