OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (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 | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 #ifndef CRASHPAD_CLIENT_CRASH_REPORT_DATABASE_H_ | |
16 #define CRASHPAD_CLIENT_CRASH_REPORT_DATABASE_H_ | |
17 | |
18 #include <time.h> | |
19 | |
20 #include <string> | |
21 #include <vector> | |
22 | |
23 #include "base/basictypes.h" | |
24 #include "base/files/file_path.h" | |
25 #include "base/memory/scoped_ptr.h" | |
26 #include "util/file/file_io.h" | |
27 #include "util/misc/uuid.h" | |
28 | |
29 namespace crashpad { | |
30 | |
31 //! \brief An interface for managing a collection of crash report files and | |
32 //! metadata associated with the crash reports. | |
33 //! | |
34 //! All Report objects that are returned by this class are logically const. | |
35 //! They are snapshots of the database at the time the query was run, and the | |
36 //! data returned is liable to change after the query is executed. | |
37 class CrashReportDatabase { | |
38 public: | |
39 //! \brief A crash report record. | |
40 //! | |
41 //! This represents the metadata for a crash report, as well as the location | |
42 //! of the report itself. A CrashReportDatabase maintains at least this | |
43 //! information. | |
44 struct Report { | |
45 Report(); | |
46 | |
47 //! A unique identifier by which this report will always be known to the | |
48 //! database. | |
49 UUID uuid; | |
50 | |
51 //! The current location of the crash report on the client’s filesystem. | |
52 //! The location of a crash report may change over time, so the UUID should | |
53 //! be used as the canonical identifier. | |
54 base::FilePath file_path; | |
55 | |
56 //! An identifier issued to this crash report by a collection server. | |
57 std::string id; | |
58 | |
59 //! The time at which the report was generated. | |
60 time_t creation_time; | |
61 | |
62 //! Whether this crash report was successfully uploaded to a collection | |
63 //! server. | |
64 bool uploaded; | |
65 | |
66 //! The last timestamp at which an attempt was made to submit this crash | |
67 //! report to a collection server. If this is zero, then the report has | |
68 //! never been uploaded. If #uploaded is true, then this timestamp is the | |
69 //! time at which the report was uploaded, and no other attempts to upload | |
70 //! this report will be made. | |
71 time_t last_upload_attempt_time; | |
72 | |
73 //! The number of times an attempt was made to submit this report to | |
74 //! a collection server. If this is more than zero, then | |
75 //! #last_upload_attempt_time will be set to the timestamp of the most | |
76 //! recent attempt. | |
77 int upload_attempts; | |
78 }; | |
79 | |
80 //! \brief The result code for operations performed on a database. | |
81 enum OperationStatus { | |
82 //! \brief No error occurred. | |
83 kNoError = 0, | |
84 | |
85 //! \brief The report that was requested could not be located. | |
86 kReportNotFound, | |
87 | |
88 //! \brief An error occured while performing a file operation on a crash | |
89 //! report. | |
90 //! | |
91 //! A database is responsible for managing both the metadata about a report | |
92 //! and the actual crash report itself. This error is returned when an | |
93 //! error occurred when managing the report file. Additional information | |
94 //! will be logged. | |
95 kFileSystemError, | |
96 | |
97 //! \brief An error occured while recording metadata for a crash report. | |
98 //! | |
99 //! A database is responsible for managing both the metadata about a report | |
100 //! and the actual crash report itself. This error is returned when an | |
101 //! error occurred when managing the metadata about a crash report. | |
102 //! Additional information will be logged. | |
103 kDatabaseError, | |
104 | |
105 //! \brief The operation could not be completed because a concurrent | |
Mark Mentovai
2015/01/21 18:01:35
A concurrent what?
Robert Sesek
2015/01/26 20:16:14
Done.
| |
106 //! affecting the report is occurring. | |
107 kBusyError, | |
108 }; | |
109 | |
110 virtual ~CrashReportDatabase() {} | |
111 | |
112 //! \brief Initializes a database of crash reports. | |
113 //! | |
114 //! \param[in] path A path to a writable directory, where the database can | |
115 //! be created or opened. | |
116 //! | |
117 //! \return A database object on success, `nullptr` on failure with an error | |
118 //! logged. | |
119 static scoped_ptr<CrashReportDatabase> Initialize(const base::FilePath& path); | |
120 | |
121 //! \brief Creates a record of a new crash report. | |
122 //! | |
123 //! Callers can then write the crash report using the file handle provided. | |
124 //! The caller does not own this handle, and it must be explicitly closed with | |
125 //! FinishedWritingCrashReport(). | |
126 //! | |
127 //! \param[out] handle A file handle to which the crash report data should be | |
128 //! written. Only valid if this returns #kNoError. The caller should not | |
Mark Mentovai
2015/01/21 18:01:35
should→must.
Robert Sesek
2015/01/26 20:16:14
Done.
| |
129 //! close this handle. | |
130 //! | |
131 //! \return The operation status code. | |
132 virtual OperationStatus PrepareNewCrashReport(FileHandle* handle) = 0; | |
133 | |
134 //! \brief Informs the database that a crash report has been written. | |
135 //! | |
136 //! After calling this method, the database is permitted to move and rename | |
137 //! the file at Record::file_path. | |
Mark Mentovai
2015/01/21 18:01:35
I don’t know Record::, only Report::. Lines 177 an
Robert Sesek
2015/01/26 20:16:14
Done.
| |
138 //! | |
139 //! \param[in] handle A handle obtained with PrepareNewCrashReport(). The | |
140 //! handle will be invalidated as part of this call. | |
141 //! \param[out] uuid The UUID of this crash report. | |
142 //! | |
143 //! \return The operation status code. | |
144 virtual OperationStatus FinishedWritingCrashReport(FileHandle handle, | |
145 UUID* uuid) = 0; | |
146 | |
147 //! \brief Returns the crash report record for the unique identifier. | |
148 //! | |
149 //! \param[in] uuid The crash report record unique identifier. | |
150 //! \param[out] report A crash report record. Only valid if this returns | |
151 //! #kNoError. | |
152 //! | |
153 //! \return The operation status code. | |
154 virtual OperationStatus LookUpCrashReport(const UUID& uuid, | |
155 Report* report) = 0; | |
156 | |
157 //! \brief Returns a list of crash report records that have not been uploaded. | |
158 //! | |
159 //! \param[out] reports A list of crash report record objects. This must be | |
160 //! empty on entry. Only valid if this returns #kNoError. | |
161 //! | |
162 //! \return The operation status code. | |
163 virtual OperationStatus GetNotUploadedReports( | |
Mark Mentovai
2015/01/21 18:01:35
The only real major problem I see with this now is
Robert Sesek
2015/01/26 20:16:14
Done. I've added a new SkipReportUpload() method a
| |
164 std::vector<const Report>* reports) = 0; | |
165 | |
166 //! \brief Returns a list of crash report records that have been uploaded. | |
167 //! | |
168 //! \param[out] reports A list of crash report record objects. This must be | |
169 //! empty on entry. Only valid if this returns #kNoError. | |
170 //! | |
171 //! \return The operation status code. | |
172 virtual OperationStatus GetUploadedReports( | |
173 std::vector<const Report>* reports) = 0; | |
174 | |
175 //! \brief Obtains a report object for uploading to a collection server. | |
176 //! | |
177 //! The file at Record::file_path should be uploaded by the caller, and then | |
178 //! the returned Record object should be disposed of via a call to | |
Mark Mentovai
2015/01/21 18:01:35
Strengthen this to “must.”
Robert Sesek
2015/01/26 20:16:14
Done.
| |
179 //! RecordUploadAttempt(). | |
180 //! | |
181 //! A subsequent call to this method with the same \a uuid is illegal if | |
Mark Mentovai
2015/01/21 18:01:35
And since it’s a “must”, the “if x() has not been
Robert Sesek
2015/01/26 20:16:14
Done.
| |
182 //! RecordUploadAttempt() has not been called first. | |
183 //! | |
184 //! \param[in] uuid The unique identifier for the crash report record. | |
185 //! \param[out] report A crash report record for the report to be uploaded. | |
186 //! The caller does not own this object. Only valid if this returns | |
187 //! #kNoError. | |
188 //! | |
189 //! \return The operation status code. | |
190 virtual OperationStatus GetReportForUploading(const UUID& uuid, | |
191 const Report** report) = 0; | |
192 | |
193 //! \brief Adjusts a crash report record’s metadata to account for an upload | |
194 //! attempt. | |
195 //! | |
196 //! After calling this method, the database is permitted to move and rename | |
197 //! the file at Record::file_path. | |
198 //! | |
199 //! \param[in] report The report object obtained from | |
200 //! GetReportForUploading(). This object is invalidated after this call. | |
201 //! \param[in] successful Whether the upload attempt was successful. | |
202 //! \param[in] id The identifier assigned to this crash report by the | |
203 //! collection server. Must be empty if \a successful is `false`; may be | |
204 //! empty if it is `true`. | |
205 //! | |
206 //! \return The operation status code. | |
207 virtual OperationStatus RecordUploadAttempt(const Report* report, | |
208 bool successful, | |
209 const std::string& id) = 0; | |
210 | |
211 protected: | |
212 CrashReportDatabase() {} | |
213 | |
214 private: | |
215 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabase); | |
216 }; | |
217 | |
218 } // namespace crashpad | |
219 | |
220 #endif // CRASHPAD_CLIENT_CRASH_REPORT_DATABASE_H_ | |
OLD | NEW |