chromium/chrome/browser/page_load_metrics/observers/core/ukm_page_load_metrics_observer.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/page_load_metrics/observers/core/ukm_page_load_metrics_observer.h"

#include <cmath>
#include <memory>
#include <string_view>
#include <vector>

#include "base/feature_list.h"
#include "base/hash/sha1.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/trace_event/common/trace_event_common.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_id_helper.h"
#include "base/trace_event/typed_macros.h"
#include "cc/metrics/ukm_smoothness_data.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/history_clusters/history_clusters_tab_helper.h"
#include "chrome/browser/performance_manager/public/user_tuning/user_tuning_utils.h"
#include "chrome/browser/preloading/prefetch/no_state_prefetch/no_state_prefetch_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/common/pref_names.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/common/features.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/history/core/browser/history_types.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/metrics/metrics_data_validation.h"
#include "components/metrics/net/network_metrics_provider.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_manager.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_utils.h"
#include "components/no_state_prefetch/common/no_state_prefetch_final_status.h"
#include "components/no_state_prefetch/common/no_state_prefetch_origin.h"
#include "components/offline_pages/buildflags/buildflags.h"
#include "components/page_load_metrics/browser/observers/core/largest_contentful_paint_handler.h"
#include "components/page_load_metrics/browser/page_load_metrics_util.h"
#include "components/page_load_metrics/browser/protocol_util.h"
#include "components/page_load_metrics/common/page_visit_final_status.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/template_url_service.h"
#include "components/site_engagement/content/site_engagement_service.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "media/base/mime_util.h"
#include "net/base/load_timing_info.h"
#include "net/cookies/cookie_options.h"
#include "net/http/http_response_headers.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 "services/network/public/cpp/network_quality_tracker.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/mime_util/mime_util.h"
#include "third_party/blink/public/common/performance/largest_contentful_paint_type.h"
#include "third_party/metrics_proto/system_profile.pb.h"
#include "third_party/perfetto/include/perfetto/tracing/track.h"
#include "ui/events/blink/blink_features.h"

#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
#include "chrome/browser/offline_pages/offline_page_tab_helper.h"
#endif

PageVisitFinalStatus;

namespace {

const char kOfflinePreviewsMimeType[] =;

static constexpr uint64_t kInstantPageLoadEventsTraceTrackId =;

const char kHistogramSoftNavigationCount[] =;

template <size_t N>
uint64_t PackBytes(base::span<const uint8_t, N> bytes) {}

uint64_t StrToHash64Bit(std::string_view str) {}

bool IsSupportedProtocol(page_load_metrics::NetworkProtocol protocol) {}

bool IsDefaultSearchEngine(content::BrowserContext* browser_context,
                           const GURL& url) {}

bool IsValidSearchURL(content::BrowserContext* browser_context,
                      const GURL& url) {}

bool IsUserHomePage(content::BrowserContext* browser_context, const GURL& url) {}

std::unique_ptr<base::trace_event::TracedValue> CumulativeShiftScoreTraceData(
    float layout_shift_score,
    float layout_shift_score_before_input_or_scroll) {}

int SiteInstanceRenderProcessAssignmentToInt(
    content::SiteInstanceProcessAssignment assignment) {}

// These are the high bounds of each bucket, in enum order. The index into this
// array is cast to an enum value when recording UKM. These should correspond to
// the upper bounds of the BitsPerPixelExponential enum in
// //tools/metrics/histograms/enums.xml.
static const double kLCPEntropyBucketThresholds[] =;

int64_t CalculateLCPEntropyBucket(double bpp) {}

}  // namespace

// static
std::unique_ptr<page_load_metrics::PageLoadMetricsObserver>
UkmPageLoadMetricsObserver::CreateIfNeeded() {}

UkmPageLoadMetricsObserver::UkmPageLoadMetricsObserver(
    network::NetworkQualityTracker* network_quality_tracker)
    :{}

