#include "content/services/auction_worklet/public/cpp/auction_downloader.h"
#include <cstddef>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/trace_event.h"
#include "base/unguessable_token.h"
#include "base/values.h"
#include "net/base/net_errors.h"
#include "net/base/request_priority.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/redirect_info.h"
#include "net/url_request/referrer_policy.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/url_loader_factory.mojom-forward.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/mime_util/mime_util.h"
#include "url/gurl.h"
namespace auction_worklet {
namespace {
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = …;
const char kWebAssemblyMime[] = …;
const char kAdAuctionTrustedSignalsMime[] = …;
std::string TruncateUrlIfNeededForError(const GURL& url) { … }
std::string_view MimeTypeToString(AuctionDownloader::MimeType mime_type) { … }
bool MimeTypeIsConsistent(
AuctionDownloader::MimeType mime_type,
const network::mojom::URLResponseHead& response_info) { … }
bool IsAllowedCharset(std::string_view charset, const std::string& body) { … }
double CalculateMillisecondDelta(const net::LoadTimingInfo& timing,
base::TimeTicks time) { … }
void WriteTraceTiming(const net::LoadTimingInfo& timing,
perfetto::TracedValue dest) { … }
}
AuctionDownloader::AuctionDownloader(
network::mojom::URLLoaderFactory* url_loader_factory,
const GURL& source_url,
DownloadMode download_mode,
MimeType mime_type,
std::optional<std::string> post_body,
std::optional<std::string> content_type,
ResponseStartedCallback response_started_callback,
AuctionDownloaderCallback auction_downloader_callback,
std::unique_ptr<NetworkEventsDelegate> network_events_delegate)
: … { … }
AuctionDownloader::NetworkEventsDelegate::~NetworkEventsDelegate() = default;
AuctionDownloader::~AuctionDownloader() = default;
void AuctionDownloader::OnHeadersOnlyReceived(
scoped_refptr<net::HttpResponseHeaders> headers) { … }
void AuctionDownloader::OnBodyReceived(std::unique_ptr<std::string> body) { … }
void AuctionDownloader::OnRedirect(
const GURL& url_before_redirect,
const net::RedirectInfo& redirect_info,
const network::mojom::URLResponseHead& response_head,
std::vector<std::string>* removed_headers) { … }
void AuctionDownloader::OnResponseStarted(
const GURL& final_url,
const network::mojom::URLResponseHead& response_head) { … }
void AuctionDownloader::FailRequest(network::URLLoaderCompletionStatus status,
std::string error_string) { … }
void AuctionDownloader::TraceResult(bool failure,
base::TimeTicks completion_time,
int64_t encoded_data_length,
int64_t decoded_body_length) { … }
}