blob: f2cdd742a83dd7781f503acd38f4df0f023ef753 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2022 The Chromium Authors
Max Curran210cffa2022-09-06 22:24:312// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/public/browser/prefetch_metrics.h"
6
7#include "content/browser/preloading/prefetch/prefetch_document_manager.h"
8#include "content/browser/preloading/prefetch/prefetch_serving_page_metrics_container.h"
Hiroshige Hayashizaki583b4962025-08-19 18:58:269#include "third_party/blink/public/mojom/tokens/tokens.mojom.h"
Max Curran210cffa2022-09-06 22:24:3110
11namespace content {
12
13// static
Arthur Sonzognic686e8f2024-01-11 08:36:3714std::optional<PrefetchReferringPageMetrics>
Max Curran210cffa2022-09-06 22:24:3115PrefetchReferringPageMetrics::GetForCurrentDocument(RenderFrameHost* rfh) {
16 DCHECK(rfh);
17 PrefetchDocumentManager* prefetch_document_manager =
18 PrefetchDocumentManager::GetForCurrentDocument(rfh);
19 if (!prefetch_document_manager)
Arthur Sonzognic686e8f2024-01-11 08:36:3720 return std::nullopt;
Max Curran210cffa2022-09-06 22:24:3121
22 return prefetch_document_manager->GetReferringPageMetrics();
23}
24
25// static
Arthur Sonzognic686e8f2024-01-11 08:36:3726std::optional<PrefetchServingPageMetrics>
Max Curran210cffa2022-09-06 22:24:3127PrefetchServingPageMetrics::GetForNavigationHandle(
28 NavigationHandle& navigation_handle) {
29 PrefetchServingPageMetricsContainer* prefetch_serving_page_metrics_container =
30 PrefetchServingPageMetricsContainer::GetForNavigationHandle(
31 navigation_handle);
32 if (!prefetch_serving_page_metrics_container)
Arthur Sonzognic686e8f2024-01-11 08:36:3733 return std::nullopt;
Max Curran210cffa2022-09-06 22:24:3134
35 return prefetch_serving_page_metrics_container->GetServingPageMetrics();
36}
37
38} // namespace content