#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/affiliations/core/browser/hash_affiliation_fetcher.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "components/affiliations/core/browser/affiliation_api.pb.h"
#include "components/affiliations/core/browser/affiliation_utils.h"
#include "components/affiliations/core/browser/lookup_affiliation_response_parser.h"
#include "components/variations/net/variations_http_headers.h"
#include "crypto/sha2.h"
#include "google_apis/google_api_keys.h"
#include "net/base/load_flags.h"
#include "net/base/url_util.h"
#include "net/http/http_status_code.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"
#include "url/gurl.h"
namespace affiliations {
namespace {
constexpr int kPrefixLength = …;
enum class AffiliationFetchResult { … };
#if BUILDFLAG(IS_ANDROID)
constexpr bool kRequestGroupingInfo = false;
#else
constexpr bool kRequestGroupingInfo = …;
#endif
uint64_t ComputeHashPrefix(const FacetURI& uri) { … }
void LogFetchResult(AffiliationFetchResult result,
base::TimeDelta fetch_time,
size_t response_size = 0) { … }
affiliation_pb::LookupAffiliationMask CreateLookupMask(
const AffiliationFetcherInterface::RequestInfo& request_info) { … }
}
HashAffiliationFetcher::HashAffiliationFetcher(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
AffiliationFetcherDelegate* delegate)
: … { … }
HashAffiliationFetcher::~HashAffiliationFetcher() = default;
AffiliationFetcherDelegate* HashAffiliationFetcher::delegate() const { … }
void HashAffiliationFetcher::StartRequest(
const std::vector<FacetURI>& facet_uris,
RequestInfo request_info) { … }
const std::vector<FacetURI>& HashAffiliationFetcher::GetRequestedFacetURIs()
const { … }
GURL HashAffiliationFetcher::BuildQueryURL() { … }
bool HashAffiliationFetcher::IsFetchPossible() { … }
void HashAffiliationFetcher::FinalizeRequest(
const std::string& payload,
const GURL& query_url,
net::NetworkTrafficAnnotationTag traffic_annotation) { … }
bool HashAffiliationFetcher::ParseResponse(
const std::string& serialized_response,
AffiliationFetcherDelegate::Result* result) const { … }
void HashAffiliationFetcher::OnSimpleLoaderComplete(
std::unique_ptr<std::string> response_body) { … }
bool operator==(const AffiliationFetcherInterface::RequestInfo& lhs,
const AffiliationFetcherInterface::RequestInfo& rhs) = default;
}