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

// Copyright 2016 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/v4_store.h"

#include <algorithm>
#include <array>
#include <optional>
#include <string_view>
#include <utility>

#include "base/base64.h"
#include "base/compiler_specific.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/timer/elapsed_timer.h"
#include "components/safe_browsing/core/browser/db/prefix_iterator.h"
#include "components/safe_browsing/core/browser/db/v4_rice.h"
#include "components/safe_browsing/core/browser/db/v4_store.pb.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/proto/webui.pb.h"
#include "crypto/secure_hash.h"
#include "crypto/sha2.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h"

TimeTicks;

namespace safe_browsing {

namespace {

// UMA related strings.
// Part 1: Represent the overall operation being performed.
const char kProcessFullUpdate[] =;
const char kProcessPartialUpdate[] =;
const char kReadFromDisk[] =;
// Part 2: Represent the sub-operation being performed as part of the larger
// operation from part 1.
const char kApplyUpdate[] =;
const char kDecodeAdditions[] =;
const char kDecodeRemovals[] =;
const char kAdditionsHashesCountPartialUpdate[] =;
const char kAdditionsHashesCountFullUpdate[] =;
const char kRemovalsHashesCount[] =;
const char kApplyUpdateDuration[] =;
const char kVerifyChecksumDuration[] =;
// Part 3: Represent the unit of value being measured and logged.
const char kResult[] =;
// Part 4 (optional): Represent the name of the list for which the metric is
// being logged. For instance, ".UrlSoceng".
// UMA metric names for this file are generated by appending one value each,
// in order, from parts [1, 2, and 3], or [1, 2, 3, and 4]. For example:
// SafeBrowsing.V4ProcessPartialUpdate.ApplyUpdate.Result, or
// SafeBrowsing.V4ProcessPartialUpdate.ApplyUpdate.Result.UrlSoceng
const char kChromeExtMalwareUmaSuffix[] =;
const char kUrlMalBinUmaSuffix[] =;
const char kUrlSocengUmaSuffix[] =;

const uint32_t kFileMagic =;
const uint32_t kFileVersion =;

// The maximum size of additions hashes in a single update response.
const int32_t ADDITIONS_HASHES_COUNT_PARTIAL_UPDATE_MAX =;
const int32_t ADDITIONS_HASHES_COUNT_FULL_UPDATE_MAX =;

// The maximum size of removals hashes in a single update response.
const int32_t REMOVALS_HASHES_COUNT_MAX =;

void RecordEnumWithAndWithoutSuffix(const std::string& metric,
                                    int32_t value,
                                    int32_t maximum,
                                    const base::FilePath& file_path) {}

void RecordBooleanWithAndWithoutSuffix(const std::string& metric,
                                       bool value,
                                       const base::FilePath& file_path) {}

void RecordCountWithAndWithoutSuffix(const std::string& metric,
                                     int32_t value,
                                     int32_t maximum,
                                     const base::FilePath& file_path) {}

void RecordTimeWithAndWithoutSuffix(const std::string& metric,
                                    base::TimeDelta duration,
                                    const base::FilePath& file_path) {}

void RecordApplyUpdateResult(const std::string& base_metric,
                             ApplyUpdateResult result,
                             const base::FilePath& file_path) {}

void RecordDecodeAdditionsResult(const std::string& base_metric,
                                 V4DecodeResult result,
                                 const base::FilePath& file_path) {}

void RecordDecodeRemovalsResult(const std::string& base_metric,
                                V4DecodeResult result,
                                const base::FilePath& file_path) {}

void RecordAdditionsHashesCount(const std::string& base_metric,
                                int32_t count,
                                const base::FilePath& file_path) {}

void RecordRemovalsHashesCount(const std::string& base_metric,
                               int32_t count,
                               const base::FilePath& file_path) {}

void RecordApplyUpdateDuration(const std::string& base_metric,
                               base::TimeDelta duration,
                               const base::FilePath& file_path) {}

void RecordVerifyChecksumDuration(const std::string& base_metric,
                                  base::TimeDelta duration,
                                  const base::FilePath& file_path) {}

void RecordStoreReadResult(StoreReadResult result) {}

void RecordStoreWriteResult(StoreWriteResult result) {}

// Returns the name of the temporary file used to buffer data for
// |filename|.
const base::FilePath TemporaryFileForFilename(const base::FilePath& filename) {}

// Cleans up files that are no longer needed after a successful write. These are
// hash files that may be left behind in the event of a crash or other failure
// which fails to clean up.
void CleanupExtraFiles(const base::FilePath& store_path,
                       const V4StoreFileFormat& file_format) {}

// A ZeroCopyOutputStream that writes to a file using base::File. Any errors
// during serialization close the file.
class BaseFileOutputStream
    : public google::protobuf::io::CopyingOutputStreamAdaptor {};

// A ZeroCopyInputStream that reads from a file using base::File. Any errors
// during deserialization close the file.
class BaseFileInputStream : public google::protobuf::io::ZeroCopyInputStream {};

}  // namespace

int32;
RepeatedField;
RepeatedPtrField;

std::ostream& operator<<(std::ostream& os, const V4Store& store) {}

V4StorePtr V4StoreFactory::CreateV4Store(
    const scoped_refptr<base::SequencedTaskRunner>& task_runner,
    const base::FilePath& store_path) {}

void V4Store::Initialize() {}

bool V4Store::HasValidData() {}

V4Store::V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner,
                 const base::FilePath& store_path,
                 const int64_t old_file_size)
    :{}

