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_PRUNE_CRASH_REPORTS_H_ |
| 16 #define CRASHPAD_CLIENT_PRUNE_CRASH_REPORTS_H_ |
| 17 |
| 18 #include <time.h> |
| 19 #include <sys/types.h> |
| 20 |
| 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "client/crash_report_database.h" |
| 23 |
| 24 namespace crashpad { |
| 25 |
| 26 class PruneCondition; |
| 27 |
| 28 //! \brief Deletes crash reports from \a database that match \a condition. |
| 29 //! |
| 30 //! This function can be used to remove old or large reports from the database. |
| 31 //! The \a condition will be evaluated against each report in the \a database, |
| 32 //! sorted in descending order by CrashReportDatabase::Report::creation_time. |
| 33 //! This guarantee allows conditions to be stateful. |
| 34 //! |
| 35 //! \param[in] database The database from which crash reports will be deleted. |
| 36 //! \param[in] condition The condition against which all reports in the database |
| 37 //! will be evaluated. |
| 38 void PruneCrashReportDatabase(CrashReportDatabase* database, |
| 39 PruneCondition* condition); |
| 40 |
| 41 scoped_ptr<PruneCondition> GetDefaultDatabasePruneCondition(); |
| 42 |
| 43 //! \brief An abstract base class for evaluating crash reports for deletion. |
| 44 //! |
| 45 //! When passed to PruneCrashReportDatabase(), each crash report in the |
| 46 //! database will be evaluated according to ShouldPruneReport(). The reports |
| 47 //! are evaluated serially in descending sort order by |
| 48 //! CrashReportDatabase::Report::creation_time. |
| 49 class PruneCondition { |
| 50 public: |
| 51 //! \brief Returns a sensible default condition for removing obsolete crash |
| 52 //! reports. |
| 53 //! |
| 54 //! The default is to keep reports for one year or a maximum database size |
| 55 //! of 128 MB. |
| 56 //! |
| 57 //! \return A PruneCondition for use with PruneCrashReportDatabase(). |
| 58 static scoped_ptr<PruneCondition> GetDefault(); |
| 59 |
| 60 virtual ~PruneCondition() {} |
| 61 |
| 62 //! \brief Evaluates a crash report for deletion. |
| 63 //! |
| 64 //! \param[in] report The crash report to evaluate. |
| 65 //! |
| 66 //! \return `true` if the crash report should be deleted, `false` if it |
| 67 //! should be kept. |
| 68 virtual bool ShouldPruneReport(const CrashReportDatabase::Report& report) = 0; |
| 69 }; |
| 70 |
| 71 //! \brief A PruneCondition that deletes reports older than the specified number |
| 72 //! days. |
| 73 class AgePruneCondition final : public PruneCondition { |
| 74 public: |
| 75 //! \brief Creates a PruneCondition based on Report::creation_time. |
| 76 //! |
| 77 //! \param[in] max_age_in_days Reports created more than this many days ago |
| 78 //! will be deleted. |
| 79 explicit AgePruneCondition(int max_age_in_days); |
| 80 ~AgePruneCondition(); |
| 81 |
| 82 bool ShouldPruneReport(const CrashReportDatabase::Report& report) override; |
| 83 |
| 84 private: |
| 85 const time_t oldest_report_time_; |
| 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(AgePruneCondition); |
| 88 }; |
| 89 |
| 90 //! \brief A PruneCondition that deletes older reports to keep the total |
| 91 //! Crashpad database size under the specified limit. |
| 92 class DatabaseSizePruneCondition final : public PruneCondition { |
| 93 public: |
| 94 //! \brief Creates a PruneCondition that will keep newer reports, until the |
| 95 //! sum of the size of all reports is not smaller than \a max_size_in_kb. |
| 96 //! After the limit is reached, older reports will be pruned. |
| 97 //! |
| 98 //! \param[in] max_size_in_kb The maximum number of kilobytes that all crash |
| 99 //! reports should consume. |
| 100 explicit DatabaseSizePruneCondition(size_t max_size_in_kb); |
| 101 ~DatabaseSizePruneCondition(); |
| 102 |
| 103 bool ShouldPruneReport(const CrashReportDatabase::Report& report) override; |
| 104 |
| 105 private: |
| 106 const size_t max_size_in_kb_; |
| 107 size_t measured_size_in_kb_; |
| 108 |
| 109 DISALLOW_COPY_AND_ASSIGN(DatabaseSizePruneCondition); |
| 110 }; |
| 111 |
| 112 //! \breif A PruneCondition that conjoins two other PruneConditions. |
| 113 class BinaryPruneCondition final : public PruneCondition { |
| 114 public: |
| 115 enum Operator { |
| 116 AND, |
| 117 OR, |
| 118 }; |
| 119 |
| 120 //! \brief Evaluates two sub-conditions according to the specified logical |
| 121 //! operator. |
| 122 //! |
| 123 //! This implements left-to-right evaluation. For Operator::AND, this means |
| 124 //! if the \a lhs is `false`, the \a rhs will not be consulted. Similarly, |
| 125 //! with Operator::OR, if the \a lhs is `true`, the \a rhs will not be |
| 126 //! consulted. |
| 127 //! |
| 128 //! \param[in] op The logical operator to apply on \a lhs and \a rhs. |
| 129 //! \param[in] lhs The left-hand side of \a op. This class takes ownership. |
| 130 //! \param[in] rhs The right-hand side of \a op. This class takes ownership. |
| 131 BinaryPruneCondition(Operator op, PruneCondition* lhs, PruneCondition* rhs); |
| 132 ~BinaryPruneCondition(); |
| 133 |
| 134 bool ShouldPruneReport(const CrashReportDatabase::Report& report) override; |
| 135 |
| 136 private: |
| 137 const Operator op_; |
| 138 scoped_ptr<PruneCondition> lhs_; |
| 139 scoped_ptr<PruneCondition> rhs_; |
| 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(BinaryPruneCondition); |
| 142 }; |
| 143 |
| 144 } // namespace crashpad |
| 145 |
| 146 #endif // CRASHPAD_CLIENT_PRUNE_CRASH_REPORTS_H_ |
OLD | NEW |