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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_OBSERVERS_PRERENDER_PAGE_LOAD_METRICS_OBSERVER_H_
#define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_OBSERVERS_PRERENDER_PAGE_LOAD_METRICS_OBSERVER_H_
#include <optional>
#include "base/time/time.h"
#include "components/page_load_metrics/browser/page_load_metrics_observer.h"
#include "content/public/browser/preloading_trigger_type.h"
namespace internal {
extern const char kHistogramPrerenderNavigationToActivation[];
extern const char kHistogramPrerenderActivationToFirstPaint[];
extern const char kHistogramPrerenderActivationToFirstContentfulPaint[];
extern const char kHistogramPrerenderActivationToLargestContentfulPaint2[];
extern const char kHistogramPrerenderFirstInputDelay4[];
extern const char kHistogramPrerenderCumulativeShiftScore[];
extern const char kHistogramPrerenderCumulativeShiftScoreMainFrame[];
extern const char
kHistogramPrerenderMaxCumulativeShiftScoreSessionWindowGap1000msMax5000ms2
[];
// Responsiveness metrics.
extern const char
kHistogramPrerenderAverageUserInteractionLatencyOverBudgetMaxEventDuration
[];
extern const char kHistogramPrerenderNumInteractions[];
extern const char
kHistogramPrerenderUserInteractionLatencyHighPercentile2MaxEventDuration[];
extern const char
kHistogramPrerenderUserInteractionLatencyHighPercentile2MaxEventDurationIncognito
[];
extern const char
kHistogramPrerenderWorstUserInteractionLatencyMaxEventDuration[];
} // namespace internal
namespace page_load_metrics {
struct ExtraRequestCompleteInfo;
} // namespace page_load_metrics
namespace net {
enum Error;
} // namespace net
// Prerender2 (content/browser/preloading/prerender/README.md):
// Records custom page load timing and loading status metrics for prerendered
// page loads.
class PrerenderPageLoadMetricsObserver
: public page_load_metrics::PageLoadMetricsObserver {
public:
explicit PrerenderPageLoadMetricsObserver(bool is_incognito);
~PrerenderPageLoadMetricsObserver() override;
// page_load_metrics::PageLoadMetricsObserver implementation:
ObservePolicy OnStart(content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url,
bool started_in_foreground) override;
ObservePolicy OnFencedFramesStart(
content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url) override;
ObservePolicy OnPrerenderStart(content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url) override;
void DidActivatePrerenderedPage(
content::NavigationHandle* navigation_handle) override;
void OnFirstPaintInPage(
const page_load_metrics::mojom::PageLoadTiming& timing) override;
void OnFirstContentfulPaintInPage(
const page_load_metrics::mojom::PageLoadTiming& timing) override;
void OnFirstInputInPage(
const page_load_metrics::mojom::PageLoadTiming& timing) override;
void OnComplete(
const page_load_metrics::mojom::PageLoadTiming& timing) override;
void OnLoadedResource(const page_load_metrics::ExtraRequestCompleteInfo&
extra_request_complete_info) override;
ObservePolicy FlushMetricsOnAppEnterBackground(
const page_load_metrics::mojom::PageLoadTiming& timing) override;
private:
enum PaintingTimeType : uint8_t;
void RecordSessionEndHistograms(
const page_load_metrics::mojom::PageLoadTiming& main_frame_timing);
// Records Cumulative Layout Shift Score (CLS) to UMA and UKM.
void RecordLayoutShiftScoreMetrics(
const page_load_metrics::mojom::PageLoadTiming& main_frame_timing);
// Records Interaction to Next Paint (INP) to UMA and UKM.
void RecordNormalizedResponsivenessMetrics();
// Records loading status for an activated and loaded page.
void MaybeRecordMainResourceLoadStatus();
void MaybeRecordDocumentLoadMetrics(
const page_load_metrics::mojom::PageLoadTiming& timing);
void EmitPaintingMetricsTraceEvent(PaintingTimeType type,
base::TimeDelta paint_timing) const;
// Helper function to concatenate the histogram name, the trigger type and the
// embedder histogram suffix when the trigger type is kEmbedder.
std::string AppendSuffix(const std::string& histogram_name) const;
// Set to true if the activation navigation main frame resource has a
// 'Cache-control: no-store' response header and set to false otherwise. Not
// set if Chrome did not receive response headers or if the prerendered page
// load was not activated.
std::optional<bool> main_frame_resource_has_no_store_;
// Set when the main resource of the main frame finishes loading.
std::optional<net::Error> main_resource_load_status_;
// Updated upon activation.
std::optional<base::TimeDelta> navigation_to_activation_time_;
// The type to trigger prerendering.
std::optional<content::PreloadingTriggerType> trigger_type_;
// The suffix of a prerender embedder. This value is valid only when
// PreloadingTriggerType is kEmbedder. Otherwise, it's an empty string.
std::string embedder_histogram_suffix_;
// Whether the WebContents being observed is for an Incognito profile.
bool is_incognito_;
};
#endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_OBSERVERS_PRERENDER_PAGE_LOAD_METRICS_OBSERVER_H_
|