blob: 3b003b8f18757c8f018d6c218ef08a2f9166b8b7 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2022 The Chromium Authors
Max Curran146bf442022-03-28 23:22:142// 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_STATUS_H_
6#define CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_STATUS_H_
Max Curran146bf442022-03-28 23:22:147
Hiroshige Hayashizaki4e3e0162023-11-01 16:50:128#include "content/public/browser/preloading.h"
9
Max Curran146bf442022-03-28 23:22:1410namespace content {
11
12// The various states that a prefetch can go through or terminate with. Used in
13// UKM logging so don't remove or reorder values. Update
14// |PrefetchProxyPrefetchStatus| in //tools/metrics/histograms/enums.xml
15// whenever this is changed.
keno434b82d2023-06-07 22:59:1116//
17// If you change this, please follow the process
18// https://docs.google.com/document/d/1PnrfowsZMt62PX1EvvTp2Nqs3ji1zrklrAEe1JYbkTk
19// to ensure failure reasons are correctly shown in the DevTools
20// frontend.
Domenic Denicola31e7eb72024-05-31 05:20:5021//
22// If you change this, please follow the process in
23// go/preloading-dashboard-updates to update the mapping reflected in dashboard,
24// or if you are not a Googler, please file an FYI bug on https://crbug.new with
25// component Internals>Preload.
26// LINT.IfChange
Max Curran146bf442022-03-28 23:22:1427enum class PrefetchStatus {
Max Curran094ee8622023-05-08 18:12:3328 // Deprecated. Replaced by `kPrefetchResponseUsed`.
29 //
Max Curran146bf442022-03-28 23:22:1430 // The interceptor used a prefetch.
Max Curran094ee8622023-05-08 18:12:3331 // kPrefetchUsedNoProbe = 0,
Max Curran146bf442022-03-28 23:22:1432
William Liu77089052022-12-15 18:53:3533 // Deprecated. Probe success implies the response is used. Thus replaced
34 // by `kPrefetchResponseUsed`.
35 //
Max Curran146bf442022-03-28 23:22:1436 // The interceptor used a prefetch after successfully probing the origin.
William Liu77089052022-12-15 18:53:3537 // kPrefetchUsedProbeSuccess = 1,
Max Curran146bf442022-03-28 23:22:1438
39 // The interceptor was not able to use an available prefetch because the
40 // origin probe failed.
41 kPrefetchNotUsedProbeFailed = 2,
42
43 // The url was eligible to be prefetched, but the network request was never
44 // made.
45 kPrefetchNotStarted = 3,
46
Max Curran094ee8622023-05-08 18:12:3347 // Deprecated. No longer a reason for ineligibility.
48 //
Max Curran146bf442022-03-28 23:22:1449 // The url was not eligible to be prefetched because it is a Google-owned
50 // domain.
Hiroshige Hayashizaki238198d82023-10-23 23:04:1251 // kPrefetchIneligibleGoogleDomain = 4,
Max Curran146bf442022-03-28 23:22:1452
53 // The url was not eligible to be prefetched because the user had cookies for
54 // that origin.
Hiroshige Hayashizaki238198d82023-10-23 23:04:1255 kPrefetchIneligibleUserHasCookies = 5,
Max Curran146bf442022-03-28 23:22:1456
57 // The url was not eligible to be prefetched because there was a registered
58 // service worker for that origin.
Hiroshige Hayashizaki5fcc71e2025-03-06 21:50:3159 // Some other ServiceWorker-related `PrefetchStatus`/`PreloadingEligibility`
60 // values (e.g. `kPrefetchIneligibleUserHasServiceWorkerNoFetchHandler`) are
61 // used for some subcases.
62 // Even after the initial ServiceWorker support (https://crbug.com/40947546),
63 // this will still used for ServiceWorker-ineligible prefetches.
Hiroshige Hayashizaki238198d82023-10-23 23:04:1264 kPrefetchIneligibleUserHasServiceWorker = 6,
Max Curran146bf442022-03-28 23:22:1465
66 // The url was not eligible to be prefetched because its scheme was not
67 // https://.
Hiroshige Hayashizaki238198d82023-10-23 23:04:1268 kPrefetchIneligibleSchemeIsNotHttps = 7,
Max Curran146bf442022-03-28 23:22:1469
Max Curran094ee8622023-05-08 18:12:3370 // Deprecated. No longer a reason for ineligibility.
71 //
Max Curran146bf442022-03-28 23:22:1472 // The url was not eligible to be prefetched because its host was an IP
Max Curran094ee8622023-05-08 18:12:3373 // address.
Hiroshige Hayashizaki238198d82023-10-23 23:04:1274 // kPrefetchIneligibleHostIsIPAddress = 8,
Max Curran146bf442022-03-28 23:22:1475
76 // The url was not eligible to be prefetched because it uses a non-default
77 // storage partition.
Hiroshige Hayashizaki238198d82023-10-23 23:04:1278 kPrefetchIneligibleNonDefaultStoragePartition = 9,
Max Curran146bf442022-03-28 23:22:1479
80 // The network request was cancelled before it finished. This happens when
81 // there is a new navigation.
82 kPrefetchNotFinishedInTime = 10,
83
84 // The prefetch failed because of a net error.
85 kPrefetchFailedNetError = 11,
86
87 // The prefetch failed with a non-2XX HTTP response code.
88 kPrefetchFailedNon2XX = 12,
89
Simon Pelchat5830fcb52022-04-13 00:17:1890 // The prefetch's Content-Type header was not supported.
91 kPrefetchFailedMIMENotSupported = 13,
Max Curran146bf442022-03-28 23:22:1492
93 // The prefetch finished successfully but was never used.
94 kPrefetchSuccessful = 14,
95
Max Curran094ee8622023-05-08 18:12:3396 // Deprecated. No longer used.
97 //
Max Curran146bf442022-03-28 23:22:1498 // The navigation off of the Google SRP was to a url that was not on the SRP.
Max Curran094ee8622023-05-08 18:12:3399 // kNavigatedToLinkNotOnSRP = 15,
Max Curran146bf442022-03-28 23:22:14100
Max Curran094ee8622023-05-08 18:12:33101 // Deprecated. NSP no longer supported.
102 //
Max Curran146bf442022-03-28 23:22:14103 // Variants of the first three statuses with the additional context of a
104 // successfully completed NoStatePrefetch.
Max Curran094ee8622023-05-08 18:12:33105 // kPrefetchUsedNoProbeWithNSP = 16,
106 // kPrefetchUsedProbeSuccessWithNSP = 17,
107 // kPrefetchNotUsedProbeFailedWithNSP = 18,
Max Curran146bf442022-03-28 23:22:14108
Max Curran094ee8622023-05-08 18:12:33109 // Deprecated. NSP no longer supported
110 //
Max Curran146bf442022-03-28 23:22:14111 // Variants of the first three statuses within the additional context of a
112 // link that was eligible for NoStatePrefetch, but was not started because
113 // the Prerender code denied the request.
Max Curran094ee8622023-05-08 18:12:33114 // kPrefetchUsedNoProbeNSPAttemptDenied = 19,
115 // kPrefetchUsedProbeSuccessNSPAttemptDenied = 20,
116 // kPrefetchNotUsedProbeFailedNSPAttemptDenied = 21,
Max Curran146bf442022-03-28 23:22:14117
Max Curran094ee8622023-05-08 18:12:33118 // Deprecated. NSP no longer supported.
119 //
Max Curran146bf442022-03-28 23:22:14120 // Variants of the first three statuses with in the additional context of a
121 // link that was eligible for NoStatePrefetch that was never started.
Max Curran094ee8622023-05-08 18:12:33122 // kPrefetchUsedNoProbeNSPNotStarted = 22,
123 // kPrefetchUsedProbeSuccessNSPNotStarted = 23,
124 // kPrefetchNotUsedProbeFailedNSPNotStarted = 24,
Max Curran146bf442022-03-28 23:22:14125
Max Curran094ee8622023-05-08 18:12:33126 // Deprecated. Subresources no longer supported.
127 //
Max Curran146bf442022-03-28 23:22:14128 // A subresource which was not fetched because it was throttled by an
129 // experimental control for the max number of subresources per prerender.
Max Curran094ee8622023-05-08 18:12:33130 // kSubresourceThrottled = 25,
Max Curran146bf442022-03-28 23:22:14131
Max Curran094ee8622023-05-08 18:12:33132 // Deprecated. No longer a reason for ineligibilty.
133 //
Max Curran146bf442022-03-28 23:22:14134 // The position of the link in the navigation prediction was not eligible to
135 // be prefetch due to experiment controls.
Max Curran094ee8622023-05-08 18:12:33136 // kPrefetchPositionIneligible = 26,
Max Curran146bf442022-03-28 23:22:14137
138 // A previous prefetch to the origin got a HTTP 503 response with an
139 // Retry-After header that has no elapsed yet.
140 kPrefetchIneligibleRetryAfter = 27,
141
142 // A network error or intentional loadshed was previously encountered when
143 // trying to setup a connection to the proxy and a prefetch should not be done
144 // right now.
Hiroshige Hayashizaki238198d82023-10-23 23:04:12145 kPrefetchIneligiblePrefetchProxyNotAvailable = 28,
Max Curran146bf442022-03-28 23:22:14146
147 // The prefetch was not eligible, but was put on the network anyways and not
148 // used to disguise that the user had some kind of previous relationship with
149 // the origin.
150 kPrefetchIsPrivacyDecoy = 29,
151
152 // The prefetch was eligible, but too much time elapsed between the prefetch
Adithya Srinivasan006b3652023-12-14 14:52:12153 // and the interception.
154 kPrefetchIsStale = 30,
Max Curran094ee8622023-05-08 18:12:33155
156 // Deprecated. NSP no longer supported
157 // kPrefetchIsStaleWithNSP = 31,
158 // kPrefetchIsStaleNSPAttemptDenied = 32,
159 // kPrefetchIsStaleNSPNotStarted = 33,
Max Curran146bf442022-03-28 23:22:14160
161 // The prefetch was not used because cookies were added to the URL after the
162 // initial eligibility check.
163 kPrefetchNotUsedCookiesChanged = 34,
164
Adithya Srinivasan006b3652023-12-14 14:52:12165 // Deprecated. Support for redirects added.
Max Curran094ee8622023-05-08 18:12:33166 //
Max Curran146bf442022-03-28 23:22:14167 // The prefetch was redirected, but following redirects was disabled.
168 // See crbug.com/1266876 for more details.
Max Curran094ee8622023-05-08 18:12:33169 // kPrefetchFailedRedirectsDisabled = 35,
Max Curran146bf442022-03-28 23:22:14170
171 // The url was not eligible to be prefetched because its host was not unique
172 // (e.g., a non publicly routable IP address or a hostname which is not
173 // registry-controlled) but the prefetch was to be proxied.
Hiroshige Hayashizaki238198d82023-10-23 23:04:12174 kPrefetchIneligibleHostIsNonUnique = 36,
Jeremy Romanbae6a422022-05-17 22:41:17175
176 // The prefetch was not made because the user requested that the browser use
177 // less data.
Hiroshige Hayashizaki238198d82023-10-23 23:04:12178 kPrefetchIneligibleDataSaverEnabled = 37,
Max Currancc1ab0c2022-09-12 22:03:11179
180 // The URL is not eligible to be prefetched, because in the default network
181 // context it is configured to use a proxy server.
Hiroshige Hayashizaki238198d82023-10-23 23:04:12182 kPrefetchIneligibleExistingProxy = 38,
William Liu77089052022-12-15 18:53:35183
184 // Prefetch not supported in Guest or Incognito mode.
Jeremy Romana7c3fa72024-07-10 14:09:15185 // OBSOLETE: kPrefetchIneligibleBrowserContextOffTheRecord = 39,
William Liu77089052022-12-15 18:53:35186
187 // Whether this prefetch is heldback for counterfactual logging.
188 kPrefetchHeldback = 40,
Hiroshige Hayashizakif1f8b3602025-01-15 11:50:49189
190 // DEPRECATED
191 // kPrefetchAllowed = 41,
William Liu77089052022-12-15 18:53:35192
193 // The response of the prefetch is used for the next navigation. This is the
194 // final successful state.
195 kPrefetchResponseUsed = 42,
196
Max Curran5d4da4b42023-03-10 23:41:46197 // The prefetch was redirected, but there was a problem with the redirect.
198 kPrefetchFailedInvalidRedirect = 43,
199
200 // The prefetch was redirected, but the redirect URL is not eligible for
201 // prefetch.
202 kPrefetchFailedIneligibleRedirect = 44,
203
Adithya Srinivasan9d1b6fa2024-08-29 15:04:35204 // Deprecated; prefetches are now queued until other prefetches are evicted
205 // when the limit is reached.
206 //
keno8ae912c2023-04-28 06:01:54207 // The prefetch was not made because prefetches exceeded the limit per
208 // page.
Adithya Srinivasan9d1b6fa2024-08-29 15:04:35209 // kPrefetchFailedPerPageLimitExceeded = 45,
keno8ae912c2023-04-28 06:01:54210
Max Curranc0137502023-05-02 18:06:22211 // The prefetch needed to fetch a same-site cross-origin URL and required the
212 // use of the prefetch proxy. These prefetches are blocked since the default
213 // network context cannot be configured to use the prefetch proxy for a single
214 // prefetch request.
Alison Gale770f3fc2024-04-27 00:39:58215 // TODO(crbug.com/40265797): Allow same-site cross-origin prefetches
Max Curranc0137502023-05-02 18:06:22216 // that require the prefetch proxy to be made.
Hiroshige Hayashizaki238198d82023-10-23 23:04:12217 kPrefetchIneligibleSameSiteCrossOriginPrefetchRequiredProxy = 46,
Max Curranc0137502023-05-02 18:06:22218
Iman Saboori8fc6d25a2023-05-17 18:19:20219 // The prefetch was not made because the `Battery Saver` setting was enabled.
Hiroshige Hayashizaki238198d82023-10-23 23:04:12220 kPrefetchIneligibleBatterySaverEnabled = 47,
Iman Saboori8fc6d25a2023-05-17 18:19:20221
222 // The prefetch was not made because preloading was disabled.
Hiroshige Hayashizaki238198d82023-10-23 23:04:12223 kPrefetchIneligiblePreloadingDisabled = 48,
Iman Saboori8fc6d25a2023-05-17 18:19:20224
kenoss6ccd7022025-05-20 14:24:21225 // The prefetch was evicted to make room for a newer prefetch.
Adithya Srinivasanb7f08b42023-12-05 15:49:36226 // kPrefetchEvicted = 49, DEPRECATED
227 kPrefetchEvictedAfterCandidateRemoved = 50,
228 kPrefetchEvictedForNewerPrefetch = 51,
Adithya Srinivasan6054e132023-05-18 17:38:39229
Hiroshige Hayashizaki5fcc71e2025-03-06 21:50:31230 // The initial URL is controlled by a ServiceWorker and then redirected
231 // (https://crbug.com/399819894).
232 kPrefetchIneligibleRedirectFromServiceWorker = 52,
233
234 // The initial URL is redirected to a URL controlled by a ServiceWorker
235 // (https://crbug.com/399819894).
236 // This case was previously counted as
237 // `kPrefetchIneligibleUserHasServiceWorker`.
238 kPrefetchIneligibleRedirectToServiceWorker = 53,
239
240 // The url was not eligible to be prefetched because there was a registered
241 // service worker with no fetch handler (when
242 // `kPrefetchServiceWorkerNoFetchHandlerFix` is enabled).
243 // This case was previously counted as
244 // `kPrefetchIneligibleUserHasServiceWorker`.
245 // Even after the initial ServiceWorker support (https://crbug.com/40947546),
246 // this will be still used for ServiceWorker-ineligible prefetches.
247 kPrefetchIneligibleUserHasServiceWorkerNoFetchHandler = 54,
248
Steven Weie829c85f72025-03-17 18:57:59249 // The prefetch canceled by clearing cache from browsing data removal.
250 kPrefetchEvictedAfterBrowsingDataRemoved = 55,
251
William Liu77089052022-12-15 18:53:35252 // The max value of the PrefetchStatus. Update this when new enums are added.
Steven Weie829c85f72025-03-17 18:57:59253 kMaxValue = kPrefetchEvictedAfterBrowsingDataRemoved,
Max Curran146bf442022-03-28 23:22:14254};
Adithya Srinivasan4d3dad02024-10-17 18:06:59255// LINT.ThenChange(/tools/metrics/histograms/enums.xml)
Max Curran146bf442022-03-28 23:22:14256
Hiroshige Hayashizaki4e3e0162023-11-01 16:50:12257// Mapping from `PrefetchStatus` to `PreloadingFailureReason`.
258static_assert(
259 static_cast<int>(PrefetchStatus::kMaxValue) +
260 static_cast<int>(
261 PreloadingFailureReason::kPreloadingFailureReasonCommonEnd) <=
262 static_cast<int>(
263 PreloadingFailureReason::kPreloadingFailureReasonContentEnd));
264
265inline PreloadingFailureReason ToPreloadingFailureReason(
266 PrefetchStatus prefetch_container_metrics) {
267 return static_cast<PreloadingFailureReason>(
268 static_cast<int>(prefetch_container_metrics) +
269 static_cast<int>(
270 PreloadingFailureReason::kPreloadingFailureReasonCommonEnd));
271}
272
Max Curran146bf442022-03-28 23:22:14273} // namespace content
274
Sreeja Kamishettyf66553a2022-07-14 17:41:27275#endif // CONTENT_BROWSER_PRELOADING_PREFETCH_PREFETCH_STATUS_H_