Record main-frame-time-ratio metrics only when in a main frame update

We were recording main frame time metrics even when doing lifecycle
updates for other reasons, which is pointless and skews the numbers.
This plumbs information on the source of the update through necessary
layers.

[email protected]
BUG=896356

Change-Id: I94ec6ec14a6629ec2295b4575e9af7a8fd5b7ead
Reviewed-on: https://chromium-review.googlesource.com/c/1303874
Reviewed-by: Fady Samuel <[email protected]>
Reviewed-by: Tommy Li <[email protected]>
Reviewed-by: Jochen Eisinger <[email protected]>
Reviewed-by: Rick Byers <[email protected]>
Reviewed-by: Philip Rogers <[email protected]>
Reviewed-by: vmpstr <[email protected]>
Commit-Queue: Stephen Chenney <[email protected]>
Cr-Commit-Position: refs/heads/master@{#610014}
diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc
index 3adeac7..ec352c5 100644
--- a/content/renderer/render_widget.cc
+++ b/content/renderer/render_widget.cc
@@ -1051,11 +1051,20 @@
   ScheduleAnimation();
 }
 
-void RenderWidget::UpdateVisualState() {
+void RenderWidget::UpdateVisualState(bool record_main_frame_metrics) {
   if (!GetWebWidget())
     return;
 
-  GetWebWidget()->UpdateLifecycle(WebWidget::LifecycleUpdate::kAll);
+  // When recording main frame metrics set the lifecycle reason to
+  // kBeginMainFrame, because this is the calller of UpdateLifecycle
+  // for the main frame. Otherwise, set the reason to kTests, which is
+  // the oinly other reason this method is called.
+  WebWidget::LifecycleUpdateReason lifecycle_reason =
+      record_main_frame_metrics
+          ? WebWidget::LifecycleUpdateReason::kBeginMainFrame
+          : WebWidget::LifecycleUpdateReason::kTest;
+  GetWebWidget()->UpdateLifecycle(WebWidget::LifecycleUpdate::kAll,
+                                  lifecycle_reason);
   GetWebWidget()->SetSuppressFrameRequestsWorkaroundFor704763Only(false);
 
   if (first_update_visual_state_after_hidden_) {