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/misc/uuid.h" |
| 27 |
| 28 namespace crashpad { |
| 29 |
| 30 //! \brief An interface for managing a collection of crash report files and |
| 31 //! metadata associated with the crash reports. |
| 32 class CrashReportDatabase { |
| 33 public: |
| 34 //! \brief A crash report record. |
| 35 //! |
| 36 //! This represents the metadata for a crash report, as well as the location |
| 37 //! of the report itself. A \a CrashReportDatabase maintains at least this |
| 38 //! information. |
| 39 struct Report { |
| 40 Report() : uuid(), file_path(), id(), uploaded(false), |
| 41 last_upload_attempt_time(0), upload_attempts(0) {} |
| 42 |
| 43 // A unique identifier by which this report will always be known to the |
| 44 // database. |
| 45 UUID uuid; |
| 46 |
| 47 // The current location of the crash report on the client's filesystem. |
| 48 // The location of a crash report may change over time, so the UUID should |
| 49 // be used as the canonical identifier. |
| 50 base::FilePath file_path; |
| 51 |
| 52 // An identifier issued to this crash report by a collection server. |
| 53 std::string id; |
| 54 |
| 55 // Whether this crash report was successfully uploaded to a collection |
| 56 // server. |
| 57 bool uploaded; |
| 58 |
| 59 // The last timestamp at which an attempt was made to submit this crash |
| 60 // report to a collection server. If this is zero, then the report has never |
| 61 // been uploaded. If \a uploaded is true, then this timestamp is the time |
| 62 // at which the report was uploaded, and no other attempts to upload this |
| 63 // report will be made. |
| 64 time_t last_upload_attempt_time; |
| 65 |
| 66 // The number of times an attempt was made to submit this report to |
| 67 // a collection server. If this is more than zero, then \a |
| 68 // last_upload_attempt_time will be set to the timestamp of the most |
| 69 // recent attempt. |
| 70 int upload_attempts; |
| 71 }; |
| 72 |
| 73 //! \brief The result code for operations performed on a database. |
| 74 enum OperationStatus { |
| 75 //! \brief No error occurred. |
| 76 kNoError = 0, |
| 77 |
| 78 //! \brief The report that was requested could not be located. |
| 79 kReportNotFound, |
| 80 |
| 81 //! \brief An error occured while performing a file operation on a crash |
| 82 //! report. |
| 83 //! |
| 84 //! A database is responsible for managing both the metadata about a report |
| 85 //! and the actual crash report itself. This error is returned when an |
| 86 //! error occurred when managing the report file. Additional information |
| 87 //! will be logged. |
| 88 kFileSystemError, |
| 89 |
| 90 //! \brief An error occured while recording metadata for a crash report. |
| 91 //! |
| 92 //! A database is responsible for managing both the metadata about a report |
| 93 //! and the actual crash report itself. This error is returned when an |
| 94 //! error occurred when managing the metadata about a crash report. |
| 95 //! Additional information will be logged. |
| 96 kDatabaseError, |
| 97 }; |
| 98 |
| 99 virtual ~CrashReportDatabase() {} |
| 100 |
| 101 //! \brief Initializes a database of crash reports. |
| 102 //! |
| 103 //! \param[in] path A path to a writable directory, where the database can |
| 104 //! be created or opened. |
| 105 //! |
| 106 //! \return A database object on success, NULL on failure with an error |
| 107 //! logged. |
| 108 static scoped_ptr<CrashReportDatabase> Initialize(const base::FilePath& path); |
| 109 |
| 110 //! \brief Creates a record of a new crash report. |
| 111 //! |
| 112 //! Callers can then write the crash report at the file path provided in the |
| 113 //! record. The file at the Report::file_path will not be created as a result |
| 114 //! of this call. |
| 115 //! |
| 116 //! \param[out] report A crash report record. The object is logically const |
| 117 //! and changes to it do not affect the database. |
| 118 //! |
| 119 //! \return The operation status code. |
| 120 virtual OperationStatus PrepareNewCrashReport(Report* report) = 0; |
| 121 |
| 122 //! \brief Informs the database that a crash report has been written. |
| 123 //! |
| 124 //! After calling this method, the database is permitted to move and rename |
| 125 //! the file at Record::file_path. |
| 126 //! |
| 127 //! \param[in] uuid The crash report record unique identifier. The identifier |
| 128 //! must be valid. |
| 129 //! |
| 130 //! \return The operation status code. |
| 131 virtual OperationStatus FinishedWritingCrashReport(const UUID& uuid) = 0; |
| 132 |
| 133 //! \brief Returns the crash report record for the unique identifier. |
| 134 //! |
| 135 //! \param[in] uuid The crash report record unique identifier. |
| 136 //! \param[out] report A crash report record. The object is logically const |
| 137 //! and changes to it do not affect the database. |
| 138 //! |
| 139 //! \return The operation status code. |
| 140 virtual OperationStatus LookUpCrashReport(const UUID& uuid, |
| 141 Report* report) = 0; |
| 142 |
| 143 //! \brief Returns a list of crash report records that have not been uploaded. |
| 144 //! |
| 145 //! \param[out] reports A list of crash report record objects. This must be |
| 146 //! empty. The returned objects are logically const and changes to them |
| 147 //! do not affect the database. |
| 148 //! |
| 149 //! \return The operation status code. |
| 150 virtual OperationStatus GetNotUploadedReports( |
| 151 std::vector<const Report>* reports) = 0; |
| 152 |
| 153 //! \brief Returns a list of crash report records that have been uploaded. |
| 154 //! |
| 155 //! \param[out] reports A list of crash report record objects. This must be |
| 156 //! empty. The returned objects are logically const and changes to them |
| 157 //! do not affect the database. |
| 158 //! |
| 159 //! \return The operation status code. |
| 160 virtual OperationStatus GetUploadedReports( |
| 161 std::vector<const Report>* reports) = 0; |
| 162 |
| 163 //! \brief Adjusts a crash report record's metadata to account for an upload |
| 164 //! attempt. |
| 165 //! |
| 166 //! After calling this method, the database is permitted to move and rename |
| 167 //! the file at Record::file_path. |
| 168 //! |
| 169 //! \param[in] uuid The unique identifier for the crash report record. The |
| 170 //! identifier must be valid. |
| 171 //! \param[in] successful Whether the upload attempt was successful. |
| 172 //! \param[in] id The identifier assigned to this crash report by the |
| 173 //! collection server. Must be empty if \a successful is false; may be |
| 174 //! empty if it is true. |
| 175 //! |
| 176 //! \return The operation status code. |
| 177 virtual OperationStatus RecordUploadAttempt(const UUID& uuid, |
| 178 bool successful, |
| 179 const std::string& id) = 0; |
| 180 |
| 181 protected: |
| 182 CrashReportDatabase() {} |
| 183 |
| 184 private: |
| 185 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabase); |
| 186 }; |
| 187 |
| 188 } // namespace crashpad |
| 189 |
| 190 #endif // CRASHPAD_CLIENT_CRASH_REPORT_DATABASE_H_ |
OLD | NEW |