#include "chrome/browser/page_load_metrics/observers/core/amp_page_load_metrics_observer.h"
#include <algorithm>
#include <optional>
#include <string>
#include <string_view>
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "components/page_load_metrics/browser/observers/core/largest_contentful_paint_handler.h"
#include "components/page_load_metrics/browser/page_load_metrics_observer_delegate.h"
#include "components/page_load_metrics/browser/page_load_metrics_util.h"
#include "components/page_load_metrics/common/page_load_timing.h"
#include "components/page_load_metrics/common/page_visit_final_status.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "net/base/url_util.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "third_party/blink/public/common/features.h"
#include "url/gurl.h"
namespace {
const char kHistogramPrefix[] = …;
const char kHistogramAMPSubframeNavigationToInput[] = …;
const char kHistogramAMPSubframeInputToNavigation[] = …;
const char kHistogramAMPSubframeMainFrameToSubFrameNavigation[] = …;
const char kHistogramAMPSubframeFirstContentfulPaint[] = …;
const char kHistogramAMPSubframeFirstContentfulPaintFullNavigation[] = …;
const char kHistogramAMPSubframeLargestContentfulPaint[] = …;
const char kHistogramAMPSubframeLargestContentfulPaintFullNavigation[] = …;
const char kHistogramAMPSubframeFirstInputDelay[] = …;
const char kHistogramAMPSubframeFirstInputDelayFullNavigation[] = …;
const char kHistogramAMPSubframeNumInteractions[] = …;
const char
kHistogramAMPSubframeUserInteractionHighPercentile2MaxEventDuration[] = …;
const char kHistogramAMPSubframeWorstUserInteractionLatencyMaxEventDuration[] = …;
GURL GetCanonicalizedSameDocumentUrl(const GURL& url) { … }
bool IsLikelyAmpCacheUrl(const GURL& url) { … }
GURL GetViewerUrlFromCacheUrl(const GURL& url) { … }
base::TimeDelta ClampToZero(base::TimeDelta t) { … }
}
bool IsInPrerenderingBeforeActivation(
const page_load_metrics::PageLoadMetricsObserverDelegate& delegate) { … }
AMPPageLoadMetricsObserver::AMPPageLoadMetricsObserver() { … }
AMPPageLoadMetricsObserver::~AMPPageLoadMetricsObserver() { … }
AMPPageLoadMetricsObserver::SubFrameInfo::SubFrameInfo() = default;
AMPPageLoadMetricsObserver::SubFrameInfo::~SubFrameInfo() = default;
const char* AMPPageLoadMetricsObserver::GetObserverName() const { … }
page_load_metrics::PageLoadMetricsObserver::ObservePolicy
AMPPageLoadMetricsObserver::OnFencedFramesStart(
content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url) { … }
page_load_metrics::PageLoadMetricsObserver::ObservePolicy
AMPPageLoadMetricsObserver::OnPrerenderStart(
content::NavigationHandle* navigation_handle,
const GURL& currently_committed_url) { … }
page_load_metrics::PageLoadMetricsObserver::ObservePolicy
AMPPageLoadMetricsObserver::OnCommit(
content::NavigationHandle* navigation_handle) { … }
void AMPPageLoadMetricsObserver::DidActivatePrerenderedPage(
content::NavigationHandle* navigation_handle) { … }
void AMPPageLoadMetricsObserver::OnCommitSameDocumentNavigation(
content::NavigationHandle* navigation_handle) { … }
void AMPPageLoadMetricsObserver::OnDidFinishSubFrameNavigation(
content::NavigationHandle* navigation_handle) { … }
void AMPPageLoadMetricsObserver::OnRenderFrameDeleted(
content::RenderFrameHost* rfh) { … }
void AMPPageLoadMetricsObserver::OnTimingUpdate(
content::RenderFrameHost* subframe_rfh,
const page_load_metrics::mojom::PageLoadTiming& timing) { … }
void AMPPageLoadMetricsObserver::OnInputTimingUpdate(
content::RenderFrameHost* subframe_rfh,
const page_load_metrics::mojom::InputTiming& input_timing_delta) { … }
void AMPPageLoadMetricsObserver::OnSubFrameRenderDataUpdate(
content::RenderFrameHost* subframe_rfh,
const page_load_metrics::mojom::FrameRenderDataUpdate& render_data) { … }
void AMPPageLoadMetricsObserver::OnComplete(
const page_load_metrics::mojom::PageLoadTiming& timing) { … }
void AMPPageLoadMetricsObserver::ProcessMainFrameNavigation(
content::NavigationHandle* navigation_handle) { … }
void AMPPageLoadMetricsObserver::OnLoadingBehaviorObserved(
content::RenderFrameHost* subframe_rfh,
int behavior_flags) { … }
void AMPPageLoadMetricsObserver::MaybeRecordLoadingBehaviorObserved() { … }
void AMPPageLoadMetricsObserver::MaybeRecordAmpDocumentMetrics() { … }
void AMPPageLoadMetricsObserver::RecordNormalizedResponsivenessMetrics(
const page_load_metrics::ResponsivenessMetricsNormalization&
responsiveness_metrics_normalization,
ukm::builders::AmpPageLoad& builder) { … }