#include "components/page_load_metrics/renderer/page_timing_metrics_sender.h"
#include <utility>
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "components/page_load_metrics/common/page_load_metrics.mojom.h"
#include "components/page_load_metrics/common/page_load_metrics_util.h"
#include "components/page_load_metrics/common/page_load_timing.h"
#include "components/page_load_metrics/renderer/page_timing_sender.h"
#include "components/page_load_metrics/renderer/soft_navigation_metrics_type_converter.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/loader/javascript_framework_detection.mojom-forward.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-shared.h"
#include "third_party/blink/public/mojom/use_counter/use_counter_feature.mojom-shared.h"
#include "ui/gfx/geometry/rect.h"
namespace page_load_metrics {
namespace {
const int kInitialTimerDelayMillis = …;
mojom::UserInteractionType UserInteractionTypeForMojom(
blink::UserInteractionType interaction_type) { … }
bool IsFirstFCP(const mojom::PageLoadTimingPtr& last_timing,
const mojom::PageLoadTimingPtr& new_timing) { … }
bool IsFirstParseStart(const mojom::PageLoadTimingPtr& last_timing,
const mojom::PageLoadTimingPtr& new_timing) { … }
bool IsFirstDCL(const mojom::PageLoadTimingPtr& last_timing,
const mojom::PageLoadTimingPtr& new_timing) { … }
}
PageTimingMetricsSender::PageTimingMetricsSender(
std::unique_ptr<PageTimingSender> sender,
std::unique_ptr<base::OneShotTimer> timer,
mojom::PageLoadTimingPtr initial_timing,
const PageTimingMetadataRecorder::MonotonicTiming& initial_monotonic_timing,
std::unique_ptr<PageResourceDataUse> initial_request,
bool is_main_frame)
: … { … }
PageTimingMetricsSender::~PageTimingMetricsSender() { … }
void PageTimingMetricsSender::DidObserveLoadingBehavior(
blink::LoadingBehaviorFlag behavior) { … }
void PageTimingMetricsSender::DidObserveJavaScriptFrameworks(
const blink::JavaScriptFrameworkDetectionResult& result) { … }
void PageTimingMetricsSender::DidObserveSubresourceLoad(
const blink::SubresourceLoadMetrics& subresource_load_metrics) { … }
void PageTimingMetricsSender::DidObserveNewFeatureUsage(
const blink::UseCounterFeature& feature) { … }
void PageTimingMetricsSender::DidObserveSoftNavigation(
blink::SoftNavigationMetrics new_metrics) { … }
void PageTimingMetricsSender::DidObserveLayoutShift(
double score,
bool after_input_or_scroll) { … }
void PageTimingMetricsSender::DidStartResponse(
const url::SchemeHostPort& final_response_url,
int resource_id,
const network::mojom::URLResponseHead& response_head,
network::mojom::RequestDestination request_destination,
bool is_ad_resource) { … }
void PageTimingMetricsSender::DidReceiveTransferSizeUpdate(
int resource_id,
int received_data_length) { … }
void PageTimingMetricsSender::DidCompleteResponse(
int resource_id,
const network::URLLoaderCompletionStatus& status) { … }
void PageTimingMetricsSender::DidCancelResponse(int resource_id) { … }
void PageTimingMetricsSender::DidLoadResourceFromMemoryCache(
const GURL& response_url,
int request_id,
int64_t encoded_body_length,
const std::string& mime_type) { … }
void PageTimingMetricsSender::OnMainFrameIntersectionChanged(
const gfx::Rect& main_frame_intersection_rect) { … }
void PageTimingMetricsSender::OnMainFrameViewportRectangleChanged(
const gfx::Rect& main_frame_viewport_rect) { … }
void PageTimingMetricsSender::OnMainFrameImageAdRectangleChanged(
int element_id,
const gfx::Rect& image_ad_rect) { … }
void PageTimingMetricsSender::UpdateResourceMetadata(
int resource_id,
bool is_main_frame_resource) { … }
void PageTimingMetricsSender::SetUpSmoothnessReporting(
base::ReadOnlySharedMemoryRegion shared_memory) { … }
void PageTimingMetricsSender::Update(
mojom::PageLoadTimingPtr timing,
const PageTimingMetadataRecorder::MonotonicTiming& monotonic_timing) { … }
void PageTimingMetricsSender::UpdateSoftNavigationMetrics(
mojom::SoftNavigationMetricsPtr soft_navigation_metrics) { … }
void PageTimingMetricsSender::SendCustomUserTimingMark(
mojom::CustomUserTimingMarkPtr custom_timing) { … }
void PageTimingMetricsSender::SendLatest() { … }
void PageTimingMetricsSender::UpdateCpuTiming(base::TimeDelta task_time) { … }
void PageTimingMetricsSender::EnsureSendTimer(bool urgent) { … }
void PageTimingMetricsSender::SendNow() { … }
PageResourceDataUse* PageTimingMetricsSender::FindOrInsertPageResourceDataUse(
int resource_id) { … }
void PageTimingMetricsSender::InitiateUserInteractionTiming() { … }
void PageTimingMetricsSender::DidObserveUserInteraction(
base::TimeTicks max_event_start,
base::TimeTicks max_event_queued_main_thread,
base::TimeTicks max_event_commit_finish,
base::TimeTicks max_event_end,
blink::UserInteractionType interaction_type,
uint64_t interaction_offset) { … }
}