#ifndef NET_DISK_CACHE_SIMPLE_POST_DOOM_WAITER_H_
#define NET_DISK_CACHE_SIMPLE_POST_DOOM_WAITER_H_
#include <stdint.h>
#include <unordered_map>
#include <vector>
#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "net/base/cache_type.h"
namespace disk_cache {
struct SimplePostDoomWaiter {
SimplePostDoomWaiter();
explicit SimplePostDoomWaiter(base::OnceClosure to_run_post_doom);
SimplePostDoomWaiter(SimplePostDoomWaiter&& other);
~SimplePostDoomWaiter();
SimplePostDoomWaiter& operator=(SimplePostDoomWaiter&& other);
base::OnceClosure run_post_doom;
};
class SimplePostDoomWaiterTable
: public base::RefCounted<SimplePostDoomWaiterTable> {
friend class base::RefCounted<SimplePostDoomWaiterTable>;
public:
explicit SimplePostDoomWaiterTable(net::CacheType cache_type);
SimplePostDoomWaiterTable(const SimplePostDoomWaiterTable&) = delete;
SimplePostDoomWaiterTable& operator=(const SimplePostDoomWaiterTable&) =
delete;
void OnDoomStart(uint64_t entry_hash);
void OnDoomComplete(uint64_t entry_hash);
std::vector<SimplePostDoomWaiter>* Find(uint64_t entry_hash);
bool Has(uint64_t entry_hash) {
return entries_pending_doom_.find(entry_hash) !=
entries_pending_doom_.end();
}
private:
~SimplePostDoomWaiterTable();
net::CacheType cache_type_;
std::unordered_map<uint64_t, std::vector<SimplePostDoomWaiter>>
entries_pending_doom_;
};
}
#endif