Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Sreeja Kamishetty | f66553a | 2022-07-14 17:41:27 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_PARAMS_H_ |
| 6 | #define CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_PARAMS_H_ |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 7 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 8 | #include <optional> |
Kouhei Ueno | 58165ea | 2023-11-13 03:41:07 | [diff] [blame] | 9 | #include <string_view> |
| 10 | |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 11 | #include "base/time/time.h" |
Taiyo Mizuhashi | 6b0a495 | 2024-03-18 22:40:37 | [diff] [blame] | 12 | #include "content/browser/preloading/prefetch/prefetch_type.h" |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 13 | #include "content/common/content_export.h" |
Max Curran | 2e83b5d | 2022-12-29 18:53:38 | [diff] [blame] | 14 | #include "third_party/blink/public/mojom/speculation_rules/speculation_rules.mojom.h" |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 15 | #include "url/gurl.h" |
| 16 | |
| 17 | namespace content { |
| 18 | |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 19 | // The url of the tunnel proxy. |
Max Curran | ead64a6 | 2022-06-22 01:10:52 | [diff] [blame] | 20 | CONTENT_EXPORT GURL PrefetchProxyHost(const GURL& default_proxy_url); |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 21 | |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 22 | // 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. |
| 26 | std::string PrefetchProxyServerExperimentGroup(); |
| 27 | |
Max Curran | ead64a6 | 2022-06-22 01:10:52 | [diff] [blame] | 28 | // Returns true if any domain can issue private prefetches using the prefetch |
| 29 | // proxy. |
| 30 | bool 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. |
| 34 | bool PrefetchAllowAllDomainsForExtendedPreloading(); |
| 35 | |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 36 | // 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 Curran | ead64a6 | 2022-06-22 01:10:52 | [diff] [blame] | 40 | CONTENT_EXPORT bool PrefetchServiceSendDecoyRequestForIneligblePrefetch( |
| 41 | bool disabled_based_on_user_settings); |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 42 | |
| 43 | // The amount of time to allow a prefetch to take before considering it a |
| 44 | // timeout error. |
| 45 | base::TimeDelta PrefetchTimeoutDuration(); |
| 46 | |
| 47 | // The maximum body length allowed to be prefetched for mainframe responses in |
| 48 | // bytes. |
| 49 | size_t PrefetchMainframeBodyLengthLimit(); |
| 50 | |
| 51 | // Whether idle sockets should be closed after every prefetch. |
| 52 | bool PrefetchCloseIdleSockets(); |
| 53 | |
Max Curran | 94511aa | 2022-08-10 20:28:26 | [diff] [blame] | 54 | // Whether a spare renderer should be started after prefetching. |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 55 | bool PrefetchStartsSpareRenderer(); |
| 56 | |
elabadysayed | f7d6b00f | 2025-02-05 11:27:00 | [diff] [blame] | 57 | // 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`. |
| 60 | base::TimeDelta PrefetchContainerDefaultTtlInPrefetchService(); |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 61 | |
Kouhei Ueno | 58165ea | 2023-11-13 03:41:07 | [diff] [blame] | 62 | // Returns if the specified host should have the prefetch proxy bypassed for |
| 63 | // testing purposes. Currently this is only used for WPT test servers. |
| 64 | CONTENT_EXPORT bool ShouldPrefetchBypassProxyForTestHost(std::string_view host); |
Iman Saboori | d74fb3c | 2022-07-21 15:34:38 | [diff] [blame] | 65 | |
Max Curran | 6b93426f | 2022-05-03 00:55:52 | [diff] [blame] | 66 | // Whether only prefetched resources with a text/html MIME type should be used. |
| 67 | // If this is false, there is no MIME type restriction. |
| 68 | bool PrefetchServiceHTMLOnly(); |
| 69 | |
Max Curran | c4445fc | 2022-06-02 18:43:43 | [diff] [blame] | 70 | // The maximum time a prefetched response is servable. |
| 71 | CONTENT_EXPORT base::TimeDelta PrefetchCacheableDuration(); |
| 72 | |
Max Curran | 0146f85 | 2022-08-01 19:49:33 | [diff] [blame] | 73 | // Whether probing must be done at all. |
| 74 | bool PrefetchProbingEnabled(); |
| 75 | |
| 76 | // Whether an ISP filtering canary check should be made on browser startup. |
| 77 | bool 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. |
| 83 | bool PrefetchTLSCanaryCheckEnabled(); |
| 84 | |
| 85 | // The URL to use for the TLS canary check. |
| 86 | GURL PrefetchTLSCanaryCheckURL(const GURL& default_tls_canary_check_url); |
| 87 | |
| 88 | // The URL to use for the DNS canary check. |
| 89 | GURL PrefetchDNSCanaryCheckURL(const GURL& default_dns_canary_check_url); |
| 90 | |
| 91 | // How long a canary check can be cached for the same network. |
| 92 | base::TimeDelta PrefetchCanaryCheckCacheLifetime(); |
| 93 | |
| 94 | // The amount of time to allow before timing out a canary check. |
| 95 | base::TimeDelta PrefetchCanaryCheckTimeout(); |
| 96 | |
| 97 | // The number of retries to allow for canary checks. |
| 98 | int PrefetchCanaryCheckRetries(); |
| 99 | |
Max Curran | e6679ca | 2023-06-06 19:01:39 | [diff] [blame] | 100 | // 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 Tinta | 1fe1a6d | 2023-09-20 19:44:04 | [diff] [blame] | 102 | CONTENT_EXPORT base::TimeDelta PrefetchBlockUntilHeadTimeout( |
kenoss | 5cc0bcf7 | 2025-03-26 04:04:33 | [diff] [blame] | 103 | const PrefetchType& prefetch_type, |
Taiyo Mizuhashi | cd08a8f | 2025-06-10 17:27:32 | [diff] [blame] | 104 | bool should_disable_block_until_head_timeout, |
kenoss | 5cc0bcf7 | 2025-03-26 04:04:33 | [diff] [blame] | 105 | bool is_nav_prerender); |
Max Curran | e6679ca | 2023-06-06 19:01:39 | [diff] [blame] | 106 | |
Taiyo Mizuhashi | 43066071f | 2025-04-25 23:40:22 | [diff] [blame] | 107 | // 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. |
| 113 | CONTENT_EXPORT std::string GetMetricsSuffixTriggerTypeAndEagerness( |
| 114 | const PrefetchType prefetch_type, |
| 115 | const std::optional<std::string>& embedder_histogram_suffix); |
Max Curran | d74e811f | 2023-06-01 19:40:04 | [diff] [blame] | 116 | |
Takashi Nakayama | 978f0a15 | 2025-06-17 08:26:25 | [diff] [blame] | 117 | // The max number of immediate prefetches allowed. |
| 118 | inline constexpr size_t kMaxNumberOfImmediatePrefetchesPerPage = 50; |
| 119 | // The max number of non-immediate prefetches allowed. |
| 120 | inline constexpr size_t kMaxNumberOfNonImmediatePrefetchesPerPage = 2; |
Adithya Srinivasan | f393dd0 | 2023-05-16 20:26:16 | [diff] [blame] | 121 | |
Kouhei Ueno | d47c0bbc | 2023-11-15 23:16:17 | [diff] [blame] | 122 | // Returns true if NIK prefetch scope is enabled. See crbug.com/1502326 |
| 123 | bool PrefetchNIKScopeEnabled(); |
| 124 | |
kenoss | 420b465a | 2024-11-21 13:17:15 | [diff] [blame] | 125 | size_t GetPrefetchDataPipeTeeBodySizeLimit(); |
| 126 | |
kenoss | 1b8ebc2 | 2025-04-04 00:11:35 | [diff] [blame] | 127 | // Returns true iff we should use `PrefetchScheduler`. |
| 128 | CONTENT_EXPORT bool UsePrefetchScheduler(); |
| 129 | |
Max Curran | 18a6f2b | 2022-05-02 23:13:24 | [diff] [blame] | 130 | } // namespace content |
| 131 | |
Sreeja Kamishetty | f66553a | 2022-07-14 17:41:27 | [diff] [blame] | 132 | #endif // CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_PARAMS_H_ |