#ifndef CONTENT_BROWSER_BROWSING_DATA_CONDITIONAL_CACHE_DELETION_HELPER_H_
#define CONTENT_BROWSER_BROWSING_DATA_CONDITIONAL_CACHE_DELETION_HELPER_H_
#include <memory>
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/sequence_checker.h"
#include "base/task/sequenced_task_runner_helpers.h"
#include "net/base/completion_once_callback.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/disk_cache.h"
#include "url/gurl.h"
namespace disk_cache {
class Entry;
}
namespace content {
class ConditionalCacheDeletionHelper {
public:
ConditionalCacheDeletionHelper(
disk_cache::Backend* cache,
base::RepeatingCallback<bool(const disk_cache::Entry*)> condition);
ConditionalCacheDeletionHelper(const ConditionalCacheDeletionHelper&) =
delete;
ConditionalCacheDeletionHelper& operator=(
const ConditionalCacheDeletionHelper&) = delete;
static base::RepeatingCallback<bool(const disk_cache::Entry*)>
CreateURLAndTimeCondition(
base::RepeatingCallback<bool(const GURL&)> url_predicate,
base::RepeatingCallback<std::string(const std::string&)> get_url_from_key,
base::Time begin_time,
base::Time end_time);
int DeleteAndDestroySelfWhenFinished(
net::CompletionOnceCallback completion_callback);
private:
friend class base::DeleteHelper<ConditionalCacheDeletionHelper>;
~ConditionalCacheDeletionHelper();
void IterateOverEntries(disk_cache::EntryResult result);
raw_ptr<disk_cache::Backend> cache_;
const base::RepeatingCallback<bool(const disk_cache::Entry*)> condition_;
net::CompletionOnceCallback completion_callback_;
SEQUENCE_CHECKER(sequence_checker_);
std::unique_ptr<disk_cache::Backend::Iterator> iterator_;
raw_ptr<disk_cache::Entry> previous_entry_;
};
}
#endif