chromium/components/safe_browsing/core/browser/db/v4_local_database_manager.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_local_database_manager.h"

#include <utility>
#include <vector>

#include "base/check_op.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_map.h"
#include "base/containers/span.h"
#include "base/feature_list.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/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/ranges/algorithm.h"
#include "base/strings/strcat.h"
#include "base/strings/string_tokenizer.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "components/safe_browsing/core/browser/db/v4_protocol_manager_util.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/safebrowsing_switches.h"
#include "crypto/sha2.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"

namespace safe_browsing {

namespace {

struct CommandLineSwitchAndThreatType {};

// The expiration time of the full hash stored in the artificial database.
const int64_t kFullHashExpiryTimeInMinutes =;

// The number of bytes in a full hash entry.
const int64_t kBytesPerFullHashEntry =;

// The minimum number of entries in the allowlist. If the actual size is
// smaller than this number, the allowlist is considered as unavailable.
const int kHighConfidenceAllowlistMinimumEntryCount =;

// If the switch is present, any high-confidence allowlist check will return
// that it does not match the allowlist.
const char kSkipHighConfidenceAllowlist[] =;

const ThreatSeverity kLeastSeverity =;

ListInfos GetListInfos() {}

base::span<const CommandLineSwitchAndThreatType> GetSwitchAndThreatTypes() {}

// Returns the severity information about a given SafeBrowsing list. The lowest
// value is 0, which represents the most severe list.
ThreatSeverity GetThreatSeverity(const ListIdentifier& list_id) {}

// This is only valid for types that are passed to GetBrowseUrl().
ListIdentifier GetUrlIdFromSBThreatType(SBThreatType sb_threat_type) {}

StoresToCheck CreateStoresToCheckFromSBThreatTypeSet(
    const SBThreatTypeSet& threat_types) {}

void RecordTimeSinceLastUpdateHistograms(const base::Time& last_response_time) {}

void HandleUrlCallback(base::OnceCallback<void(bool)> callback,
                       FullHashToStoreAndHashPrefixesMap results) {}

}  // namespace

V4LocalDatabaseManager::PendingCheck::PendingCheck(
    Client* client,
    ClientCallbackType client_callback_type,
    const StoresToCheck& stores_to_check,
    const std::vector<GURL>& urls)
    :{}

V4LocalDatabaseManager::PendingCheck::PendingCheck(
    Client* client,
    ClientCallbackType client_callback_type,
    const StoresToCheck& stores_to_check,
    const std::set<FullHashStr>& full_hashes_set)
    :{}

V4LocalDatabaseManager::PendingCheck::~PendingCheck() {}

void V4LocalDatabaseManager::PendingCheck::Abandon() {}

// static
const V4LocalDatabaseManager*
    V4LocalDatabaseManager::current_local_database_manager_;

// static
scoped_refptr<V4LocalDatabaseManager> V4LocalDatabaseManager::Create(
    const base::FilePath& base_path,
    scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
    scoped_refptr<base::SequencedTaskRunner> io_task_runner,
    ExtendedReportingLevelCallback extended_reporting_level_callback,
    RecordMigrationMetricsCallback record_migration_metrics_callback) {}

void V4LocalDatabaseManager::CollectDatabaseManagerInfo(
    DatabaseManagerInfo* database_manager_info,
    FullHashCacheInfo* full_hash_cache_info) const {}

V4LocalDatabaseManager::V4LocalDatabaseManager(
    const base::FilePath& base_path,
    ExtendedReportingLevelCallback extended_reporting_level_callback,
    RecordMigrationMetricsCallback record_migration_metrics_callback,
    scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
    scoped_refptr<base::SequencedTaskRunner> io_task_runner,
    scoped_refptr<base::SequencedTaskRunner> task_runner_for_tests)
    :{}

V4LocalDatabaseManager::~V4LocalDatabaseManager() {}

//
// Start: SafeBrowsingDatabaseManager implementation
//

void V4LocalDatabaseManager::CancelCheck(Client* client) {}

bool V4LocalDatabaseManager::CanCheckUrl(const GURL& url) const {}

bool V4LocalDatabaseManager::CheckBrowseUrl(
    const GURL& url,
    const SBThreatTypeSet& threat_types,
    Client* client,
    CheckBrowseUrlType check_type) {}

bool V4LocalDatabaseManager::CheckDownloadUrl(
    const std::vector<GURL>& url_chain,
    Client* client) {}

bool V4LocalDatabaseManager::CheckExtensionIDs(
    const std::set<FullHashStr>& extension_ids,
    Client* client) {}

std::optional<
    SafeBrowsingDatabaseManager::HighConfidenceAllowlistCheckLoggingDetails>
V4LocalDatabaseManager::CheckUrlForHighConfidenceAllowlist(
    const GURL& url,
    base::OnceCallback<void(bool)> callback) {}

bool V4LocalDatabaseManager::CheckUrlForSubresourceFilter(const GURL& url,
                                                          Client* client) {}

AsyncMatch V4LocalDatabaseManager::CheckCsdAllowlistUrl(const GURL& url,
                                                        Client* client) {}

void V4LocalDatabaseManager::MatchDownloadAllowlistUrl(
    const GURL& url,
    base::OnceCallback<void(bool)> callback) {}

ThreatSource V4LocalDatabaseManager::GetBrowseUrlThreatSource(
    CheckBrowseUrlType check_type) const {}

ThreatSource V4LocalDatabaseManager::GetNonBrowseUrlThreatSource() const {}

void V4LocalDatabaseManager::StartOnUIThread(
    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
    const V4ProtocolConfig& config) {}

void V4LocalDatabaseManager::StopOnUIThread(bool shutdown) {}

bool V4LocalDatabaseManager::IsDatabaseReady() const {}

//
// End: SafeBrowsingDatabaseManager implementation
//

void V4LocalDatabaseManager::DatabaseReadyForChecks(
    base::Time start_time,
    std::unique_ptr<V4Database, base::OnTaskRunnerDeleter> v4_database) {}

void V4LocalDatabaseManager::DatabaseReadyForUpdates(
    const std::vector<ListIdentifier>& stores_to_reset) {}

void V4LocalDatabaseManager::DatabaseUpdated() {}

void V4LocalDatabaseManager::GetArtificialPrefixMatches(
    const std::unique_ptr<PendingCheck>& check) {}

void V4LocalDatabaseManager::GetPrefixMatches(
    PendingCheck* check,
    base::OnceCallback<void(FullHashToStoreAndHashPrefixesMap)> callback) {}

void V4LocalDatabaseManager::GetSeverestThreatTypeAndMetadata(
    const std::vector<FullHashInfo>& full_hash_infos,
    const std::vector<FullHashStr>& full_hashes,
    std::vector<SBThreatType>* full_hash_threat_types,
    SBThreatType* most_severe_threat_type,
    ThreatMetadata* metadata) {}

StoresToCheck V4LocalDatabaseManager::GetStoresForFullHashRequests() {}

std::unique_ptr<StoreStateMap> V4LocalDatabaseManager::GetStoreStateMap() {}

// Returns the SBThreatType corresponding to a given SafeBrowsing list.
SBThreatType V4LocalDatabaseManager::GetSBThreatTypeForList(
    const ListIdentifier& list_id) {}

void V4LocalDatabaseManager::HandleAllowlistCheck(
    std::unique_ptr<PendingCheck> check,
    bool allow_async_full_hash_check,
    base::OnceCallback<void(bool)> callback) {}

void V4LocalDatabaseManager::HandleAllowlistCheckContinuation(
    std::unique_ptr<PendingCheck> check,
    bool allow_async_full_hash_check,
    base::OnceCallback<void(bool)> callback,
    FullHashToStoreAndHashPrefixesMap results) {}

void V4LocalDatabaseManager::HandleCheck(std::unique_ptr<PendingCheck> check) {}

void V4LocalDatabaseManager::HandleCheckContinuation(
    std::unique_ptr<PendingCheck> check,
    FullHashToStoreAndHashPrefixesMap results) {}

void V4LocalDatabaseManager::PopulateArtificialDatabase() {}

void V4LocalDatabaseManager::ScheduleFullHashCheck(
    std::unique_ptr<PendingCheck> check) {}

void V4LocalDatabaseManager::HandleUrl(
    const GURL& url,
    const StoresToCheck& stores_to_check,
    base::OnceCallback<void(bool)> callback) {}

void V4LocalDatabaseManager::OnFullHashResponse(
    std::unique_ptr<PendingCheck> check,
    const std::vector<FullHashInfo>& full_hash_infos) {}

void V4LocalDatabaseManager::PerformFullHashCheck(
    std::unique_ptr<PendingCheck> check) {}

void V4LocalDatabaseManager::ProcessQueuedChecks() {}

void V4LocalDatabaseManager::ProcessQueuedChecksContinuation(
    std::unique_ptr<PendingCheck> check,
    FullHashToStoreAndHashPrefixesMap results) {}

void V4LocalDatabaseManager::RespondSafeToQueuedAndPendingChecks() {}

void V4LocalDatabaseManager::DropQueuedAndPendingChecks() {}

void V4LocalDatabaseManager::RespondToClient(
    std::unique_ptr<PendingCheck> check) {}

void V4LocalDatabaseManager::RespondToClientWithoutPendingCheckCleanup(
    PendingCheck* check) {}

void V4LocalDatabaseManager::SetupDatabase() {}

void V4LocalDatabaseManager::SetupUpdateProtocolManager(
    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
    const V4ProtocolConfig& config) {}

void V4LocalDatabaseManager::UpdateRequestCompleted(
    std::unique_ptr<ParsedServerResponse> parsed_server_response) {}

bool V4LocalDatabaseManager::AreAllStoresAvailableNow(
    const StoresToCheck& stores_to_check) const {}

int64_t V4LocalDatabaseManager::GetStoreEntryCount(const ListIdentifier& store,
                                                   int bytes_per_entry) const {}

bool V4LocalDatabaseManager::IsStoreTooSmall(const ListIdentifier& store,
                                             int bytes_per_entry,
                                             int min_entry_count) const {}

bool V4LocalDatabaseManager::AreAnyStoresAvailableNow(
    const StoresToCheck& stores_to_check) const {}

void V4LocalDatabaseManager::UpdateListClientStates(
    const std::unique_ptr<StoreStateMap>& store_state_map) {}

void V4LocalDatabaseManager::AddPendingCheck(PendingCheck* check) {}

void V4LocalDatabaseManager::RemovePendingCheck(
    PendingChecks::const_iterator it) {}

V4LocalDatabaseManager::PendingChecks
V4LocalDatabaseManager::CopyAndRemoveAllPendingChecks() {}

V4LocalDatabaseManager::HighConfidenceAllowlistCheckLoggingDetails::
    HighConfidenceAllowlistCheckLoggingDetails(
        bool were_all_stores_available,
        bool was_allowlist_size_too_small)
    :{}

}  // namespace safe_browsing