chromium/content/services/auction_worklet/public/cpp/auction_downloader.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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[] =;

// If `url` is too long to reasonably use as part of an error message, returns a
// truncated copy of it. Otherwise, returns the entire URL as a string.
std::string TruncateUrlIfNeededForError(const GURL& url) {}

// Returns the MIME type string to send for the Accept header for `mime_type`.
// These are the official IANA MIME type strings, though other MIME type strings
// are allows in the response.
std::string_view MimeTypeToString(AuctionDownloader::MimeType mime_type) {}

// Checks if `response_info` is consistent with `mime_type`.
bool MimeTypeIsConsistent(
    AuctionDownloader::MimeType mime_type,
    const network::mojom::URLResponseHead& response_info) {}

// Checks if `charset` is a valid charset, in lowercase ASCII. Takes `body` as
// well, to ensure it uses the specified charset.
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) {}

}  // namespace

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) {}

}  // namespace auction_worklet