1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74

content / public / browser / prefetch_metrics.h [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_PUBLIC_BROWSER_PREFETCH_METRICS_H_
#define CONTENT_PUBLIC_BROWSER_PREFETCH_METRICS_H_

#include <optional>

#include "base/time/time.h"
#include "content/common/content_export.h"

namespace content {

class NavigationHandle;
class RenderFrameHost;

// Holds metrics related to the prefetches requested by a page load.
struct CONTENT_EXPORT PrefetchReferringPageMetrics {
  static std::optional<PrefetchReferringPageMetrics> GetForCurrentDocument(
      RenderFrameHost* rfh);

  PrefetchReferringPageMetrics() = default;
  ~PrefetchReferringPageMetrics() = default;

  PrefetchReferringPageMetrics(const PrefetchReferringPageMetrics&) = default;
  PrefetchReferringPageMetrics& operator=(const PrefetchReferringPageMetrics&) =
      default;

  // The number of prefetches that were attempted by this page.
  int prefetch_attempted_count = 0;

  // The number of prefetches that were determined to be eligible.
  int prefetch_eligible_count = 0;

  // The number of prefetches that completed successfully.
  int prefetch_successful_count = 0;
};

// Holds metrics related to page loads that may benefit from prefetches
// triggered by speculation rules.
struct CONTENT_EXPORT PrefetchServingPageMetrics {
  static std::optional<PrefetchServingPageMetrics> GetForNavigationHandle(
      NavigationHandle& navigation_handle);

  PrefetchServingPageMetrics() = default;
  ~PrefetchServingPageMetrics() = default;

  PrefetchServingPageMetrics(const PrefetchServingPageMetrics&) = default;
  PrefetchServingPageMetrics& operator=(const PrefetchServingPageMetrics&) =
      default;

  // The |PrefetchStatus| of the prefetch used when serving this page.
  std::optional<int> prefetch_status;

  // Whether or not the prefetch required the use of a private prefetch proxy.
  bool required_private_prefetch_proxy = false;

  // Whether or not this page load is in the same WebContents as the page the
  // requested the page load.
  bool same_tab_as_prefetching_tab = false;

  // The time between the prefetch request was sent and the time the response
  // headers were received.
  std::optional<base::TimeDelta> prefetch_header_latency;

  // The amount of time it took to get the result of the probe. Only set if
  // the probe result was checked.
  std::optional<base::TimeDelta> probe_latency;
};

}  // namespace content

#endif  // CONTENT_PUBLIC_BROWSER_PREFETCH_METRICS_H_