#include "services/network/shared_dictionary/shared_dictionary_manager_on_disk.h"
#include "base/containers/contains.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/token.h"
#include "base/unguessable_token.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/disk_cache.h"
#include "services/network/public/cpp/request_destination.h"
#include "services/network/shared_dictionary/shared_dictionary_storage_on_disk.h"
#include "services/network/shared_dictionary/simple_url_pattern_matcher.h"
namespace network {
namespace {
std::optional<base::UnguessableToken> DeserializeToUnguessableToken(
const std::string& token_string) { … }
std::string ToCommaSeparatedString(
const std::set<mojom::RequestDestination>& match_dest) { … }
}
class SharedDictionaryManagerOnDisk::ClearDataTask
: public SharedDictionaryManagerOnDisk::SerializedTask { … };
class SharedDictionaryManagerOnDisk::ClearDataForIsolationKeyTask
: public SharedDictionaryManagerOnDisk::SerializedTask { … };
class SharedDictionaryManagerOnDisk::ClearDataTaskInfo
: public SharedDictionaryManagerOnDisk::SerializedTaskInfo { … };
class SharedDictionaryManagerOnDisk::ClearDataForIsolationKeyTaskInfo
: public SharedDictionaryManagerOnDisk::SerializedTaskInfo { … };
class SharedDictionaryManagerOnDisk::MismatchingEntryDeletionTask
: public SharedDictionaryManagerOnDisk::SerializedTask { … };
class SharedDictionaryManagerOnDisk::MismatchingEntryDeletionTaskInfo
: public SharedDictionaryManagerOnDisk::SerializedTaskInfo { … };
class SharedDictionaryManagerOnDisk::CacheEvictionTask
: public SharedDictionaryManagerOnDisk::SerializedTask { … };
class SharedDictionaryManagerOnDisk::CacheEvictionTaskInfo
: public SharedDictionaryManagerOnDisk::SerializedTaskInfo { … };
class SharedDictionaryManagerOnDisk::ExpiredDictionaryDeletionTask
: public SharedDictionaryManagerOnDisk::SerializedTask { … };
class SharedDictionaryManagerOnDisk::ExpiredDictionaryDeletionTaskInfo
: public SharedDictionaryManagerOnDisk::SerializedTaskInfo { … };
SharedDictionaryManagerOnDisk::SharedDictionaryManagerOnDisk(
const base::FilePath& database_path,
const base::FilePath& cache_directory_path,
uint64_t cache_max_size,
uint64_t cache_max_count,
#if BUILDFLAG(IS_ANDROID)
disk_cache::ApplicationStatusListenerGetter app_status_listener_getter,
#endif
scoped_refptr<disk_cache::BackendFileOperationsFactory>
file_operations_factory)
: … { … }
SharedDictionaryManagerOnDisk::~SharedDictionaryManagerOnDisk() = default;
scoped_refptr<SharedDictionaryStorage>
SharedDictionaryManagerOnDisk::CreateStorage(
const net::SharedDictionaryIsolationKey& isolation_key) { … }
void SharedDictionaryManagerOnDisk::SetCacheMaxSize(uint64_t cache_max_size) { … }
void SharedDictionaryManagerOnDisk::GetUsageInfo(
base::OnceCallback<void(const std::vector<net::SharedDictionaryUsageInfo>&)>
callback) { … }
void SharedDictionaryManagerOnDisk::GetSharedDictionaryInfo(
const net::SharedDictionaryIsolationKey& isolation_key,
base::OnceCallback<
void(std::vector<network::mojom::SharedDictionaryInfoPtr>)> callback) { … }
void SharedDictionaryManagerOnDisk::GetOriginsBetween(
base::Time start_time,
base::Time end_time,
base::OnceCallback<void(const std::vector<url::Origin>&)> callback) { … }
scoped_refptr<SharedDictionaryWriter>
SharedDictionaryManagerOnDisk::CreateWriter(
const net::SharedDictionaryIsolationKey& isolation_key,
const GURL& url,
base::Time last_fetch_time,
base::Time response_time,
base::TimeDelta expiration,
const std::string& match,
const std::set<mojom::RequestDestination>& match_dest,
const std::string& id,
base::OnceCallback<void(net::SharedDictionaryInfo)> callback) { … }
void SharedDictionaryManagerOnDisk::OnDictionaryWrittenInDiskCache(
const net::SharedDictionaryIsolationKey& isolation_key,
const GURL& url,
base::Time last_fetch_time,
base::Time response_time,
base::TimeDelta expiration,
const std::string& match,
const std::set<mojom::RequestDestination>& match_dest,
const std::string& id,
const base::UnguessableToken& disk_cache_key_token,
base::OnceCallback<void(net::SharedDictionaryInfo)> callback,
SharedDictionaryWriterOnDisk::Result result,
size_t size,
const net::SHA256HashValue& hash) { … }
void SharedDictionaryManagerOnDisk::OnDictionaryWrittenInDatabase(
net::SharedDictionaryInfo info,
base::OnceCallback<void(net::SharedDictionaryInfo)> callback,
net::SQLitePersistentSharedDictionaryStore::RegisterDictionaryResultOrError
result) { … }
void SharedDictionaryManagerOnDisk::UpdateDictionaryLastFetchTime(
net::SharedDictionaryInfo& info,
base::Time last_fetch_time) { … }
void SharedDictionaryManagerOnDisk::UpdateDictionaryLastUsedTime(
net::SharedDictionaryInfo& info) { … }
void SharedDictionaryManagerOnDisk::ClearData(
base::Time start_time,
base::Time end_time,
base::RepeatingCallback<bool(const GURL&)> url_matcher,
base::OnceClosure callback) { … }
void SharedDictionaryManagerOnDisk::ClearDataForIsolationKey(
const net::SharedDictionaryIsolationKey& isolation_key,
base::OnceClosure callback) { … }
void SharedDictionaryManagerOnDisk::PostSerializedTask(
std::unique_ptr<SerializedTaskInfo> task_info) { … }
void SharedDictionaryManagerOnDisk::OnFinishSerializedTask() { … }
void SharedDictionaryManagerOnDisk::MaybeStartSerializedTask() { … }
void SharedDictionaryManagerOnDisk::OnDictionaryDeleted(
const std::set<base::UnguessableToken>& disk_cache_key_tokens,
bool need_to_doom_disk_cache_entries) { … }
void SharedDictionaryManagerOnDisk::MaybePostMismatchingEntryDeletionTask() { … }
void SharedDictionaryManagerOnDisk::MaybePostCacheEvictionTask() { … }
void SharedDictionaryManagerOnDisk::MaybePostExpiredDictionaryDeletionTask() { … }
}