blob: ab74029439f8ac85b5fb3a26aabac350a03c55ae [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2022 The Chromium Authors
Max Curran18a6f2b2022-05-02 23:13:242// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Sreeja Kamishettyf66553a2022-07-14 17:41:275#ifndef CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_PARAMS_H_
6#define CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_PARAMS_H_
Max Curran18a6f2b2022-05-02 23:13:247
Arthur Sonzognic686e8f2024-01-11 08:36:378#include <optional>
Kouhei Ueno58165ea2023-11-13 03:41:079#include <string_view>
10
Max Curran18a6f2b2022-05-02 23:13:2411#include "base/time/time.h"
Taiyo Mizuhashi6b0a4952024-03-18 22:40:3712#include "content/browser/preloading/prefetch/prefetch_type.h"
Max Curran18a6f2b2022-05-02 23:13:2413#include "content/common/content_export.h"
Max Curran2e83b5d2022-12-29 18:53:3814#include "third_party/blink/public/mojom/speculation_rules/speculation_rules.mojom.h"
Max Curran18a6f2b2022-05-02 23:13:2415#include "url/gurl.h"
16
17namespace content {
18
Max Curran18a6f2b2022-05-02 23:13:2419// The url of the tunnel proxy.
Max Curranead64a62022-06-22 01:10:5220CONTENT_EXPORT GURL PrefetchProxyHost(const GURL& default_proxy_url);
Max Curran18a6f2b2022-05-02 23:13:2421
Max Curran18a6f2b2022-05-02 23:13:2422// This value is included in the |PrefetchProxyHeaderKey| request header.
23// The tunnel proxy will use this to determine what, if any, experimental
24// behavior to apply to requests. If the client is not in any server experiment
25// group, this will return an empty string.
26std::string PrefetchProxyServerExperimentGroup();
27
Max Curranead64a62022-06-22 01:10:5228// Returns true if any domain can issue private prefetches using the prefetch
29// proxy.
30bool PrefetchAllowAllDomains();
31
32// Returns true if any domain can issue private prefetches using the prefetch
33// proxy, so long as the user opted-in to extended preloading.
34bool PrefetchAllowAllDomainsForExtendedPreloading();
35
Max Curran18a6f2b2022-05-02 23:13:2436// Returns true if an ineligible prefetch request should be put on the network,
37// but not cached, to disguise the presence of cookies (or other criteria). The
38// return value is randomly decided based on variation params since always
39// sending the decoy request is expensive from a data use perspective.
Max Curranead64a62022-06-22 01:10:5240CONTENT_EXPORT bool PrefetchServiceSendDecoyRequestForIneligblePrefetch(
41 bool disabled_based_on_user_settings);
Max Curran18a6f2b2022-05-02 23:13:2442
43// The amount of time to allow a prefetch to take before considering it a
44// timeout error.
45base::TimeDelta PrefetchTimeoutDuration();
46
47// The maximum body length allowed to be prefetched for mainframe responses in
48// bytes.
49size_t PrefetchMainframeBodyLengthLimit();
50
51// Whether idle sockets should be closed after every prefetch.
52bool PrefetchCloseIdleSockets();
53
Max Curran94511aa2022-08-10 20:28:2654// Whether a spare renderer should be started after prefetching.
Max Curran18a6f2b2022-05-02 23:13:2455bool PrefetchStartsSpareRenderer();
56
elabadysayedf7d6b00f2025-02-05 11:27:0057// The default amount of time `PrefetchService` will keep an owned
58// `PrefetchContainer` alive. If this value is zero or less, the service will
59// keep the prefetch forever. This can be overridden in the `PrefetchContainer`.
60base::TimeDelta PrefetchContainerDefaultTtlInPrefetchService();
Max Curran18a6f2b2022-05-02 23:13:2461
Kouhei Ueno58165ea2023-11-13 03:41:0762// Returns if the specified host should have the prefetch proxy bypassed for
63// testing purposes. Currently this is only used for WPT test servers.
64CONTENT_EXPORT bool ShouldPrefetchBypassProxyForTestHost(std::string_view host);
Iman Saboorid74fb3c2022-07-21 15:34:3865
Max Curran6b93426f2022-05-03 00:55:5266// Whether only prefetched resources with a text/html MIME type should be used.
67// If this is false, there is no MIME type restriction.
68bool PrefetchServiceHTMLOnly();
69
Max Curranc4445fc2022-06-02 18:43:4370// The maximum time a prefetched response is servable.
71CONTENT_EXPORT base::TimeDelta PrefetchCacheableDuration();
72
Max Curran0146f852022-08-01 19:49:3373// Whether probing must be done at all.
74bool PrefetchProbingEnabled();
75
76// Whether an ISP filtering canary check should be made on browser startup.
77bool PrefetchCanaryCheckEnabled();
78
79// Whether the TLS ISP filtering canary check should enabled. Only has effect if
80// canary checks are enabled (PrefetchProxyCanaryCheckEnabled is true). When
81// false, only the DNS canary check will be performed. When true, both the DNS
82// and TLS canary checks will be enabled.
83bool PrefetchTLSCanaryCheckEnabled();
84
85// The URL to use for the TLS canary check.
86GURL PrefetchTLSCanaryCheckURL(const GURL& default_tls_canary_check_url);
87
88// The URL to use for the DNS canary check.
89GURL PrefetchDNSCanaryCheckURL(const GURL& default_dns_canary_check_url);
90
91// How long a canary check can be cached for the same network.
92base::TimeDelta PrefetchCanaryCheckCacheLifetime();
93
94// The amount of time to allow before timing out a canary check.
95base::TimeDelta PrefetchCanaryCheckTimeout();
96
97// The number of retries to allow for canary checks.
98int PrefetchCanaryCheckRetries();
99
Max Currane6679ca2023-06-06 19:01:39100// The maximum amount of time to block until the head of a prefetch is received.
101// If the value is zero or less, then a navigation can be blocked indefinitely.
Liviu Tinta1fe1a6d2023-09-20 19:44:04102CONTENT_EXPORT base::TimeDelta PrefetchBlockUntilHeadTimeout(
kenoss5cc0bcf72025-03-26 04:04:33103 const PrefetchType& prefetch_type,
Taiyo Mizuhashicd08a8f2025-06-10 17:27:32104 bool should_disable_block_until_head_timeout,
kenoss5cc0bcf72025-03-26 04:04:33105 bool is_nav_prerender);
Max Currane6679ca2023-06-06 19:01:39106
Taiyo Mizuhashi43066071f2025-04-25 23:40:22107// Gets the histogram suffix for the given `prefetch_type` and
108// `embedder_histogram_suffix`.
109// `embedder_histogram_suffix` will be utilized directly to generate the
110// histogram names. `TriggerTypeAndEagerness` in
111// //tools/metrics/histograms/metadata/prefetch/histograms.xml should be updated
112// if we start using a new one.
113CONTENT_EXPORT std::string GetMetricsSuffixTriggerTypeAndEagerness(
114 const PrefetchType prefetch_type,
115 const std::optional<std::string>& embedder_histogram_suffix);
Max Currand74e811f2023-06-01 19:40:04116
Takashi Nakayama978f0a152025-06-17 08:26:25117// The max number of immediate prefetches allowed.
118inline constexpr size_t kMaxNumberOfImmediatePrefetchesPerPage = 50;
119// The max number of non-immediate prefetches allowed.
120inline constexpr size_t kMaxNumberOfNonImmediatePrefetchesPerPage = 2;
Adithya Srinivasanf393dd02023-05-16 20:26:16121
Kouhei Uenod47c0bbc2023-11-15 23:16:17122// Returns true if NIK prefetch scope is enabled. See crbug.com/1502326
123bool PrefetchNIKScopeEnabled();
124
kenoss420b465a2024-11-21 13:17:15125size_t GetPrefetchDataPipeTeeBodySizeLimit();
126
kenoss1b8ebc22025-04-04 00:11:35127// Returns true iff we should use `PrefetchScheduler`.
128CONTENT_EXPORT bool UsePrefetchScheduler();
129
Max Curran18a6f2b2022-05-02 23:13:24130} // namespace content
131
Sreeja Kamishettyf66553a2022-07-14 17:41:27132#endif // CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_PARAMS_H_