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

Side by Side Diff: client/prune_crash_reports.h

Issue 1392653002: Add functionality to prune old crash reports from the database. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 2 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
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_PRUNE_CRASH_REPORTS_H_
16 #define CRASHPAD_CLIENT_PRUNE_CRASH_REPORTS_H_
17
18 #include <time.h>
19
20 #include "base/memory/scoped_ptr.h"
21 #include "client/crash_report_database.h"
22
23 namespace crashpad {
24
25 class PruneCondition;
26
27 //! \brief Deletes crash reports from \a database that match \a condition.
28 //!
29 //! This function can be used to remove old or large reports from the database.
30 //! The \a condition will be evaluated against each report in the \a database,
31 //! sorted in descending by CrashReportDatabase::Report::creation_time. This
Mark Mentovai 2015/10/07 03:54:28 in descending what?
Robert Sesek 2015/10/07 16:24:35 Done.
32 //! guarantee allows conditions to be stateful.
33 //!
34 //! \param[in] database The database from which crash reports will be deleted.
35 //! \param[in] condition The condition by which all reports in the database
Mark Mentovai 2015/10/07 03:54:28 by → against?
Robert Sesek 2015/10/07 16:24:34 Done.
36 //! will be evaluated.
37 void PruneCrashReportDatabase(CrashReportDatabase* database,
38 PruneCondition* condition);
39
40 //! \brief Returns a sensible default condition for removing obsolete crash
Mark Mentovai 2015/10/07 03:54:28 This should actually say what the condition is in
Robert Sesek 2015/10/07 16:24:35 Didn't know if we wanted to define that in the API
41 //! reports.
42 //!
43 //! \return A PruneCondition for use with PruneCrashReportDatabase().
44 scoped_ptr<PruneCondition> GetDefaultDatabasePruneCondition();
Mark Mentovai 2015/10/07 03:54:28 Maybe make this a static function, PruneCondition:
Robert Sesek 2015/10/07 16:24:35 Done.
45
46 //! \brief An abstract base class for evaluating crash reports for deletion.
47 //!
48 //! When passed to PruneCrashReportDatabase(), each crash report in the
49 //! database will be evaluated according to ShouldPruneReport(). The reports
50 //! are evaluated serially in descending sort order by Report::creation_time.
51 class PruneCondition {
52 public:
53 virtual ~PruneCondition() {}
54
55 //! \brief Evaluates a crash report for deletion.
56 //!
57 //! \param[in] report The crash report to evaluate.
58 //!
59 //! \return `true` if the crash report should be deleted, `false` if it
60 //! should be kept.
61 virtual bool ShouldPruneReport(const CrashReportDatabase::Report& report) = 0;
62 };
63
64 //! \brief A PruneCondition that deletes reports older than the specified number
65 //! days.
66 class AgePruneCondition : public PruneCondition {
67 public:
68 //! \brief Creates a PruneCondition based on Report::creation_time.
Mark Mentovai 2015/10/07 03:54:28 CrashReportDatabase::Report::creation_time
Robert Sesek 2015/10/07 16:24:35 Done.
69 //!
70 //! \param[in] max_age_in_days Reports created more than this many days ago
71 //! will be deleted.
72 explicit AgePruneCondition(int max_age_in_days);
73 ~AgePruneCondition();
74
75 bool ShouldPruneReport(const CrashReportDatabase::Report& report) override;
76
77 private:
78 time_t oldest_report_time_;
Mark Mentovai 2015/10/07 03:54:28 const
Robert Sesek 2015/10/07 16:24:35 Done.
79
80 DISALLOW_COPY_AND_ASSIGN(AgePruneCondition);
81 };
82
83 //! \brief A PruneCondition that deletes older reports to keep the total
84 //! Crashpad database size under the specified limit.
85 class DatabaseSizePruneCondition : public PruneCondition {
86 public:
87 //! \brief Creates a PruneCondition that will keep newer reports, until the
88 //! sum of the size of all reports is not smaller than
89 //! \a max_size_in_bytes.
Mark Mentovai 2015/10/07 03:54:28 Clarify that after that, it will prune.
Robert Sesek 2015/10/07 16:24:34 Done.
90 //!
91 //! \param[in] max_size_in_bytes The maximum number of bytes that all crash
92 //! crash reports should consume.
Mark Mentovai 2015/10/07 03:54:28 Duplicate “crash crash.”
Robert Sesek 2015/10/07 16:24:34 Done.
93 explicit DatabaseSizePruneCondition(size_t max_size_in_bytes);
Mark Mentovai 2015/10/07 03:54:28 <sys/types.h> for size_t.
Mark Mentovai 2015/10/07 03:54:28 “Bytes” is probably not the best choice for a unit
Robert Sesek 2015/10/07 16:24:35 Done.
Robert Sesek 2015/10/07 16:24:35 Done.
94 ~DatabaseSizePruneCondition();
95
96 bool ShouldPruneReport(const CrashReportDatabase::Report& report) override;
97
98 private:
99 const size_t max_size_in_bytes_;
100 size_t measured_size_;
101
102 DISALLOW_COPY_AND_ASSIGN(DatabaseSizePruneCondition);
103 };
104
105 //! \breif A PruneCondition that conjoins two other PruneConditions.
106 class BinaryPruneCondition : public PruneCondition {
107 public:
108 enum Operator {
Mark Mentovai 2015/10/07 03:54:28 enum class is hot and should work just fine in thi
Robert Sesek 2015/10/07 16:24:34 Sure, but I think it'd be more verbose than necess
109 AND,
110 OR,
111 };
112
113 //! \brief Evaluates two sub-conditions according to the specified logical
114 //! operator.
115 //!
116 //! \param[in] op The logical operator to apply on \a lhs and \a rhs.
Mark Mentovai 2015/10/07 03:54:28 Specify whether short-circuiting is implemented.
Robert Sesek 2015/10/07 16:24:34 Done.
117 //! \param[in] lhs The left-hand side of \a op. This class takes ownership.
118 //! \param[in] rhs The right-hand side of \a op. This class takes ownership.
119 BinaryPruneCondition(Operator op, PruneCondition* lhs, PruneCondition* rhs);
120 ~BinaryPruneCondition();
121
122 bool ShouldPruneReport(const CrashReportDatabase::Report& report) override;
123
124 private:
125 Operator op_;
Mark Mentovai 2015/10/07 03:54:28 These data members can be const. Well, maybe lhs_
Robert Sesek 2015/10/07 16:24:35 Done.
126 scoped_ptr<PruneCondition> lhs_;
127 scoped_ptr<PruneCondition> rhs_;
128
129 DISALLOW_COPY_AND_ASSIGN(BinaryPruneCondition);
130 };
131
132 } // namespace crashpad
133
134 #endif // CRASHPAD_CLIENT_PRUNE_CRASH_REPORTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698