#ifndef SERVICES_NETWORK_SHARED_DICTIONARY_SHARED_DICTIONARY_ON_DISK_H_
#define SERVICES_NETWORK_SHARED_DICTIONARY_SHARED_DICTIONARY_ON_DISK_H_
#include <string>
#include "base/component_export.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/time/time.h"
#include "base/unguessable_token.h"
#include "net/base/hash_value.h"
#include "net/disk_cache/disk_cache.h"
#include "net/shared_dictionary/shared_dictionary.h"
namespace net {
class IOBufferWithSize;
}
namespace network {
class SharedDictionaryDiskCache;
class COMPONENT_EXPORT(NETWORK_SERVICE) SharedDictionaryOnDisk
: public net::SharedDictionary {
public:
SharedDictionaryOnDisk(size_t size,
const net::SHA256HashValue& hash,
const std::string& id,
const base::UnguessableToken& disk_cache_key_token,
SharedDictionaryDiskCache& disk_cahe,
base::OnceClosure disk_cache_error_callback,
base::ScopedClosureRunner on_deleted_closure_runner);
int ReadAll(base::OnceCallback<void(int)> callback) override;
scoped_refptr<net::IOBuffer> data() const override;
size_t size() const override;
const net::SHA256HashValue& hash() const override;
const std::string& id() const override;
private:
~SharedDictionaryOnDisk() override;
enum class State { kLoading, kDone, kFailed };
void OnEntry(base::Time open_start_time, disk_cache::EntryResult result);
void OnDataRead(base::Time read_start_time, int result);
void SetState(State state);
State state_ = State::kLoading;
const size_t size_;
const net::SHA256HashValue hash_;
const std::string id_;
base::OnceClosure disk_cache_error_callback_;
std::vector<base::OnceCallback<void(int)>> readall_callbacks_;
disk_cache::ScopedEntryPtr entry_;
scoped_refptr<net::IOBufferWithSize> data_;
base::ScopedClosureRunner on_deleted_closure_runner_;
base::WeakPtrFactory<SharedDictionaryOnDisk> weak_factory_{this};
};
}
#endif