chromium/components/safe_browsing/core/browser/db/hash_prefix_map.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 =;

// This is the max size of the offset map since only the first two bytes of the
// hash are used to compute the index.
constexpr size_t kMaxOffsetMapSize =;

std::string GenerateExtension(PrefixSize size) {}

// Returns true if |hash_prefix| with PrefixSize |size| exists in |prefixes|.
bool HashPrefixMatches(std::string_view prefix,
                       HashPrefixesView prefixes,
                       PrefixSize size,
                       size_t start,
                       size_t end) {}

// Gets the index |prefix| should map to in an offset map of size |size|.
// The index is calculated as follows:
//  - Take the first 16 bits of the prefix.
//  - Divide that number evenly into |size| buckets.
size_t GetOffsetIndex(HashPrefixesView prefix, size_t size) {}

// Gets the size of the offset map based on the experiment configuration.
size_t GetOffsetMapSize(size_t file_size) {}

// Builds the offset map for a prefix DB file.
class OffsetMapBuilder {};

}  // namespace

// Writes a hash prefix file, and buffers writes to avoid a write call for each
// hash prefix. The file will be deleted if Finish() is never called.
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 {};

}  // namespace

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) {}

// static
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 {}

}  // namespace safe_browsing