Index: chrome/browser/page_load_metrics/observers/session_restore_foreground_tab_page_load_metrics_observer.cc |
diff --git a/chrome/browser/page_load_metrics/observers/session_restore_foreground_tab_page_load_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/session_restore_foreground_tab_page_load_metrics_observer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..194e313e26adb6dd97b51c81ef59687ab7640670 |
--- /dev/null |
+++ b/chrome/browser/page_load_metrics/observers/session_restore_foreground_tab_page_load_metrics_observer.cc |
@@ -0,0 +1,92 @@ |
+// 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_foreground_tab_page_load_metrics_observer.h" |
+ |
+#include "base/metrics/histogram_macros.h" |
+#include "chrome/browser/browser_process.h" |
+ |
+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 |
+ |
+// static |
+std::unique_ptr<SessionRestoreForegroundTabPageLoadMetricsObserver> |
+SessionRestoreForegroundTabPageLoadMetricsObserver::CreateIfNeeded() { |
+ return GetTabManager() && IsSessionRestoreLoadingTabs() && |
+ !HasInitialForegroundTabChanged() |
+ ? base::MakeUnique< |
+ SessionRestoreForegroundTabPageLoadMetricsObserver>() |
+ : nullptr; |
+} |
+ |
+page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
+SessionRestoreForegroundTabPageLoadMetricsObserver::OnStart( |
+ content::NavigationHandle* navigation_handle, |
+ const GURL& currently_committed_url, |
+ bool started_in_foreground) { |
+ return started_in_foreground ? CONTINUE_OBSERVING : STOP_OBSERVING; |
+} |
+ |
+page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
+SessionRestoreForegroundTabPageLoadMetricsObserver::OnHidden( |
+ const page_load_metrics::mojom::PageLoadTiming& timing, |
+ const page_load_metrics::PageLoadExtraInfo& info) { |
+ return STOP_OBSERVING; |
+} |
+ |
+void SessionRestoreForegroundTabPageLoadMetricsObserver::OnFirstPaintInPage( |
+ const page_load_metrics::mojom::PageLoadTiming& timing, |
+ const page_load_metrics::PageLoadExtraInfo& extra_info) { |
+ UMA_HISTOGRAM_TIMES(internal::kHistogramSessionRestoreForegroundTabFirstPaint, |
+ timing.paint_timing->first_paint.value()); |
+} |
+ |
+void SessionRestoreForegroundTabPageLoadMetricsObserver:: |
+ OnFirstContentfulPaintInPage( |
+ const page_load_metrics::mojom::PageLoadTiming& timing, |
+ const page_load_metrics::PageLoadExtraInfo& extra_info) { |
+ UMA_HISTOGRAM_TIMES( |
+ internal::kHistogramSessionRestoreForegroundTabFirstContentfulPaint, |
+ timing.paint_timing->first_contentful_paint.value()); |
+} |
+ |
+void SessionRestoreForegroundTabPageLoadMetricsObserver:: |
+ OnFirstMeaningfulPaintInMainFrameDocument( |
+ const page_load_metrics::mojom::PageLoadTiming& timing, |
+ const page_load_metrics::PageLoadExtraInfo& extra_info) { |
+ UMA_HISTOGRAM_TIMES( |
+ internal::kHistogramSessionRestoreForegroundTabFirstMeaningfulPaint, |
+ timing.paint_timing->first_meaningful_paint.value()); |
+} |
+ |
+// static |
+resource_coordinator::TabManager* |
+SessionRestoreForegroundTabPageLoadMetricsObserver::GetTabManager() { |
+ resource_coordinator::TabManager* tab_manager = |
+ g_browser_process->GetTabManager(); |
+ // tab_manager should not be null because this is used only |
+ // on TabManager-supported platforms |
+ DCHECK(tab_manager); |
+ return tab_manager; |
+} |
+ |
+// static |
+bool SessionRestoreForegroundTabPageLoadMetricsObserver:: |
+ HasInitialForegroundTabChanged() { |
+ return GetTabManager()->HasSessionRestoreInitialForegroundTabChanged(); |
+} |
+ |
+// static |
+bool SessionRestoreForegroundTabPageLoadMetricsObserver:: |
+ IsSessionRestoreLoadingTabs() { |
+ return GetTabManager()->IsSessionRestoreLoadingTabs(); |
+} |