UkmPageLoadMetricsObserver::~UkmPageLoadMetricsObserver() = default;

UkmPageLoadMetricsObserver::ObservePolicy UkmPageLoadMetricsObserver::OnStart(
    content::NavigationHandle* navigation_handle,
    const GURL& currently_committed_url,
    bool started_in_foreground) {}

page_load_metrics::PageLoadMetricsObserver::ObservePolicy
UkmPageLoadMetricsObserver::OnFencedFramesStart(
    content::NavigationHandle* navigation_handle,
    const GURL& currently_committed_url) {}

page_load_metrics::PageLoadMetricsObserver::ObservePolicy
UkmPageLoadMetricsObserver::OnPrerenderStart(
    content::NavigationHandle* navigation_handle,
    const GURL& currently_committed_url) {}

page_load_metrics::PageLoadMetricsObserver::ObservePolicy
UkmPageLoadMetricsObserver::OnRedirect(
    content::NavigationHandle* navigation_handle) {}

void UkmPageLoadMetricsObserver::UpdateMainFrameRequestHadCookie(
    content::BrowserContext* browser_context,
    const GURL& url) {}

void UkmPageLoadMetricsObserver::OnMainFrameRequestHadCookieResult(
    base::Time query_start_time,
    const net::CookieAccessResultList& cookies,
    const net::CookieAccessResultList& excluded_cookies) {}

UkmPageLoadMetricsObserver::ObservePolicy
UkmPageLoadMetricsObserver::ShouldObserveMimeType(
    const std::string& mime_type) const {}

UkmPageLoadMetricsObserver::ObservePolicy UkmPageLoadMetricsObserver::OnCommit(
    content::NavigationHandle* navigation_handle) {}

UkmPageLoadMetricsObserver::ObservePolicy
UkmPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground(
    const page_load_metrics::mojom::PageLoadTiming& timing) {}

UkmPageLoadMetricsObserver::ObservePolicy UkmPageLoadMetricsObserver::OnHidden(
    const page_load_metrics::mojom::PageLoadTiming& timing) {}

UkmPageLoadMetricsObserver::ObservePolicy
UkmPageLoadMetricsObserver::OnShown() {}

void UkmPageLoadMetricsObserver::OnFailedProvisionalLoad(
    const page_load_metrics::FailedProvisionalLoadInfo& failed_load_info) {}

void UkmPageLoadMetricsObserver::OnComplete(
    const page_load_metrics::mojom::PageLoadTiming& timing) {}

void UkmPageLoadMetricsObserver::OnResourceDataUseObserved(
    content::RenderFrameHost* content,
    const std::vector<page_load_metrics::mojom::ResourceDataUpdatePtr>&
        resources) {}

void UkmPageLoadMetricsObserver::OnLoadedResource(
    const page_load_metrics::ExtraRequestCompleteInfo&
        extra_request_complete_info) {}

void UkmPageLoadMetricsObserver::RecordNavigationTimingMetrics() {}

void UkmPageLoadMetricsObserver::OnFirstContentfulPaintInPage(
    const page_load_metrics::mojom::PageLoadTiming& timing) {}

void UkmPageLoadMetricsObserver::RecordSiteEngagement() const {}

void UkmPageLoadMetricsObserver::RecordSoftNavigationMetrics(
    ukm::SourceId ukm_source_id,
    page_load_metrics::mojom::SoftNavigationMetrics& soft_navigation_metrics) {}

void UkmPageLoadMetricsObserver::
    RecordResponsivenessMetricsBeforeSoftNavigationForMainFrame() {}

void UkmPageLoadMetricsObserver::
    RecordLayoutShiftBeforeSoftNavigationForMainFrame() {}

void UkmPageLoadMetricsObserver::OnSoftNavigationUpdated(
    const page_load_metrics::mojom::SoftNavigationMetrics&
        new_soft_navigation_metrics) {}

