#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 {
const char kProcessFullUpdate[] = …;
const char kProcessPartialUpdate[] = …;
const char kReadFromDisk[] = …;
const char kApplyUpdate[] = …;
const char kDecodeAdditions[] = …;
const char kDecodeRemovals[] = …;
const char kAdditionsHashesCountPartialUpdate[] = …;
const char kAdditionsHashesCountFullUpdate[] = …;
const char kRemovalsHashesCount[] = …;
const char kApplyUpdateDuration[] = …;
const char kVerifyChecksumDuration[] = …;
const char kResult[] = …;
const char kChromeExtMalwareUmaSuffix[] = …;
const char kUrlMalBinUmaSuffix[] = …;
const char kUrlSocengUmaSuffix[] = …;
const uint32_t kFileMagic = …;
const uint32_t kFileVersion = …;
const int32_t ADDITIONS_HASHES_COUNT_PARTIAL_UPDATE_MAX = …;
const int32_t ADDITIONS_HASHES_COUNT_FULL_UPDATE_MAX = …;
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) { … }
const base::FilePath TemporaryFileForFilename(const base::FilePath& filename) { … }
void CleanupExtraFiles(const base::FilePath& store_path,
const V4StoreFileFormat& file_format) { … }
class BaseFileOutputStream
: public google::protobuf::io::CopyingOutputStreamAdaptor { … };
class BaseFileInputStream : public google::protobuf::io::ZeroCopyInputStream { … };
}
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) { … }
ApplyUpdateResult V4Store::AddUnlumpedHashes(
PrefixSize prefix_size,
const std::string& raw_hashes,
std::unordered_map<PrefixSize, HashPrefixes>* additions_map) { … }
ApplyUpdateResult V4Store::AddUnlumpedHashes(
PrefixSize prefix_size,
const char* raw_hashes_begin,
const size_t raw_hashes_length,
std::unordered_map<PrefixSize, HashPrefixes>* additions_map) { … }
bool V4Store::GetNextSmallestUnmergedPrefix(
const HashPrefixMapView& hash_prefix_map,
const IteratorMap& iterator_map,
HashPrefixStr* smallest_hash_prefix) { … }
void V4Store::InitializeIteratorMap(const HashPrefixMapView& hash_prefix_map,
IteratorMap* iterator_map) { … }
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;
}