Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Lingqi Chi | fc4b7d9c | 2021-04-08 01:41:22 | [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 | c227f7a | 2022-07-08 22:33:15 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_PRELOADING_PRERENDER_PRERENDER_METRICS_H_ |
| 6 | #define CONTENT_BROWSER_PRELOADING_PRERENDER_PRERENDER_METRICS_H_ |
Lingqi Chi | fc4b7d9c | 2021-04-08 01:41:22 | [diff] [blame] | 7 | |
Lingqi Chi | db94973 | 2022-11-08 05:55:21 | [diff] [blame] | 8 | #include <cstdint> |
Lingqi Chi | fc4b7d9c | 2021-04-08 01:41:22 | [diff] [blame] | 9 | #include <string> |
Victor Hugo Vianna Silva | 0069272 | 2025-03-18 19:51:48 | [diff] [blame] | 10 | #include <variant> |
Lingqi Chi | fc4b7d9c | 2021-04-08 01:41:22 | [diff] [blame] | 11 | |
Asami Doi | 0240627 | 2021-11-12 05:01:44 | [diff] [blame] | 12 | #include "base/time/time.h" |
Yoshiki Tanioka | 49b4cfb | 2022-10-20 09:25:31 | [diff] [blame] | 13 | #include "content/browser/preloading/prerender/prerender_final_status.h" |
Sreeja Kamishetty | c227f7a | 2022-07-08 22:33:15 | [diff] [blame] | 14 | #include "content/browser/preloading/prerender/prerender_host.h" |
Miina Koyama | d0e41f3 | 2023-11-13 06:50:09 | [diff] [blame] | 15 | #include "content/common/content_export.h" |
Kouhei Ueno | 3f37992b | 2023-11-09 23:29:02 | [diff] [blame] | 16 | #include "content/public/browser/preloading_trigger_type.h" |
Robert Lin | d75062bf | 2021-10-28 12:50:55 | [diff] [blame] | 17 | #include "services/metrics/public/cpp/ukm_source_id.h" |
Lingqi Chi | fc4b7d9c | 2021-04-08 01:41:22 | [diff] [blame] | 18 | |
Robert Lin | d75062bf | 2021-10-28 12:50:55 | [diff] [blame] | 19 | namespace content { |
Kunihiko Sakamoto | 73d0a90 | 2021-07-15 00:22:32 | [diff] [blame] | 20 | |
Miina Koyama | d0e41f3 | 2023-11-13 06:50:09 | [diff] [blame] | 21 | struct CONTENT_EXPORT PrerenderMismatchedHeaders { |
Miina Koyama | 89b81504 | 2023-10-31 08:20:12 | [diff] [blame] | 22 | public: |
| 23 | PrerenderMismatchedHeaders(const std::string& header_name, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 24 | std::optional<std::string> initial_value, |
| 25 | std::optional<std::string> activation_value); |
Miina Koyama | 89b81504 | 2023-10-31 08:20:12 | [diff] [blame] | 26 | |
| 27 | ~PrerenderMismatchedHeaders(); |
| 28 | |
Adithya Srinivasan | 6bd2247 | 2024-08-21 17:13:17 | [diff] [blame] | 29 | PrerenderMismatchedHeaders(const PrerenderMismatchedHeaders& other); |
Miina Koyama | 89b81504 | 2023-10-31 08:20:12 | [diff] [blame] | 30 | PrerenderMismatchedHeaders(PrerenderMismatchedHeaders&& other); |
| 31 | |
Adithya Srinivasan | 6bd2247 | 2024-08-21 17:13:17 | [diff] [blame] | 32 | PrerenderMismatchedHeaders& operator=( |
| 33 | const PrerenderMismatchedHeaders& other); |
Miina Koyama | 89b81504 | 2023-10-31 08:20:12 | [diff] [blame] | 34 | PrerenderMismatchedHeaders& operator=(PrerenderMismatchedHeaders&& other); |
| 35 | |
| 36 | std::string header_name; |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 37 | std::optional<std::string> initial_value; |
| 38 | std::optional<std::string> activation_value; |
Miina Koyama | 89b81504 | 2023-10-31 08:20:12 | [diff] [blame] | 39 | }; |
| 40 | |
Lingqi Chi | fc4b7d9c | 2021-04-08 01:41:22 | [diff] [blame] | 41 | // These values are persisted to logs. Entries should not be renumbered and |
| 42 | // numeric values should never be reused. |
| 43 | // Note: Please update GetCancelledInterfaceType() in the corresponding .cc file |
Julie Jeongeun Kim | 7a9439c | 2022-01-26 13:17:45 | [diff] [blame] | 44 | // and the enum of PrerenderCancelledUnknownInterface in |
| 45 | // tools/metrics/histograms/enums.xml if you add a new item. |
Lingqi Chi | fc4b7d9c | 2021-04-08 01:41:22 | [diff] [blame] | 46 | enum class PrerenderCancelledInterface { |
| 47 | kUnknown = 0, // For kCancel interfaces added by embedders or tests. |
| 48 | kGamepadHapticsManager = 1, |
| 49 | kGamepadMonitor = 2, |
Lingqi Chi | d9aedcb | 2022-06-07 08:06:55 | [diff] [blame] | 50 | // kNotificationService = 3, Deprecated. |
Martin Kreichgauer | 8f209898 | 2023-06-12 22:13:47 | [diff] [blame] | 51 | kTrustedVaultEncryptionKeys = 4, |
| 52 | kMaxValue = kTrustedVaultEncryptionKeys |
Lingqi Chi | fc4b7d9c | 2021-04-08 01:41:22 | [diff] [blame] | 53 | }; |
| 54 | |
Lingqi Chi | c7fe224 | 2022-08-26 10:35:36 | [diff] [blame] | 55 | // Used by PrerenderNavigationThrottle, to track the cross-origin cancellation |
| 56 | // reason, and break it down into more cases. |
| 57 | // These values are persisted to logs. Entries should not be renumbered and |
| 58 | // numeric values should never be reused. |
| 59 | enum class PrerenderCrossOriginRedirectionMismatch { |
| 60 | kShouldNotBeReported = 0, |
| 61 | kPortMismatch = 1, |
| 62 | kHostMismatch = 2, |
| 63 | kHostPortMismatch = 3, |
| 64 | kSchemeMismatch = 4, |
| 65 | kSchemePortMismatch = 5, |
| 66 | kSchemeHostMismatch = 6, |
| 67 | kSchemeHostPortMismatch = 7, |
| 68 | kMaxValue = kSchemeHostPortMismatch |
| 69 | }; |
| 70 | |
Lingqi Chi | 8e192ba | 2022-11-22 04:34:25 | [diff] [blame] | 71 | // Assembles PrerenderHostFinalStatus with a detailed explanation if applicable. |
| 72 | // Some FinalStatus enums cover multiple sub cases. To explain them in detail, |
| 73 | // some explanations can be attached to the status. |
Miina Koyama | d0e41f3 | 2023-11-13 06:50:09 | [diff] [blame] | 74 | class CONTENT_EXPORT PrerenderCancellationReason { |
Lingqi Chi | 8e192ba | 2022-11-22 04:34:25 | [diff] [blame] | 75 | public: |
keno | e16970c | 2023-06-26 10:59:29 | [diff] [blame] | 76 | // Tagged by `final_status_`. See `BuildFor*` and `ToDevtoolReasonString`. |
Miina Koyama | d0e41f3 | 2023-11-13 06:50:09 | [diff] [blame] | 77 | using DetailedReasonVariant = |
Victor Hugo Vianna Silva | 0069272 | 2025-03-18 19:51:48 | [diff] [blame] | 78 | std::variant<std::monostate, |
| 79 | int32_t, |
| 80 | uint64_t, |
| 81 | std::string, |
| 82 | std::vector<PrerenderMismatchedHeaders>>; |
Miina Koyama | d0e41f3 | 2023-11-13 06:50:09 | [diff] [blame] | 83 | |
| 84 | explicit PrerenderCancellationReason(PrerenderFinalStatus final_status); |
| 85 | ~PrerenderCancellationReason(); |
Lingqi Chi | 8e192ba | 2022-11-22 04:34:25 | [diff] [blame] | 86 | |
| 87 | static PrerenderCancellationReason BuildForDisallowActivationState( |
| 88 | uint64_t disallow_activation_reason); |
| 89 | |
| 90 | static PrerenderCancellationReason BuildForMojoBinderPolicy( |
| 91 | const std::string& interface_name); |
| 92 | |
Lingqi Chi | 897e7ec | 2023-04-28 05:50:59 | [diff] [blame] | 93 | static PrerenderCancellationReason BuildForLoadingError(int32_t error_code); |
| 94 | |
Miina Koyama | d0e41f3 | 2023-11-13 06:50:09 | [diff] [blame] | 95 | static PrerenderCancellationReason |
| 96 | CreateCandidateReasonForActivationParameterMismatch(); |
Lingqi Chi | 8e192ba | 2022-11-22 04:34:25 | [diff] [blame] | 97 | |
| 98 | PrerenderCancellationReason(PrerenderCancellationReason&& reason); |
| 99 | |
Lingqi Chi | 20b3fd84 | 2022-11-24 05:29:11 | [diff] [blame] | 100 | // Reports UMA and UKM metrics. |
Lingqi Chi | 74633466 | 2024-06-04 01:11:22 | [diff] [blame] | 101 | void ReportMetrics(const std::string& histogram_suffix) const; |
Lingqi Chi | 8e192ba | 2022-11-22 04:34:25 | [diff] [blame] | 102 | |
| 103 | PrerenderFinalStatus final_status() const { return final_status_; } |
| 104 | |
keno | e16970c | 2023-06-26 10:59:29 | [diff] [blame] | 105 | // Returns disallowed Mojo interface name iff final status is |
| 106 | // `kMojoBinderPolicy`. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 107 | std::optional<std::string> DisallowedMojoInterface() const; |
Lingqi Chi | 20b3fd84 | 2022-11-24 05:29:11 | [diff] [blame] | 108 | |
Miina Koyama | d0e41f3 | 2023-11-13 06:50:09 | [diff] [blame] | 109 | // Returns the pointer of the vector of PrerenderMismatchedHeaders iff |
| 110 | // header mismatch occurred. |
| 111 | const std::vector<PrerenderMismatchedHeaders>* GetPrerenderMismatchedHeaders() |
| 112 | const; |
| 113 | |
| 114 | void SetPrerenderMismatchedHeaders( |
| 115 | std::unique_ptr<std::vector<PrerenderMismatchedHeaders>> |
| 116 | mismatched_headers); |
Miina Koyama | 89b81504 | 2023-10-31 08:20:12 | [diff] [blame] | 117 | |
Lingqi Chi | 8e192ba | 2022-11-22 04:34:25 | [diff] [blame] | 118 | private: |
| 119 | PrerenderCancellationReason(PrerenderFinalStatus final_status, |
| 120 | DetailedReasonVariant explanation); |
| 121 | |
| 122 | const PrerenderFinalStatus final_status_; |
| 123 | |
Miina Koyama | 89b81504 | 2023-10-31 08:20:12 | [diff] [blame] | 124 | DetailedReasonVariant explanation_; |
Lingqi Chi | 8e192ba | 2022-11-22 04:34:25 | [diff] [blame] | 125 | }; |
| 126 | |
Lingqi Chi | c7fe224 | 2022-08-26 10:35:36 | [diff] [blame] | 127 | // Used by PrerenderNavigationThrottle. This is a breakdown enum for |
| 128 | // PrerenderCrossOriginRedirectionMismatch.kSchemePortMismatch. |
| 129 | // These values are persisted to logs. Entries should not be renumbered and |
| 130 | // numeric values should never be reused. |
| 131 | enum class PrerenderCrossOriginRedirectionProtocolChange { |
| 132 | kHttpProtocolUpgrade = 0, |
| 133 | kHttpProtocolDowngrade = 1, |
| 134 | kMaxValue = kHttpProtocolDowngrade |
| 135 | }; |
| 136 | |
Lingqi Chi | 2a7b3c4 | 2024-05-31 03:50:06 | [diff] [blame] | 137 | std::string GeneratePrerenderHistogramSuffix( |
| 138 | PreloadingTriggerType trigger_type, |
| 139 | const std::string& embedder_suffix); |
| 140 | |
Robert Lin | d75062bf | 2021-10-28 12:50:55 | [diff] [blame] | 141 | void RecordPrerenderTriggered(ukm::SourceId ukm_id); |
Kunihiko Sakamoto | 73d0a90 | 2021-07-15 00:22:32 | [diff] [blame] | 142 | |
Asami Doi | 0240627 | 2021-11-12 05:01:44 | [diff] [blame] | 143 | void RecordPrerenderActivationTime( |
| 144 | base::TimeDelta delta, |
Kouhei Ueno | 3f37992b | 2023-11-09 23:29:02 | [diff] [blame] | 145 | PreloadingTriggerType trigger_type, |
Asami Doi | 0240627 | 2021-11-12 05:01:44 | [diff] [blame] | 146 | const std::string& embedder_histogram_suffix); |
| 147 | |
Lingqi Chi | 20b3fd84 | 2022-11-24 05:29:11 | [diff] [blame] | 148 | // Used by failing prerender attempts. Records the status to UMA and UKM, and |
| 149 | // reports the failing reason to devtools. In the attributes, `initiator_ukm_id` |
| 150 | // represents the page that starts prerendering. |
| 151 | void RecordFailedPrerenderFinalStatus( |
| 152 | const PrerenderCancellationReason& cancellation_reason, |
| 153 | const PrerenderAttributes& attributes); |
| 154 | |
| 155 | // Records a success activation to UMA and UKM. |
| 156 | // `prerendered_ukm_id` is the UKM ID of the activated page. |
| 157 | void ReportSuccessActivation(const PrerenderAttributes& attributes, |
| 158 | ukm::SourceId prerendered_ukm_id); |
Asami Doi | 4584b3b | 2021-12-13 04:17:14 | [diff] [blame] | 159 | |
Yoshiki Tanioka | ab74ea5 | 2022-08-17 02:09:17 | [diff] [blame] | 160 | // Records which navigation parameters are different between activation and |
| 161 | // initial prerender navigation when activation fails. |
| 162 | void RecordPrerenderActivationNavigationParamsMatch( |
| 163 | PrerenderHost::ActivationNavigationParamsMatch result, |
Lingqi Chi | 74633466 | 2024-06-04 01:11:22 | [diff] [blame] | 164 | const std::string& histogram_suffix); |
Yoshiki Tanioka | ab74ea5 | 2022-08-17 02:09:17 | [diff] [blame] | 165 | |
Lingqi Chi | c7fe224 | 2022-08-26 10:35:36 | [diff] [blame] | 166 | // Records the detailed types of the cross-origin redirection, e.g., changes to |
| 167 | // scheme, host name etc. |
| 168 | void RecordPrerenderRedirectionMismatchType( |
| 169 | PrerenderCrossOriginRedirectionMismatch case_type, |
Lingqi Chi | 74633466 | 2024-06-04 01:11:22 | [diff] [blame] | 170 | const std::string& histogram_suffix); |
Lingqi Chi | c7fe224 | 2022-08-26 10:35:36 | [diff] [blame] | 171 | |
| 172 | // Records whether the redirection was caused by HTTP protocol upgrade. |
| 173 | void RecordPrerenderRedirectionProtocolChange( |
| 174 | PrerenderCrossOriginRedirectionProtocolChange change_type, |
Lingqi Chi | 74633466 | 2024-06-04 01:11:22 | [diff] [blame] | 175 | const std::string& histogram_suffix); |
Lingqi Chi | c7fe224 | 2022-08-26 10:35:36 | [diff] [blame] | 176 | |
Hiroki Nakagawa | 9c5bc50 | 2023-05-01 23:27:22 | [diff] [blame] | 177 | // Records ui::PageTransition of prerender activation navigation when transition |
| 178 | // mismatch happens on prerender activation. |
| 179 | void RecordPrerenderActivationTransition( |
| 180 | int32_t potential_activation_transition, |
Lingqi Chi | 74633466 | 2024-06-04 01:11:22 | [diff] [blame] | 181 | const std::string& histogram_suffix); |
Hiroki Nakagawa | 9c5bc50 | 2023-05-01 23:27:22 | [diff] [blame] | 182 | |
Domenic Denicola | 31e7eb7 | 2024-05-31 05:20:50 | [diff] [blame] | 183 | // If you change this, please follow the process in |
| 184 | // go/preloading-dashboard-updates to update the mapping reflected in dashboard, |
| 185 | // or if you are not a Googler, please file an FYI bug on https://crbug.new with |
| 186 | // component Internals>Preload. |
| 187 | // |
Kevin McNee | 097680d | 2023-04-05 22:14:51 | [diff] [blame] | 188 | // These values are persisted to logs. Entries should not be renumbered and |
| 189 | // numeric values should never be reused. |
| 190 | // These are also mapped onto the second content internal range of |
| 191 | // `PreloadingEligibility`. |
Domenic Denicola | 31e7eb7 | 2024-05-31 05:20:50 | [diff] [blame] | 192 | // |
| 193 | // LINT.IfChange |
Kevin McNee | 097680d | 2023-04-05 22:14:51 | [diff] [blame] | 194 | enum class PrerenderBackNavigationEligibility { |
| 195 | kEligible = 0, |
| 196 | |
| 197 | kNoBackEntry = 1, |
| 198 | kTargetIsSameDocument = 2, |
| 199 | kMethodNotGet = 3, |
| 200 | kTargetIsFailedNavigation = 4, |
| 201 | kBfcacheEntryExists = 5, |
| 202 | kTargetIsSameSite = 6, |
| 203 | kNoHttpCacheEntry = 7, |
| 204 | kTargetingOtherWindow = 8, |
| 205 | kTargetIsNonHttp = 9, |
Kevin McNee | 8bad63f | 2023-08-23 21:19:37 | [diff] [blame] | 206 | kRelatedActiveContents = 10, |
Kevin McNee | 097680d | 2023-04-05 22:14:51 | [diff] [blame] | 207 | |
Kevin McNee | 8bad63f | 2023-08-23 21:19:37 | [diff] [blame] | 208 | kMaxValue = kRelatedActiveContents, |
Kevin McNee | 097680d | 2023-04-05 22:14:51 | [diff] [blame] | 209 | }; |
Domenic Denicola | 31e7eb7 | 2024-05-31 05:20:50 | [diff] [blame] | 210 | // LINT.ThenChange() |
Kevin McNee | 097680d | 2023-04-05 22:14:51 | [diff] [blame] | 211 | |
| 212 | // Maps `eligibility` onto a content internal range of PreloadingEligibility. |
| 213 | CONTENT_EXPORT PreloadingEligibility |
| 214 | ToPreloadingEligibility(PrerenderBackNavigationEligibility eligibility); |
| 215 | |
| 216 | void RecordPrerenderBackNavigationEligibility( |
| 217 | PreloadingPredictor predictor, |
| 218 | PrerenderBackNavigationEligibility eligibility, |
| 219 | PreloadingAttempt* preloading_attempt); |
| 220 | |
Hiroki Nakagawa | 938494a | 2023-05-30 03:21:10 | [diff] [blame] | 221 | void RecordPrerenderActivationCommitDeferTime( |
| 222 | base::TimeDelta time_delta, |
Kouhei Ueno | 3f37992b | 2023-11-09 23:29:02 | [diff] [blame] | 223 | PreloadingTriggerType trigger_type, |
Hiroki Nakagawa | 938494a | 2023-05-30 03:21:10 | [diff] [blame] | 224 | const std::string& embedder_histogram_suffix); |
| 225 | |
Taiyo Mizuhashi | 5470a52 | 2023-08-21 05:05:56 | [diff] [blame] | 226 | void RecordReceivedPrerendersPerPrimaryPageChangedCount( |
| 227 | int number, |
Kouhei Ueno | 3f37992b | 2023-11-09 23:29:02 | [diff] [blame] | 228 | PreloadingTriggerType trigger_type, |
Taiyo Mizuhashi | 5470a52 | 2023-08-21 05:05:56 | [diff] [blame] | 229 | const std::string& eagerness_category); |
| 230 | |
Lingqi Chi | fc4b7d9c | 2021-04-08 01:41:22 | [diff] [blame] | 231 | } // namespace content |
| 232 | |
Sreeja Kamishetty | c227f7a | 2022-07-08 22:33:15 | [diff] [blame] | 233 | #endif // CONTENT_BROWSER_PRELOADING_PRERENDER_PRERENDER_METRICS_H_ |