#include "components/safe_browsing/core/browser/db/hash_prefix_map.h"
#include <string_view>
#include "base/debug/crash_logging.h"
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ref.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/threading/scoped_blocking_call.h"
#include "components/safe_browsing/core/browser/db/prefix_iterator.h"
#include "components/safe_browsing/core/common/features.h"
namespace safe_browsing {
namespace {
constexpr uint32_t kInvalidOffset = …;
constexpr size_t kMaxOffsetMapSize = …;
std::string GenerateExtension(PrefixSize size) { … }
bool HashPrefixMatches(std::string_view prefix,
HashPrefixesView prefixes,
PrefixSize size,
size_t start,
size_t end) { … }
size_t GetOffsetIndex(HashPrefixesView prefix, size_t size) { … }
size_t GetOffsetMapSize(size_t file_size) { … }
class OffsetMapBuilder { … };
}
class HashPrefixMap::BufferedFileWriter { … };
HashPrefixMap::HashPrefixMap(
const base::FilePath& store_path,
scoped_refptr<base::SequencedTaskRunner> task_runner,
size_t buffer_size)
: … { … }
HashPrefixMap::~HashPrefixMap() { … }
void HashPrefixMap::Clear() { … }
void HashPrefixMap::ClearOnTaskRunner() { … }
HashPrefixMapView HashPrefixMap::view() const { … }
HashPrefixesView HashPrefixMap::at(PrefixSize size) const { … }
void HashPrefixMap::Append(PrefixSize size, HashPrefixesView prefix) { … }
void HashPrefixMap::Reserve(PrefixSize size, size_t capacity) { … }
ApplyUpdateResult HashPrefixMap::ReadFromDisk(
const V4StoreFileFormat& file_format) { … }
namespace {
class HashPrefixMapWriteSession : public HashPrefixMap::WriteSession { … };
}
std::unique_ptr<HashPrefixMap::WriteSession> HashPrefixMap::WriteToDisk(
V4StoreFileFormat* file_format) { … }
ApplyUpdateResult HashPrefixMap::IsValid() const { … }
HashPrefixStr HashPrefixMap::GetMatchingHashPrefix(std::string_view full_hash) { … }
HashPrefixMap::MigrateResult HashPrefixMap::MigrateFileFormat(
const base::FilePath& store_path,
V4StoreFileFormat* file_format) { … }
void HashPrefixMap::GetPrefixInfo(
google::protobuf::RepeatedPtrField<
DatabaseManagerInfo::DatabaseInfo::StoreInfo::PrefixSet>* prefix_sets) { … }
base::FilePath HashPrefixMap::GetPath(const base::FilePath& store_path,
const std::string& extension) { … }
const std::string& HashPrefixMap::GetExtensionForTesting(PrefixSize size) { … }
void HashPrefixMap::ClearAndWaitForTesting() { … }
HashPrefixMap::FileInfo& HashPrefixMap::GetFileInfo(PrefixSize size) { … }
HashPrefixMap::FileInfo::FileInfo(const base::FilePath& store_path,
PrefixSize size)
: … { … }
HashPrefixMap::FileInfo::~FileInfo() = default;
HashPrefixesView HashPrefixMap::FileInfo::GetView() const { … }
bool HashPrefixMap::FileInfo::Initialize(const HashFile& hash_file) { … }
bool HashPrefixMap::FileInfo::Finalize(HashFile* hash_file) { … }
HashPrefixStr HashPrefixMap::FileInfo::Matches(
std::string_view full_hash) const { … }
HashPrefixMap::BufferedFileWriter* HashPrefixMap::FileInfo::GetOrCreateWriter(
size_t buffer_size) { … }
const std::string& HashPrefixMap::FileInfo::GetExtensionForTesting() const { … }
}