// Copyright 2023 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_BROWSER_LOADER_KEEP_ALIVE_URL_LOADER_SERVICE_H_ #define CONTENT_BROWSER_LOADER_KEEP_ALIVE_URL_LOADER_SERVICE_H_ #include <memory> #include <optional> #include "base/memory/scoped_refptr.h" #include "content/browser/attribution_reporting/attribution_suitable_context.h" #include "content/browser/loader/keep_alive_url_loader.h" #include "content/common/content_export.h" #include "content/public/browser/weak_document_ptr.h" #include "mojo/public/cpp/bindings/pending_associated_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "services/network/public/mojom/url_loader_factory.mojom.h" #include "third_party/blink/public/common/loader/url_loader_factory_bundle.h" #include "third_party/blink/public/mojom/loader/fetch_later.mojom.h" namespace content { class BrowserContext; class PolicyContainerHost; // A service that stores bound SharedURLLoaderFactory mojo pipes from renderers // of the same storage partition, and the intermediate URLLoader receivers, i.e. // KeepAliveURLLoader, they have created to load fetch keepalive requests. // // A fetch keepalive request is originated from a JS call to // `fetch(..., {keepalive: true})` or `navigator.sendBeacon()`. A renderer can // ask this service to handle such request by using a remote of // mojom::URLLoaderFactory bound to this service by `BindFactory()`, which also // binds RenderFrameHostImpl-specific context with every receiver. // // Calling the remote `CreateLoaderAndStart()` of a factory will create a // `KeepAliveURLLoader` here in browser. The service is responsible for keeping // these loaders in `loader_receivers_` until the corresponding request // completes or fails. // // Handling keepalive requests in this service allows a request to continue even // if a renderer unloads before completion, i.e. the request is "keepalive", // without needing the renderer to stay extra longer than the necessary time. // // This service is created and stored in every `StoragePartitionImpl` instance. // Hence, its lifetime is the same as the owner StoragePartition for a partition // domain, which should be generally longer than any of the renderers spawned // from the partition domain. // // Design Doc: // https://docs.google.com/document/d/1ZzxMMBvpqn8VZBZKnb7Go8TWjnrGcXuLS_USwVVRUvY class CONTENT_EXPORT KeepAliveURLLoaderService { … }; } // namespace content #endif // CONTENT_BROWSER_LOADER_KEEP_ALIVE_URL_LOADER_SERVICE_H_