chromium/third_party/blink/renderer/platform/loader/fetch/url_loader/background_url_loader.cc

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

#include "third_party/blink/renderer/platform/loader/fetch/url_loader/background_url_loader.h"

#include <atomic>
#include <cstdint>
#include <memory>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/checked_math.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/common/loader/background_resource_fetch_histograms.h"
#include "third_party/blink/public/common/loader/mime_sniffing_throttle.h"
#include "third_party/blink/public/common/loader/referrer_utils.h"
#include "third_party/blink/public/mojom/navigation/renderer_eviction_reason.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/resource_load_info_notifier_wrapper.h"
#include "third_party/blink/public/platform/web_background_resource_fetch_assets.h"
#include "third_party/blink/public/platform/web_url_error.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/renderer/platform/back_forward_cache_buffer_limit_tracker.h"
#include "third_party/blink/renderer/platform/loader/fetch/back_forward_cache_loader_helper.h"
#include "third_party/blink/renderer/platform/loader/fetch/background_code_cache_host.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_utils.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_request.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/background_response_processor.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/resource_request_client.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/resource_request_sender.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/url_loader_client.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_mojo.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_std.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/deque.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/wtf.h"

namespace {

FollowRedirectCallback;

BodyVariant;

}  // namespace

namespace WTF {

template <>
struct CrossThreadCopier<FollowRedirectCallback> {};

template <>
struct CrossThreadCopier<url::Origin> {};

template <>
struct CrossThreadCopier<network::mojom::URLResponseHeadPtr> {};

template <>
struct CrossThreadCopier<network::URLLoaderCompletionStatus>
    : public CrossThreadCopierByValuePassThrough<
          network::URLLoaderCompletionStatus> {};

template <>
struct CrossThreadCopier<net::RedirectInfo>
    : public CrossThreadCopierByValuePassThrough<net::RedirectInfo> {};

template <>
struct CrossThreadCopier<std::vector<std::string>> {};

template <>
struct CrossThreadCopier<
    std::vector<std::unique_ptr<blink::URLLoaderThrottle>>> {};

template <>
struct CrossThreadCopier<std::optional<mojo_base::BigBuffer>> {};

template <>
struct CrossThreadCopier<net::HttpRequestHeaders> {};

template <>
struct CrossThreadCopier<BodyVariant> {};

template <>
struct CrossThreadCopier<std::optional<network::URLLoaderCompletionStatus>> {};

}  // namespace WTF

namespace blink {

namespace {

BackgroundResourceFetchSupportStatus CanHandleRequestInternal(
    const network::ResourceRequest& request,
    const ResourceLoaderOptions& options,
    bool is_prefech_only_document) {}

}  // namespace

class BackgroundURLLoader::Context
    : public WTF::ThreadSafeRefCounted<BackgroundURLLoader::Context> {};

// static
bool BackgroundURLLoader::CanHandleRequest(
    const network::ResourceRequest& request,
    const ResourceLoaderOptions& options,
    bool is_prefech_only_document) {}

BackgroundURLLoader::BackgroundURLLoader(
    scoped_refptr<WebBackgroundResourceFetchAssets>
        background_resource_fetch_context,
    const Vector<String>& cors_exempt_header_list,
    scoped_refptr<base::SingleThreadTaskRunner> unfreezable_task_runner,
    BackForwardCacheLoaderHelper* back_forward_cache_loader_helper,
    scoped_refptr<BackgroundCodeCacheHost> background_code_cache_host)
    :{}

BackgroundURLLoader::~BackgroundURLLoader() {}

void BackgroundURLLoader::LoadSynchronously(
    std::unique_ptr<network::ResourceRequest> request,
    scoped_refptr<const SecurityOrigin> top_frame_origin,
    bool download_to_blob,
    bool no_mime_sniffing,
    base::TimeDelta timeout_interval,
    URLLoaderClient* client,
    WebURLResponse& response,
    std::optional<WebURLError>& error,
    scoped_refptr<SharedBuffer>& data,
    int64_t& encoded_data_length,
    uint64_t& encoded_body_length,
    scoped_refptr<BlobDataHandle>& downloaded_blob,
    std::unique_ptr<ResourceLoadInfoNotifierWrapper>
        resource_load_info_notifier_wrapper) {}

void BackgroundURLLoader::LoadAsynchronously(
    std::unique_ptr<network::ResourceRequest> request,
    scoped_refptr<const SecurityOrigin> top_frame_origin,
    bool no_mime_sniffing,
    std::unique_ptr<ResourceLoadInfoNotifierWrapper>
        resource_load_info_notifier_wrapper,
    CodeCacheHost* code_cache_host,
    URLLoaderClient* client) {}

void BackgroundURLLoader::Freeze(LoaderFreezeMode mode) {}

void BackgroundURLLoader::DidChangePriority(
    WebURLRequest::Priority new_priority,
    int intra_priority_value) {}

scoped_refptr<base::SingleThreadTaskRunner>
BackgroundURLLoader::GetTaskRunnerForBodyLoader() {}

void BackgroundURLLoader::SetBackgroundResponseProcessorFactory(
    std::unique_ptr<BackgroundResponseProcessorFactory>
        background_response_processor_factory) {}

}  // namespace blink