2022-09-06 19:14:07 -04:00
|
|
|
// Copyright 2015 The Crashpad Authors
|
2015-10-07 17:01:47 -04:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef CRASHPAD_CLIENT_PRUNE_CRASH_REPORTS_H_
|
|
|
|
#define CRASHPAD_CLIENT_PRUNE_CRASH_REPORTS_H_
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2016-01-06 12:22:50 -05:00
|
|
|
#include <time.h>
|
2015-10-07 17:01:47 -04:00
|
|
|
|
2016-04-25 12:13:07 -07:00
|
|
|
#include <memory>
|
|
|
|
|
2015-10-07 17:01:47 -04:00
|
|
|
#include "client/crash_report_database.h"
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
class PruneCondition;
|
|
|
|
|
|
|
|
//! \brief Deletes crash reports from \a database that match \a condition.
|
|
|
|
//!
|
|
|
|
//! This function can be used to remove old or large reports from the database.
|
|
|
|
//! The \a condition will be evaluated against each report in the \a database,
|
|
|
|
//! sorted in descending order by CrashReportDatabase::Report::creation_time.
|
|
|
|
//! This guarantee allows conditions to be stateful.
|
|
|
|
//!
|
|
|
|
//! \param[in] database The database from which crash reports will be deleted.
|
|
|
|
//! \param[in] condition The condition against which all reports in the database
|
|
|
|
//! will be evaluated.
|
2019-09-16 15:54:13 -07:00
|
|
|
//!
|
|
|
|
//! \return The number of deleted crash reports.
|
|
|
|
size_t PruneCrashReportDatabase(CrashReportDatabase* database,
|
|
|
|
PruneCondition* condition);
|
2015-10-07 17:01:47 -04:00
|
|
|
|
2016-04-25 12:13:07 -07:00
|
|
|
std::unique_ptr<PruneCondition> GetDefaultDatabasePruneCondition();
|
2015-10-07 17:01:47 -04:00
|
|
|
|
|
|
|
//! \brief An abstract base class for evaluating crash reports for deletion.
|
|
|
|
//!
|
|
|
|
//! When passed to PruneCrashReportDatabase(), each crash report in the
|
|
|
|
//! database will be evaluated according to ShouldPruneReport(). The reports
|
|
|
|
//! are evaluated serially in descending sort order by
|
|
|
|
//! CrashReportDatabase::Report::creation_time.
|
|
|
|
class PruneCondition {
|
|
|
|
public:
|
|
|
|
//! \brief Returns a sensible default condition for removing obsolete crash
|
|
|
|
//! reports.
|
|
|
|
//!
|
|
|
|
//! The default is to keep reports for one year or a maximum database size
|
|
|
|
//! of 128 MB.
|
|
|
|
//!
|
|
|
|
//! \return A PruneCondition for use with PruneCrashReportDatabase().
|
2016-04-25 12:13:07 -07:00
|
|
|
static std::unique_ptr<PruneCondition> GetDefault();
|
2015-10-07 17:01:47 -04:00
|
|
|
|
|
|
|
virtual ~PruneCondition() {}
|
|
|
|
|
|
|
|
//! \brief Evaluates a crash report for deletion.
|
|
|
|
//!
|
|
|
|
//! \param[in] report The crash report to evaluate.
|
|
|
|
//!
|
|
|
|
//! \return `true` if the crash report should be deleted, `false` if it
|
|
|
|
//! should be kept.
|
|
|
|
virtual bool ShouldPruneReport(const CrashReportDatabase::Report& report) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! \brief A PruneCondition that deletes reports older than the specified number
|
|
|
|
//! days.
|
|
|
|
class AgePruneCondition final : public PruneCondition {
|
|
|
|
public:
|
|
|
|
//! \brief Creates a PruneCondition based on Report::creation_time.
|
|
|
|
//!
|
|
|
|
//! \param[in] max_age_in_days Reports created more than this many days ago
|
|
|
|
//! will be deleted.
|
|
|
|
explicit AgePruneCondition(int max_age_in_days);
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
AgePruneCondition(const AgePruneCondition&) = delete;
|
|
|
|
AgePruneCondition& operator=(const AgePruneCondition&) = delete;
|
|
|
|
|
2015-10-07 17:01:47 -04:00
|
|
|
~AgePruneCondition();
|
|
|
|
|
|
|
|
bool ShouldPruneReport(const CrashReportDatabase::Report& report) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const time_t oldest_report_time_;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! \brief A PruneCondition that deletes older reports to keep the total
|
|
|
|
//! Crashpad database size under the specified limit.
|
|
|
|
class DatabaseSizePruneCondition final : public PruneCondition {
|
|
|
|
public:
|
|
|
|
//! \brief Creates a PruneCondition that will keep newer reports, until the
|
|
|
|
//! sum of the size of all reports is not smaller than \a max_size_in_kb.
|
|
|
|
//! After the limit is reached, older reports will be pruned.
|
|
|
|
//!
|
|
|
|
//! \param[in] max_size_in_kb The maximum number of kilobytes that all crash
|
|
|
|
//! reports should consume.
|
|
|
|
explicit DatabaseSizePruneCondition(size_t max_size_in_kb);
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
DatabaseSizePruneCondition(const DatabaseSizePruneCondition&) = delete;
|
|
|
|
DatabaseSizePruneCondition& operator=(const DatabaseSizePruneCondition&) =
|
|
|
|
delete;
|
|
|
|
|
2015-10-07 17:01:47 -04:00
|
|
|
~DatabaseSizePruneCondition();
|
|
|
|
|
|
|
|
bool ShouldPruneReport(const CrashReportDatabase::Report& report) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const size_t max_size_in_kb_;
|
|
|
|
size_t measured_size_in_kb_;
|
|
|
|
};
|
|
|
|
|
doc: Fix all Doxygen warnings, cleaning up some generated documentation
This makes Doxygen’s output more actionable by setting QUIET = YES to
suppress verbose progress spew, and WARN_IF_UNDOCUMENTED = NO to prevent
warnings for undocumented classes and members from being generated. The
latter is too noisy, producing 721 warnings in the current codebase.
The remaining warnings produced by Doxygen were useful and actionable.
They fell into two categories: abuses of Doxygen’s markup syntax, and
missing (or misspelled) parameter documentation. In a small number of
cases, pass-through parameters had intentionally been left undocumented.
In these cases, they are now given blank \param descriptions. This is
not optimal, but there doesn’t appear to be any other way to tell
Doxygen to allow a single parameter to be undocumented.
Some tricky Doxygen errors were resolved by asking it to not enter
directiores that we do not provide documentation in (such as the
“on-platform” compat directories, compat/mac and compat/win, as well as
compat/non_cxx11_lib) while allowing it to enter the
“off-platform” directories that we do document (compat/non_mac and
compat/non_win).
A Doxygen run (doc/support/generate_doxygen.sh) now produces no output
at all. It would produce warnings if any were triggered.
Not directly related, but still relevant to documentation,
doc/support/generate.sh is updated to remove temporary removals of
now-extinct files and directories. doc/appengine/README is updated so
that a consistent path to “goapp” is used throughout the file.
Change-Id: I300730c04de4d3340551ea3086ca70cc5ff862d1
Reviewed-on: https://chromium-review.googlesource.com/408812
Reviewed-by: Robert Sesek <rsesek@chromium.org>
2016-11-08 14:23:09 -05:00
|
|
|
//! \brief A PruneCondition that conjoins two other PruneConditions.
|
2015-10-07 17:01:47 -04:00
|
|
|
class BinaryPruneCondition final : public PruneCondition {
|
|
|
|
public:
|
|
|
|
enum Operator {
|
|
|
|
AND,
|
|
|
|
OR,
|
|
|
|
};
|
|
|
|
|
|
|
|
//! \brief Evaluates two sub-conditions according to the specified logical
|
|
|
|
//! operator.
|
|
|
|
//!
|
|
|
|
//! This implements left-to-right evaluation. For Operator::AND, this means
|
|
|
|
//! if the \a lhs is `false`, the \a rhs will not be consulted. Similarly,
|
|
|
|
//! with Operator::OR, if the \a lhs is `true`, the \a rhs will not be
|
|
|
|
//! consulted.
|
|
|
|
//!
|
|
|
|
//! \param[in] op The logical operator to apply on \a lhs and \a rhs.
|
|
|
|
//! \param[in] lhs The left-hand side of \a op. This class takes ownership.
|
|
|
|
//! \param[in] rhs The right-hand side of \a op. This class takes ownership.
|
|
|
|
BinaryPruneCondition(Operator op, PruneCondition* lhs, PruneCondition* rhs);
|
2021-09-20 12:55:12 -07:00
|
|
|
|
|
|
|
BinaryPruneCondition(const BinaryPruneCondition&) = delete;
|
|
|
|
BinaryPruneCondition& operator=(const BinaryPruneCondition&) = delete;
|
|
|
|
|
2015-10-07 17:01:47 -04:00
|
|
|
~BinaryPruneCondition();
|
|
|
|
|
|
|
|
bool ShouldPruneReport(const CrashReportDatabase::Report& report) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Operator op_;
|
2016-04-25 12:13:07 -07:00
|
|
|
std::unique_ptr<PruneCondition> lhs_;
|
|
|
|
std::unique_ptr<PruneCondition> rhs_;
|
2015-10-07 17:01:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace crashpad
|
|
|
|
|
|
|
|
#endif // CRASHPAD_CLIENT_PRUNE_CRASH_REPORTS_H_
|