Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Unified Diff: chrome/browser/page_load_metrics/observers/session_restore_page_load_metrics_observer.cc

Issue 2930013005: [Tab Metrics] Measure FP, FCP and FMP for Foreground Tab during Session Restore (Closed)
Patch Set: Refine tests Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/page_load_metrics/observers/session_restore_page_load_metrics_observer.cc
diff --git a/chrome/browser/page_load_metrics/observers/session_restore_page_load_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/session_restore_page_load_metrics_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cd1c1afbca0aa719d56a9d4d0438d105c7a066c1
--- /dev/null
+++ b/chrome/browser/page_load_metrics/observers/session_restore_page_load_metrics_observer.cc
@@ -0,0 +1,80 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/page_load_metrics/observers/session_restore_page_load_metrics_observer.h"
+
+#include <base/debug/stack_trace.h>
Charlie Harrison 2017/08/07 14:30:07 nit: remove stack_trace
ducbui 2017/08/08 16:29:47 Done.
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
Charlie Harrison 2017/08/07 14:30:07 nit: unused.
ducbui 2017/08/08 16:29:47 Done.
+#include "base/metrics/histogram_macros.h"
Charlie Harrison 2017/08/07 14:30:08 nit: unused (you're just using our own custom macr
ducbui 2017/08/08 16:29:47 Done.
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
+#include "chrome/browser/resource_coordinator/tab_manager.h"
+#include "chrome/browser/sessions/session_restore.h"
Charlie Harrison 2017/08/07 14:30:07 nit: is it used?
ducbui 2017/08/08 16:29:47 Acknowledged. It is not used so I will remove it.
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/web_contents.h"
+#include "url/gurl.h"
Charlie Harrison 2017/08/07 14:30:07 nit: unused.
ducbui 2017/08/08 16:29:47 Done.
+
+namespace internal {
+
+const char kHistogramSessionRestoreForegroundTabFirstPaint[] =
+ "TabManager.Experimental.SessionRestore.ForegroundTab.FirstPaint";
+const char kHistogramSessionRestoreForegroundTabFirstContentfulPaint[] =
+ "TabManager.Experimental.SessionRestore.ForegroundTab.FirstContentfulPaint";
+const char kHistogramSessionRestoreForegroundTabFirstMeaningfulPaint[] =
+ "TabManager.Experimental.SessionRestore.ForegroundTab.FirstMeaningfulPaint";
+
+} // namespace internal
+
+SessionRestorePageLoadMetricsObserver::SessionRestorePageLoadMetricsObserver() {
+}
+
+page_load_metrics::PageLoadMetricsObserver::ObservePolicy
+SessionRestorePageLoadMetricsObserver::OnStart(
+ content::NavigationHandle* navigation_handle,
+ const GURL& currently_committed_url,
+ bool started_in_foreground) {
+ content::WebContents* contents = navigation_handle->GetWebContents();
+ resource_coordinator::TabManager* tab_manager =
+ g_browser_process->GetTabManager();
+ // Should not be null because this is used only on supported platforms.
+ DCHECK(tab_manager);
+
+ return (tab_manager->IsTabInSessionRestore(contents) &&
+ tab_manager->IsTabRestoredInForeground(contents) &&
+ started_in_foreground)
+ ? CONTINUE_OBSERVING
+ : STOP_OBSERVING;
+}
+
+page_load_metrics::PageLoadMetricsObserver::ObservePolicy
+SessionRestorePageLoadMetricsObserver::OnHidden(
+ const page_load_metrics::mojom::PageLoadTiming& timing,
+ const page_load_metrics::PageLoadExtraInfo& info) {
+ return STOP_OBSERVING;
Charlie Harrison 2017/08/07 14:30:08 Note: OnHidden() is called immediately when the ta
ducbui 2017/08/08 16:29:47 Thank you for the suggestion! I did not aware of t
Bryan McQuade 2017/08/09 15:41:34 Good point, yes. There are corner case timing issu
+}
+
+void SessionRestorePageLoadMetricsObserver::OnFirstPaintInPage(
+ const page_load_metrics::mojom::PageLoadTiming& timing,
+ const page_load_metrics::PageLoadExtraInfo& extra_info) {
+ PAGE_LOAD_HISTOGRAM(internal::kHistogramSessionRestoreForegroundTabFirstPaint,
+ timing.paint_timing->first_paint.value());
Charlie Harrison 2017/08/07 14:30:08 #include page_load_metrics.mojom.h
ducbui 2017/08/08 16:29:47 Done.
+}
+
+void SessionRestorePageLoadMetricsObserver::OnFirstContentfulPaintInPage(
+ const page_load_metrics::mojom::PageLoadTiming& timing,
+ const page_load_metrics::PageLoadExtraInfo& extra_info) {
+ PAGE_LOAD_HISTOGRAM(
+ internal::kHistogramSessionRestoreForegroundTabFirstContentfulPaint,
+ timing.paint_timing->first_contentful_paint.value());
+}
+
+void SessionRestorePageLoadMetricsObserver::
+ OnFirstMeaningfulPaintInMainFrameDocument(
+ const page_load_metrics::mojom::PageLoadTiming& timing,
+ const page_load_metrics::PageLoadExtraInfo& extra_info) {
+ PAGE_LOAD_HISTOGRAM(
+ internal::kHistogramSessionRestoreForegroundTabFirstMeaningfulPaint,
+ timing.paint_timing->first_meaningful_paint.value());
+}

Powered by Google App Engine
This is Rietveld 408576698