#include "components/segmentation_platform/internal/database/database_maintenance_impl.h"
#include <deque>
#include <memory>
#include <set>
#include <utility>
#include <vector>
#include "base/check_is_test.h"
#include "base/containers/adapters.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "components/prefs/pref_service.h"
#include "components/segmentation_platform/internal/constants.h"
#include "components/segmentation_platform/internal/database/signal_database.h"
#include "components/segmentation_platform/internal/metadata/metadata_utils.h"
#include "components/segmentation_platform/internal/stats.h"
#include "components/segmentation_platform/public/proto/types.pb.h"
namespace {
constexpr uint64_t kFirstCompactionDay = …;
constexpr uint64_t kMaxSignalStorageDays = …;
}
namespace segmentation_platform {
SignalIdentifier;
namespace {
base::Time GetEndOfDayTime(base::Time current_time) { … }
std::set<SignalIdentifier> CollectAllSignalIdentifiers(
std::unique_ptr<SegmentInfoDatabase::SegmentInfoList> segment_infos) { … }
base::OnceClosure LinkTasks(
std::vector<base::OnceCallback<void(base::OnceClosure)>> tasks) { … }
}
struct DatabaseMaintenanceImpl::CleanupState { … };
DatabaseMaintenanceImpl::DatabaseMaintenanceImpl(
const base::flat_set<SegmentId>& segment_ids,
base::Clock* clock,
SegmentInfoDatabase* segment_info_database,
SignalDatabase* signal_database,
SignalStorageConfig* signal_storage_config,
PrefService* profile_prefs)
: … { … }
DatabaseMaintenanceImpl::~DatabaseMaintenanceImpl() = default;
void DatabaseMaintenanceImpl::ExecuteMaintenanceTasks() { … }
void DatabaseMaintenanceImpl::OnSegmentInfoCallback(
std::unique_ptr<SegmentInfoDatabase::SegmentInfoList> segment_infos) { … }
std::vector<base::OnceCallback<void(base::OnceClosure)>>
DatabaseMaintenanceImpl::GetAllTasks(std::set<SignalIdentifier> signal_ids) { … }
void DatabaseMaintenanceImpl::CleanupSignalStorage(
std::set<SignalIdentifier> signal_ids,
base::OnceClosure next_action) { … }
void DatabaseMaintenanceImpl::CleanupSignalStorageProcessNext(
std::unique_ptr<CleanupState> cleanup_state,
base::OnceCallback<void(std::vector<CleanupItem>)> on_done_callback,
CleanupItem previous_item,
bool previous_item_deleted) { … }
void DatabaseMaintenanceImpl::CleanupSignalStorageDone(
base::OnceClosure next_action,
std::vector<CleanupItem> cleaned_up_signals) { … }
void DatabaseMaintenanceImpl::CompactSamples(
std::set<SignalIdentifier> signal_ids,
base::OnceClosure next_action) { … }
void DatabaseMaintenanceImpl::RecordCompactionResult(
proto::SignalType signal_type,
uint64_t name_hash,
bool success) { … }
void DatabaseMaintenanceImpl::CompactSamplesDone(
base::OnceClosure next_action,
base::Time last_compation_time) { … }
}