V4Store::~V4Store() = default;

std::string V4Store::DebugString() const {}

void V4Store::Reset() {}

ApplyUpdateResult V4Store::ProcessPartialUpdateAndWriteToDisk(
    const std::string& metric,
    const HashPrefixMapView& hash_prefix_map_old,
    std::unique_ptr<ListUpdateResponse> response) {}

ApplyUpdateResult V4Store::ProcessFullUpdateAndWriteToDisk(
    const std::string& metric,
    std::unique_ptr<ListUpdateResponse> response) {}

ApplyUpdateResult V4Store::ProcessFullUpdate(
    const std::string& metric,
    const std::unique_ptr<ListUpdateResponse>& response,
    bool delay_checksum_check) {}

ApplyUpdateResult V4Store::ProcessUpdate(
    const std::string& metric,
    const HashPrefixMapView& hash_prefix_map_old,
    const std::unique_ptr<ListUpdateResponse>& response,
    bool delay_checksum_check) {}

void V4Store::ApplyUpdate(
    std::unique_ptr<ListUpdateResponse> response,
    const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner,
    UpdatedStoreReadyCallback callback) {}

ApplyUpdateResult V4Store::UpdateHashPrefixMapFromAdditions(
    const std::string& metric,
    const RepeatedPtrField<ThreatEntrySet>& additions,
    std::unordered_map<PrefixSize, HashPrefixes>* additions_map) {}

// static
ApplyUpdateResult V4Store::AddUnlumpedHashes(
    PrefixSize prefix_size,
    const std::string& raw_hashes,
    std::unordered_map<PrefixSize, HashPrefixes>* additions_map) {}

// static
ApplyUpdateResult V4Store::AddUnlumpedHashes(
    PrefixSize prefix_size,
    const char* raw_hashes_begin,
    const size_t raw_hashes_length,
    std::unordered_map<PrefixSize, HashPrefixes>* additions_map) {}

// static
bool V4Store::GetNextSmallestUnmergedPrefix(
    const HashPrefixMapView& hash_prefix_map,
    const IteratorMap& iterator_map,
    HashPrefixStr* smallest_hash_prefix) {}

// static
void V4Store::InitializeIteratorMap(const HashPrefixMapView& hash_prefix_map,
                                    IteratorMap* iterator_map) {}

// static
void V4Store::ReserveSpaceInPrefixMap(const HashPrefixMapView& old_map,
                                      const HashPrefixMapView& additions_map,
                                      size_t removals_count,
                                      HashPrefixMap* prefix_map_to_update) {}

ApplyUpdateResult V4Store::MergeUpdate(
    const HashPrefixMapView& old_prefixes_map,
    const HashPrefixMapView& additions_map,
    const RepeatedField<int32>* raw_removals,
    const std::string& expected_checksum) {}

HashPrefixMap::MigrateResult V4Store::MigrateFileFormatIfNeeded(
    V4StoreFileFormat* file_format) {}

StoreReadResult V4Store::ReadFromDisk() {}

StoreWriteResult V4Store::WriteToDisk(const Checksum& checksum) {}

StoreWriteResult V4Store::WriteToDisk(V4StoreFileFormat* file_format) {}

HashPrefixStr V4Store::GetMatchingHashPrefix(const FullHashStr& full_hash) {}

HashPrefixStr V4Store::GetMatchingHashPrefix(std::string_view full_hash) {}

bool V4Store::VerifyChecksum() {}

int64_t V4Store::RecordAndReturnFileSize(const std::string& base_metric) {}

void V4Store::CollectStoreInfo(
    DatabaseManagerInfo::DatabaseInfo::StoreInfo* store_info,
    const std::string& base_metric) {}

V4StoreDeleter::V4StoreDeleter(
    scoped_refptr<base::SequencedTaskRunner> task_runner)
    :{}
V4StoreDeleter::~V4StoreDeleter() = default;
V4StoreDeleter::V4StoreDeleter(V4StoreDeleter&&) = default;
V4StoreDeleter& V4StoreDeleter::operator=(V4StoreDeleter&&) = default;

}  // namespace safe_browsing