Commit b1f32d9e authored by Liquan(Max) Gu's avatar Liquan(Max) Gu Committed by Commit Bot

[LCP] Browser: reuse LCP-handler for main-frame-LCP

As we already have LCP-handler since this CL
https://chromium-review.googlesource.com/c/chromium/src/+/1500254,
the main-frame-LCP can benefit from it by reusing the
LCP-handler's functions.

Bug: 940587

Change-Id: I24d2fbb6d11a50c114d767c4c87c048aaea4c167
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1517162Reviewed-by: default avatarBryan McQuade <bmcquade@chromium.org>
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686543}
parent 5ac87529
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <memory> #include <memory>
#include <utility> #include <utility>
...@@ -46,7 +47,8 @@ PageLoadType GetPageLoadType(ui::PageTransition transition) { ...@@ -46,7 +47,8 @@ PageLoadType GetPageLoadType(ui::PageTransition transition) {
void RecordFirstMeaningfulPaintStatus( void RecordFirstMeaningfulPaintStatus(
internal::FirstMeaningfulPaintStatus status) { internal::FirstMeaningfulPaintStatus status) {
UMA_HISTOGRAM_ENUMERATION(internal::kHistogramFirstMeaningfulPaintStatus, UMA_HISTOGRAM_ENUMERATION(internal::kHistogramFirstMeaningfulPaintStatus,
status, internal::FIRST_MEANINGFUL_PAINT_LAST_ENTRY); status,
internal::FIRST_MEANINGFUL_PAINT_LAST_ENTRY);
} }
void RecordTimeToInteractiveStatus(internal::TimeToInteractiveStatus status) { void RecordTimeToInteractiveStatus(internal::TimeToInteractiveStatus status) {
...@@ -797,41 +799,50 @@ void CorePageLoadMetricsObserver::RecordTimingHistograms( ...@@ -797,41 +799,50 @@ void CorePageLoadMetricsObserver::RecordTimingHistograms(
info.first_foreground_time.value()); info.first_foreground_time.value());
} }
if (WasStartedInForegroundOptionalEventInForeground( const page_load_metrics::ContentfulPaintTimingInfo&
main_frame_timing.paint_timing->largest_image_paint, info)) { main_frame_largest_image_paint =
PAGE_LOAD_HISTOGRAM( largest_contentful_paint_handler_.MainFrameLargestImagePaint();
internal::kHistogramLargestImagePaint, if (!main_frame_largest_image_paint.IsEmpty() &&
main_frame_timing.paint_timing->largest_image_paint.value()); WasStartedInForegroundOptionalEventInForeground(
main_frame_largest_image_paint.Time(), info)) {
PAGE_LOAD_HISTOGRAM(internal::kHistogramLargestImagePaint,
main_frame_largest_image_paint.Time().value());
} }
if (WasStartedInForegroundOptionalEventInForeground(
main_frame_timing.paint_timing->largest_text_paint, info)) { const page_load_metrics::ContentfulPaintTimingInfo&
PAGE_LOAD_HISTOGRAM( main_frame_largest_text_paint =
internal::kHistogramLargestTextPaint, largest_contentful_paint_handler_.MainFrameLargestTextPaint();
main_frame_timing.paint_timing->largest_text_paint.value()); if (!main_frame_largest_text_paint.IsEmpty() &&
}
base::Optional<base::TimeDelta> largest_content_paint_time;
uint64_t largest_content_paint_size;
PageLoadMetricsObserver::LargestContentType largest_content_type;
if (AssignTimeAndSizeForLargestContentfulPaint(
main_frame_timing.paint_timing, &largest_content_paint_time,
&largest_content_paint_size, &largest_content_type) &&
WasStartedInForegroundOptionalEventInForeground( WasStartedInForegroundOptionalEventInForeground(
largest_content_paint_time, info)) { main_frame_largest_text_paint.Time(), info)) {
PAGE_LOAD_HISTOGRAM(internal::kHistogramLargestTextPaint,
main_frame_largest_text_paint.Time().value());
}
const page_load_metrics::ContentfulPaintTimingInfo&
main_frame_largest_contentful_paint =
largest_contentful_paint_handler_.MainFrameLargestContentfulPaint();
if (!main_frame_largest_contentful_paint.IsEmpty() &&
WasStartedInForegroundOptionalEventInForeground(
main_frame_largest_contentful_paint.Time(), info)) {
PAGE_LOAD_HISTOGRAM(internal::kHistogramLargestContentfulPaintMainFrame, PAGE_LOAD_HISTOGRAM(internal::kHistogramLargestContentfulPaintMainFrame,
largest_content_paint_time.value()); main_frame_largest_contentful_paint.Time().value());
UMA_HISTOGRAM_ENUMERATION( UMA_HISTOGRAM_ENUMERATION(
internal::kHistogramLargestContentfulPaintMainFrameContentType, internal::kHistogramLargestContentfulPaintMainFrameContentType,
largest_content_type); main_frame_largest_contentful_paint.Type());
} }
const page_load_metrics::ContentfulPaintTimingInfo& paint = const page_load_metrics::ContentfulPaintTimingInfo&
largest_contentful_paint_handler_.MergeMainFrameAndSubframes(); all_frames_largest_contentful_paint =
if (!paint.IsEmpty() && largest_contentful_paint_handler_.MergeMainFrameAndSubframes();
WasStartedInForegroundOptionalEventInForeground(paint.Time(), info)) { if (!all_frames_largest_contentful_paint.IsEmpty() &&
WasStartedInForegroundOptionalEventInForeground(
all_frames_largest_contentful_paint.Time(), info)) {
PAGE_LOAD_HISTOGRAM(internal::kHistogramLargestContentfulPaint, PAGE_LOAD_HISTOGRAM(internal::kHistogramLargestContentfulPaint,
paint.Time().value()); all_frames_largest_contentful_paint.Time().value());
UMA_HISTOGRAM_ENUMERATION( UMA_HISTOGRAM_ENUMERATION(
internal::kHistogramLargestContentfulPaintContentType, paint.Type()); internal::kHistogramLargestContentfulPaintContentType,
all_frames_largest_contentful_paint.Type());
} }
if (main_frame_timing.paint_timing->first_paint && if (main_frame_timing.paint_timing->first_paint &&
......
...@@ -78,6 +78,21 @@ class LargestContentfulPaintHandler { ...@@ -78,6 +78,21 @@ class LargestContentfulPaintHandler {
return main_frame_tree_node_id_.value(); return main_frame_tree_node_id_.value();
} }
// We merge the candidates from text side and image side to get the largest
// candidate across both types of content.
const ContentfulPaintTimingInfo& MainFrameLargestContentfulPaint() {
return main_frame_contentful_paint_.MergeTextAndImageTiming();
}
const ContentfulPaintTimingInfo& SubframesLargestContentfulPaint() {
return subframe_contentful_paint_.MergeTextAndImageTiming();
}
const ContentfulPaintTimingInfo& MainFrameLargestImagePaint() {
return main_frame_contentful_paint_.Image();
}
const ContentfulPaintTimingInfo& MainFrameLargestTextPaint() {
return main_frame_contentful_paint_.Text();
}
// We merge the candidates from main frame and subframe to get the largest // We merge the candidates from main frame and subframe to get the largest
// candidate across all frames. // candidate across all frames.
const ContentfulPaintTimingInfo& MergeMainFrameAndSubframes(); const ContentfulPaintTimingInfo& MergeMainFrameAndSubframes();
......
...@@ -298,35 +298,41 @@ void UkmPageLoadMetricsObserver::RecordTimingMetrics( ...@@ -298,35 +298,41 @@ void UkmPageLoadMetricsObserver::RecordTimingMetrics(
builder.SetExperimental_PaintTiming_NavigationToFirstMeaningfulPaint( builder.SetExperimental_PaintTiming_NavigationToFirstMeaningfulPaint(
timing.paint_timing->first_meaningful_paint.value().InMilliseconds()); timing.paint_timing->first_meaningful_paint.value().InMilliseconds());
} }
if (timing.paint_timing->largest_image_paint.has_value() && const page_load_metrics::ContentfulPaintTimingInfo&
main_frame_largest_image_paint =
largest_contentful_paint_handler_.MainFrameLargestImagePaint();
if (!main_frame_largest_image_paint.IsEmpty() &&
WasStartedInForegroundOptionalEventInForeground( WasStartedInForegroundOptionalEventInForeground(
timing.paint_timing->largest_image_paint, info)) { main_frame_largest_image_paint.Time(), info)) {
builder.SetExperimental_PaintTiming_NavigationToLargestImagePaint( builder.SetExperimental_PaintTiming_NavigationToLargestImagePaint(
timing.paint_timing->largest_image_paint.value().InMilliseconds()); timing.paint_timing->largest_image_paint.value().InMilliseconds());
} }
if (timing.paint_timing->largest_text_paint.has_value() && const page_load_metrics::ContentfulPaintTimingInfo&
main_frame_largest_text_paint =
largest_contentful_paint_handler_.MainFrameLargestTextPaint();
if (!main_frame_largest_text_paint.IsEmpty() &&
WasStartedInForegroundOptionalEventInForeground( WasStartedInForegroundOptionalEventInForeground(
timing.paint_timing->largest_text_paint, info)) { main_frame_largest_text_paint.Time(), info)) {
builder.SetExperimental_PaintTiming_NavigationToLargestTextPaint( builder.SetExperimental_PaintTiming_NavigationToLargestTextPaint(
timing.paint_timing->largest_text_paint.value().InMilliseconds()); timing.paint_timing->largest_text_paint.value().InMilliseconds());
} }
base::Optional<base::TimeDelta> largest_content_paint_time; const page_load_metrics::ContentfulPaintTimingInfo&
uint64_t largest_content_paint_size; main_frame_largest_contentful_paint =
PageLoadMetricsObserver::LargestContentType largest_content_type; largest_contentful_paint_handler_.MainFrameLargestContentfulPaint();
if (AssignTimeAndSizeForLargestContentfulPaint( if (!main_frame_largest_contentful_paint.IsEmpty() &&
timing.paint_timing, &largest_content_paint_time,
&largest_content_paint_size, &largest_content_type) &&
WasStartedInForegroundOptionalEventInForeground( WasStartedInForegroundOptionalEventInForeground(
largest_content_paint_time, info)) { main_frame_largest_contentful_paint.Time(), info)) {
builder.SetPaintTiming_NavigationToLargestContentfulPaint_MainFrame( builder.SetPaintTiming_NavigationToLargestContentfulPaint_MainFrame(
largest_content_paint_time.value().InMilliseconds()); main_frame_largest_contentful_paint.Time().value().InMilliseconds());
} }
const page_load_metrics::ContentfulPaintTimingInfo& paint = const page_load_metrics::ContentfulPaintTimingInfo&
largest_contentful_paint_handler_.MergeMainFrameAndSubframes(); all_frames_largest_contentful_paint =
if (!paint.IsEmpty() && largest_contentful_paint_handler_.MergeMainFrameAndSubframes();
WasStartedInForegroundOptionalEventInForeground(paint.Time(), info)) { if (!all_frames_largest_contentful_paint.IsEmpty() &&
WasStartedInForegroundOptionalEventInForeground(
all_frames_largest_contentful_paint.Time(), info)) {
builder.SetPaintTiming_NavigationToLargestContentfulPaint( builder.SetPaintTiming_NavigationToLargestContentfulPaint(
paint.Time().value().InMilliseconds()); all_frames_largest_contentful_paint.Time().value().InMilliseconds());
} }
if (timing.interactive_timing->interactive) { if (timing.interactive_timing->interactive) {
base::TimeDelta time_to_interactive = base::TimeDelta time_to_interactive =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment