#include "components/safe_browsing/core/browser/db/v4_get_hash_protocol_manager.h"
#include <memory>
#include <utility>
#include "base/base64url.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/strings/string_split.h"
#include "base/timer/timer.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/utils.h"
#include "net/base/load_flags.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
Time;
namespace {
void RecordGetHashResult(safe_browsing::V4OperationResult result) { … }
void RecordBackoffErrorCountResult(size_t count) { … }
enum ParseResultType { … };
void RecordParseGetHashResult(ParseResultType result_type) { … }
enum V4FullHashCacheResultType { … };
void RecordV4FullHashCacheResult(V4FullHashCacheResultType result_type) { … }
enum V4GetHashCheckResultType { … };
void RecordV4GetHashCheckResult(V4GetHashCheckResultType result_type) { … }
const char kPermission[] = …;
const char kPhaPatternType[] = …;
const char kMalwareThreatType[] = …;
const char kSePatternType[] = …;
const char kLanding[] = …;
const char kDistribution[] = …;
const char kSocialEngineeringAds[] = …;
const char kSocialEngineeringLanding[] = …;
const char kPhishing[] = …;
}
namespace safe_browsing {
class V4GetHashProtocolManagerFactoryImpl
: public V4GetHashProtocolManagerFactory { … };
CachedHashPrefixInfo::CachedHashPrefixInfo() { … }
CachedHashPrefixInfo::CachedHashPrefixInfo(const CachedHashPrefixInfo& other) =
default;
CachedHashPrefixInfo::~CachedHashPrefixInfo() { … }
FullHashCallbackInfo::FullHashCallbackInfo() { … }
FullHashCallbackInfo::FullHashCallbackInfo(
const std::vector<FullHashInfo>& cached_full_hash_infos,
const std::vector<HashPrefixStr>& prefixes_requested,
std::unique_ptr<network::SimpleURLLoader> loader,
const FullHashToStoreAndHashPrefixesMap&
full_hash_to_store_and_hash_prefixes,
FullHashCallback callback,
const base::Time& network_start_time)
: … { … }
FullHashCallbackInfo::~FullHashCallbackInfo() { … }
FullHashInfo::FullHashInfo(const FullHashStr& full_hash,
const ListIdentifier& list_id,
const base::Time& positive_expiry)
: … { … }
FullHashInfo::FullHashInfo(const FullHashInfo& other) = default;
FullHashInfo::~FullHashInfo() { … }
bool FullHashInfo::operator==(const FullHashInfo& other) const { … }
bool FullHashInfo::operator!=(const FullHashInfo& other) const { … }
V4GetHashProtocolManagerFactory* V4GetHashProtocolManager::factory_ = …;
std::unique_ptr<V4GetHashProtocolManager> V4GetHashProtocolManager::Create(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const StoresToCheck& stores_to_check,
const V4ProtocolConfig& config) { … }
void V4GetHashProtocolManager::RegisterFactory(
std::unique_ptr<V4GetHashProtocolManagerFactory> factory) { … }
V4GetHashProtocolManager::V4GetHashProtocolManager(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const StoresToCheck& stores_to_check,
const V4ProtocolConfig& config)
: … { … }
V4GetHashProtocolManager::~V4GetHashProtocolManager() { … }
void V4GetHashProtocolManager::GetFullHashes(
const FullHashToStoreAndHashPrefixesMap
full_hash_to_store_and_hash_prefixes,
const std::vector<std::string>& list_client_states,
FullHashCallback callback) { … }
void V4GetHashProtocolManager::GetFullHashesWithApis(
const GURL& url,
const std::vector<std::string>& list_client_states,
ThreatMetadataForApiCallback api_callback) { … }
void V4GetHashProtocolManager::GetFullHashCachedResults(
const FullHashToStoreAndHashPrefixesMap&
full_hash_to_store_and_hash_prefixes,
const Time& now,
std::vector<HashPrefixStr>* prefixes_to_request,
std::vector<FullHashInfo>* cached_full_hash_infos) { … }
std::string V4GetHashProtocolManager::GetHashRequest(
const std::vector<HashPrefixStr>& prefixes_to_request,
const std::vector<std::string>& list_client_states) { … }
void V4GetHashProtocolManager::GetHashUrlAndHeaders(
const std::string& req_base64,
GURL* gurl,
net::HttpRequestHeaders* headers) const { … }
void V4GetHashProtocolManager::HandleGetHashError(const Time& now) { … }
void V4GetHashProtocolManager::OnFullHashForApi(
ThreatMetadataForApiCallback api_callback,
const std::vector<FullHashStr>& full_hashes,
const std::vector<FullHashInfo>& full_hash_infos) { … }
bool V4GetHashProtocolManager::ParseHashResponse(
const std::string& response_data,
std::vector<FullHashInfo>* full_hash_infos,
Time* negative_cache_expire) { … }
void V4GetHashProtocolManager::ParseMetadata(const ThreatMatch& match,
ThreatMetadata* metadata) { … }
void V4GetHashProtocolManager::ResetGetHashErrors() { … }
void V4GetHashProtocolManager::SetClockForTests(base::Clock* clock) { … }
void V4GetHashProtocolManager::UpdateCache(
const std::vector<HashPrefixStr>& prefixes_requested,
const std::vector<FullHashInfo>& full_hash_infos,
const Time& negative_cache_expire) { … }
void V4GetHashProtocolManager::MergeResults(
const FullHashToStoreAndHashPrefixesMap&
full_hash_to_store_and_hash_prefixes,
const std::vector<FullHashInfo>& full_hash_infos,
std::vector<FullHashInfo>* merged_full_hash_infos) { … }
void V4GetHashProtocolManager::OnURLLoaderComplete(
network::SimpleURLLoader* url_loader,
std::unique_ptr<std::string> response_body) { … }
void V4GetHashProtocolManager::OnURLLoaderCompleteInternal(
network::SimpleURLLoader* url_loader,
int net_error,
int response_code,
const std::string& data) { … }
void V4GetHashProtocolManager::CollectFullHashCacheInfo(
FullHashCacheInfo* full_hash_cache_info) { … }
#ifndef DEBUG
std::ostream& operator<<(std::ostream& os, const FullHashInfo& fhi) { … }
#endif
}