const page_load_metrics::ContentfulPaintTimingInfo&
UkmPageLoadMetricsObserver::GetSoftNavigationLargestContentfulPaint() const {}

const page_load_metrics::ContentfulPaintTimingInfo&
UkmPageLoadMetricsObserver::GetCoreWebVitalsLcpTimingInfo() {}

void UkmPageLoadMetricsObserver::RecordTimingMetrics(
    const page_load_metrics::mojom::PageLoadTiming& timing) {}

void UkmPageLoadMetricsObserver::RecordInternalTimingMetrics(
    const page_load_metrics::ContentfulPaintTimingInfo&
        all_frames_largest_contentful_paint) {}

void UkmPageLoadMetricsObserver::RecordPageLoadMetrics(
    base::TimeTicks app_background_time) {}

void UkmPageLoadMetricsObserver::RecordRendererUsageMetrics() {}

void UkmPageLoadMetricsObserver::ReportMainResourceTimingMetrics(
    ukm::builders::PageLoad& builder) {}

std::optional<float> UkmPageLoadMetricsObserver::GetCoreWebVitalsCLS() {}

std::optional<float>
UkmPageLoadMetricsObserver::GetCoreWebVitalsSoftNavigationIntervalCLS() {}

void UkmPageLoadMetricsObserver::ReportLayoutStability() {}

void UkmPageLoadMetricsObserver::ReportLayoutInstabilityAfterFirstForeground() {}

void UkmPageLoadMetricsObserver::
    ReportLargestContentfulPaintAfterFirstForeground() {}

void UkmPageLoadMetricsObserver::ReportResponsivenessAfterFirstForeground() {}

void UkmPageLoadMetricsObserver::RecordAbortMetrics(
    const page_load_metrics::mojom::PageLoadTiming& timing,
    base::TimeTicks page_end_time,
    ukm::builders::PageLoad* builder) {}

void UkmPageLoadMetricsObserver::RecordMemoriesMetrics(
    ukm::builders::PageLoad& builder,
    const page_load_metrics::PageEndReason page_end_reason) {}

void UkmPageLoadMetricsObserver::RecordPageLoadTimestampMetrics(
    ukm::builders::PageLoad& builder) {}

void UkmPageLoadMetricsObserver::RecordSmoothnessMetrics() {}

void UkmPageLoadMetricsObserver::RecordPageEndMetrics(
    const page_load_metrics::mojom::PageLoadTiming* timing,
    base::TimeTicks page_end_time,
    bool app_entered_background) {}

std::optional<int64_t>
UkmPageLoadMetricsObserver::GetRoundedSiteEngagementScore() const {}

std::optional<bool>
UkmPageLoadMetricsObserver::GetThirdPartyCookieBlockingEnabled() const {}

void UkmPageLoadMetricsObserver::RecordResponsivenessMetrics() {}

void UkmPageLoadMetricsObserver::OnTimingUpdate(
    content::RenderFrameHost* subframe_rfh,
    const page_load_metrics::mojom::PageLoadTiming& timing) {}

void UkmPageLoadMetricsObserver::SetUpSharedMemoryForSmoothness(
    const base::ReadOnlySharedMemoryRegion& shared_memory) {}

void UkmPageLoadMetricsObserver::OnCpuTimingUpdate(
    content::RenderFrameHost* subframe_rfh,
    const page_load_metrics::mojom::CpuTiming& timing) {}

void UkmPageLoadMetricsObserver::RecordNoStatePrefetchMetrics(
    content::NavigationHandle* navigation_handle,
    ukm::SourceId source_id) {}

bool UkmPageLoadMetricsObserver::IsOfflinePreview(
    content::WebContents* web_contents) const {}

void UkmPageLoadMetricsObserver::RecordGeneratedNavigationUKM(
    ukm::SourceId source_id,
    const GURL& committed_url) {}

void UkmPageLoadMetricsObserver::EmitUserTimingEvent(base::TimeDelta duration,
                                                     const char event_name[]) {}