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

Side by Side Diff: client/crash_report_database.h

Issue 842513002: Create CrashReportDatabase interface, a test, and a Mac implementation. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address comments Created 5 years, 10 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
« no previous file with comments | « client/client.gyp ('k') | client/crash_report_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 //!
38 //! The lifecycle of a crash report has three stages:
39 //!
40 //! 1. New: A crash report is created with PrepareNewCrashReport(), the
41 //! the client then writes the report, and then calls
42 //! FinishedWritingCrashReport() to make the report Pending.
43 //! 2. Pending: The report has been written but has not been locally
44 //! processed.
45 //! 3. Completed: The report has been locally processed, either by uploading
46 //! it to a collection server and calling RecordUploadAttempt(), or by
47 //! calling SkipReportUpload().
48 class CrashReportDatabase {
49 public:
50 //! \brief A crash report record.
51 //!
52 //! This represents the metadata for a crash report, as well as the location
53 //! of the report itself. A CrashReportDatabase maintains at least this
54 //! information.
55 struct Report {
56 Report();
57
58 //! A unique identifier by which this report will always be known to the
59 //! database.
60 UUID uuid;
61
62 //! The current location of the crash report on the client’s filesystem.
63 //! The location of a crash report may change over time, so the UUID should
64 //! be used as the canonical identifier.
65 base::FilePath file_path;
66
67 //! An identifier issued to this crash report by a collection server.
68 std::string id;
69
70 //! The time at which the report was generated.
71 time_t creation_time;
72
73 //! Whether this crash report was successfully uploaded to a collection
74 //! server.
75 bool uploaded;
76
77 //! The last timestamp at which an attempt was made to submit this crash
78 //! report to a collection server. If this is zero, then the report has
79 //! never been uploaded. If #uploaded is true, then this timestamp is the
80 //! time at which the report was uploaded, and no other attempts to upload
81 //! this report will be made.
82 time_t last_upload_attempt_time;
83
84 //! The number of times an attempt was made to submit this report to
85 //! a collection server. If this is more than zero, then
86 //! #last_upload_attempt_time will be set to the timestamp of the most
87 //! recent attempt.
88 int upload_attempts;
89 };
90
91 //! \brief A crash report that is in the process of being written.
92 //!
93 //! An instance of this struct should be created via PrepareNewCrashReport()
94 //! and destroyed with FinishedWritingCrashReport().
95 struct NewReport {
96 //! The file handle to which the report should be written.
97 FileHandle handle;
98
99 //! The path to the crash report being written.
100 base::FilePath path;
101 };
102
103 //! \brief The result code for operations performed on a database.
104 enum OperationStatus {
105 //! \brief No error occurred.
106 kNoError = 0,
107
108 //! \brief The report that was requested could not be located.
109 kReportNotFound,
110
111 //! \brief An error occured while performing a file operation on a crash
112 //! report.
113 //!
114 //! A database is responsible for managing both the metadata about a report
115 //! and the actual crash report itself. This error is returned when an
116 //! error occurred when managing the report file. Additional information
117 //! will be logged.
118 kFileSystemError,
119
120 //! \brief An error occured while recording metadata for a crash report.
121 //!
122 //! A database is responsible for managing both the metadata about a report
123 //! and the actual crash report itself. This error is returned when an
124 //! error occurred when managing the metadata about a crash report.
125 //! Additional information will be logged.
126 kDatabaseError,
127
128 //! \brief The operation could not be completed because a concurrent
129 //! operation affecting the report is occurring.
130 kBusyError,
131 };
132
133 virtual ~CrashReportDatabase() {}
134
135 //! \brief Initializes a database of crash reports.
136 //!
137 //! \param[in] path A path to a writable directory, where the database can
138 //! be created or opened.
139 //!
140 //! \return A database object on success, `nullptr` on failure with an error
141 //! logged.
142 static scoped_ptr<CrashReportDatabase> Initialize(const base::FilePath& path);
143
144 //! \brief Creates a record of a new crash report.
145 //!
146 //! Callers can then write the crash report using the file handle provided.
147 //! The caller does not own this handle, and it must be explicitly closed with
148 //! FinishedWritingCrashReport().
149 //!
150 //! \param[out] report A file handle to which the crash report data should be
151 //! written. Only valid if this returns #kNoError. The caller must not
152 //! close this handle.
153 //!
154 //! \return The operation status code.
155 virtual OperationStatus PrepareNewCrashReport(NewReport** report) = 0;
156
157 //! \brief Informs the database that a crash report has been written.
158 //!
159 //! After calling this method, the database is permitted to move and rename
160 //! the file at Report::file_path.
161 //!
162 //! \param[in] report A handle obtained with PrepareNewCrashReport(). The
163 //! handle will be invalidated as part of this call.
164 //! \param[out] uuid The UUID of this crash report.
165 //!
166 //! \return The operation status code.
167 virtual OperationStatus FinishedWritingCrashReport(NewReport* report,
168 UUID* uuid) = 0;
169
170 //! \brief Returns the crash report record for the unique identifier.
171 //!
172 //! \param[in] uuid The crash report record unique identifier.
173 //! \param[out] report A crash report record. Only valid if this returns
174 //! #kNoError.
175 //!
176 //! \return The operation status code.
177 virtual OperationStatus LookUpCrashReport(const UUID& uuid,
178 Report* report) = 0;
179
180 //! \brief Returns a list of crash report records that have not been uploaded.
181 //!
182 //! \param[out] reports A list of crash report record objects. This must be
183 //! empty on entry. Only valid if this returns #kNoError.
184 //!
185 //! \return The operation status code.
186 virtual OperationStatus GetPendingReports(
187 std::vector<const Report>* reports) = 0;
188
189 //! \brief Returns a list of crash report records that have been completed,
190 //! either by being uploaded or by skipping upload.
191 //!
192 //! \param[out] reports A list of crash report record objects. This must be
193 //! empty on entry. Only valid if this returns #kNoError.
194 //!
195 //! \return The operation status code.
196 virtual OperationStatus GetCompletedReports(
197 std::vector<const Report>* reports) = 0;
198
199 //! \brief Obtains a report object for uploading to a collection server.
200 //!
201 //! The file at Report::file_path should be uploaded by the caller, and then
202 //! the returned Report object must be disposed of via a call to
203 //! RecordUploadAttempt().
204 //!
205 //! A subsequent call to this method with the same \a uuid is illegal until
206 //! RecordUploadAttempt() has been called.
207 //!
208 //! \param[in] uuid The unique identifier for the crash report record.
209 //! \param[out] report A crash report record for the report to be uploaded.
210 //! The caller does not own this object. Only valid if this returns
211 //! #kNoError.
212 //!
213 //! \return The operation status code.
214 virtual OperationStatus GetReportForUploading(const UUID& uuid,
215 const Report** report) = 0;
216
217 //! \brief Adjusts a crash report record’s metadata to account for an upload
218 //! attempt.
219 //!
220 //! After calling this method, the database is permitted to move and rename
221 //! the file at Report::file_path.
222 //!
223 //! \param[in] report The report object obtained from
224 //! GetReportForUploading(). This object is invalidated after this call.
225 //! \param[in] successful Whether the upload attempt was successful.
226 //! \param[in] id The identifier assigned to this crash report by the
227 //! collection server. Must be empty if \a successful is `false`; may be
228 //! empty if it is `true`.
229 //!
230 //! \return The operation status code.
231 virtual OperationStatus RecordUploadAttempt(const Report* report,
232 bool successful,
233 const std::string& id) = 0;
234
235 //! \brief Moves a report from the pending state to the completed state, but
236 //! without the report being uploaded.
237 //!
238 //! This can be used if the user has disabled crash report collection, but
239 //! crash generation is still enabled in the product.
240 //!
241 //! \param[in] uuid The unique identifier for the crash report record.
242 //!
243 //! \return The operation status code.
244 virtual OperationStatus SkipReportUpload(const UUID& uuid) = 0;
245
246 protected:
247 CrashReportDatabase() {}
248
249 private:
250 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabase);
251 };
252
253 } // namespace crashpad
254
255 #endif // CRASHPAD_CLIENT_CRASH_REPORT_DATABASE_H_
OLDNEW
« no previous file with comments | « client/client.gyp ('k') | client/crash_report_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698