chromium/chrome/browser/page_load_metrics/observers/core/amp_page_load_metrics_observer.h

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

#ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_CORE_AMP_PAGE_LOAD_METRICS_OBSERVER_H_
#define CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_CORE_AMP_PAGE_LOAD_METRICS_OBSERVER_H_

#include <map>
#include <memory>

#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "components/page_load_metrics/browser/layout_shift_normalization.h"
#include "components/page_load_metrics/browser/page_load_metrics_observer.h"
#include "components/page_load_metrics/browser/responsiveness_metrics_normalization.h"
#include "services/metrics/public/cpp/ukm_source.h"

namespace content {
class NavigationHandle;
}
namespace ukm {
namespace builders {
class AmpPageLoad;
}  // namespace builders
}  // namespace ukm

// Observer responsible for recording metrics for AMP documents. This includes
// both AMP documents loaded in the main frame, and AMP documents loaded in a
// subframe (e.g. in an AMP viewer in the main frame).
//
// For AMP documents loaded in a subframe, recording works like so:
//
// * whenever the main frame URL gets updated with an AMP viewer
//   URL (e.g. https://www.google.com/amp/...), we track that in
//   OnCommitSameDocumentNavigation. we use the time of the main
//   frame URL update as the baseline time from which the
//   user-perceived performance metrics like FCP are computed.
//
// * whenever an iframe AMP document is loaded, we track that in
//   OnDidFinishSubFrameNavigation. we also keep track of the
//   performance timing metrics such as FCP reported in the frame.
//
// * we associate the main frame AMP navigation with its associated
//   AMP document in an iframe by comparing URLs between the main
//   frame and the iframe documents.
//
// * we record AMP metrics at the times when an AMP viewer URL is
//   navigated away from. when a user swipes to change the AMP
//   document, closes a tab, types a new URL in the URL bar, etc,
//   we will record AMP metrics for the AMP doc in an iframe that
//   the user is navigating away from.
class AMPPageLoadMetricsObserver
    : public page_load_metrics::PageLoadMetricsObserver {};

#endif  // CHROME_BROWSER_PAGE_LOAD_METRICS_OBSERVERS_CORE_AMP_PAGE_LOAD_METRICS_OBSERVER_H_