#include "components/safe_browsing/core/browser/db/v4_database.h"
#include <memory>
#include <utility>
#include "base/debug/crash_logging.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/proto/webui.pb.h"
#if BUILDFLAG(IS_APPLE)
#include "base/apple/backup_util.h"
#endif
TimeTicks;
namespace safe_browsing {
namespace {
const char kV4DatabaseSizeMetric[] = …;
const char kV4DatabaseSizeLinearMetric[] = …;
const char kV4DatabaseUpdateLatency[] = …;
constexpr base::TimeDelta kUmaMinTime = …;
constexpr base::TimeDelta kUmaMaxTime = …;
constexpr int kUmaNumBuckets = …;
base::LazyInstance<std::unique_ptr<V4DatabaseFactory>>::Leaky g_db_factory = …;
base::LazyInstance<std::unique_ptr<V4StoreFactory>>::Leaky g_store_factory = …;
std::vector<ListIdentifier> VerifyChecksums(
std::vector<std::pair<ListIdentifier, V4Store*>> stores) { … }
FullHashToStoreAndHashPrefixesMap CheckStores(
const std::vector<FullHashStr>& full_hashes,
std::vector<std::pair<ListIdentifier, V4Store*>> stores) { … }
}
std::unique_ptr<V4Database, base::OnTaskRunnerDeleter>
V4DatabaseFactory::Create(
const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
std::unique_ptr<StoreMap> store_map) { … }
void V4Database::Create(
const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
const base::FilePath& base_path,
const ListInfos& list_infos,
NewDatabaseReadyCallback new_db_callback) { … }
void V4Database::CreateOnTaskRunner(
const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
const base::FilePath& base_path,
const ListInfos& list_infos,
const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner,
NewDatabaseReadyCallback new_db_callback) { … }
void V4Database::RegisterDatabaseFactoryForTest(
std::unique_ptr<V4DatabaseFactory> factory) { … }
void V4Database::RegisterStoreFactoryForTest(
std::unique_ptr<V4StoreFactory> factory) { … }
V4Database::V4Database(
const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
std::unique_ptr<StoreMap> store_map)
: … { … }
void V4Database::InitializeOnUIThread() { … }
void V4Database::StopOnUIThread() { … }
V4Database::~V4Database() { … }
void V4Database::ApplyUpdate(
std::unique_ptr<ParsedServerResponse> parsed_server_response,
DatabaseUpdatedCallback db_updated_callback) { … }
void V4Database::UpdatedStoreReady(ListIdentifier identifier,
V4StorePtr new_store) { … }
std::unique_ptr<StoreStateMap> V4Database::GetStoreStateMap() { … }
bool V4Database::AreAnyStoresAvailable(
const StoresToCheck& stores_to_check) const { … }
bool V4Database::AreAllStoresAvailable(
const StoresToCheck& stores_to_check) const { … }
void V4Database::GetStoresMatchingFullHash(
const std::vector<FullHashStr>& full_hashes,
const StoresToCheck& stores_to_check,
base::OnceCallback<void(FullHashToStoreAndHashPrefixesMap)> callback) { … }
void V4Database::ResetStores(
const std::vector<ListIdentifier>& stores_to_reset) { … }
void V4Database::VerifyChecksum(
DatabaseReadyForUpdatesCallback db_ready_for_updates_callback) { … }
void V4Database::OnChecksumVerified(
DatabaseReadyForUpdatesCallback db_ready_for_updates_callback,
const std::vector<ListIdentifier>& stores_to_reset) { … }
bool V4Database::IsStoreAvailable(const ListIdentifier& identifier) const { … }
int64_t V4Database::GetStoreSizeInBytes(
const ListIdentifier& identifier) const { … }
void V4Database::RecordFileSizeHistograms() { … }
HashPrefixMap::MigrateResult V4Database::GetMigrateResult() { … }
void V4Database::RecordDatabaseUpdateLatency() { … }
void V4Database::CollectDatabaseInfo(
DatabaseManagerInfo::DatabaseInfo* database_info) { … }
ListInfo::ListInfo(const bool fetch_updates,
const std::string& filename,
const ListIdentifier& list_id,
const SBThreatType sb_threat_type)
: … { … }
ListInfo::~ListInfo() { … }
}