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

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

Issue 2694183004: Adding TabRestore PLM UMA (Closed)
Patch Set: rebase + comments Created 3 years, 10 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/tab_restore_page_load_metrics_observer.cc
diff --git a/chrome/browser/page_load_metrics/observers/tab_restore_page_load_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/tab_restore_page_load_metrics_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1223f5f5c90bcb184f6eb15b04c07e4cd98657c9
--- /dev/null
+++ b/chrome/browser/page_load_metrics/observers/tab_restore_page_load_metrics_observer.cc
@@ -0,0 +1,85 @@
+// 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/tab_restore_page_load_metrics_observer.h"
+
+#include <string>
+
+#include "base/metrics/histogram_macros.h"
+#include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
+#include "content/public/browser/navigation_controller.h"
+#include "content/public/browser/navigation_entry.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/restore_type.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/base/page_transition_types.h"
+
+namespace {
+
+const char kHistogramNetworkBytes[] =
+ "PageLoad.Clients.TabRestore.Experimental.Bytes.Network";
+const char kHistogramCacheBytes[] =
+ "PageLoad.Clients.TabRestore.Experimental.Bytes.Cache";
+const char kHistogramTotalBytes[] =
+ "PageLoad.Clients.TabRestore.Experimental.Bytes.Total";
+
+} // namespace
+
+TabRestorePageLoadMetricsObserver::TabRestorePageLoadMetricsObserver()
+ : cache_bytes_(0), network_bytes_(0) {}
+
+TabRestorePageLoadMetricsObserver::~TabRestorePageLoadMetricsObserver() {}
+
+page_load_metrics::PageLoadMetricsObserver::ObservePolicy
+TabRestorePageLoadMetricsObserver::OnStart(
+ content::NavigationHandle* navigation_handle,
+ const GURL& currently_committed_url,
+ bool started_in_foreground) {
+ return IsTabRestore(navigation_handle) ? CONTINUE_OBSERVING : STOP_OBSERVING;
+}
+
+void TabRestorePageLoadMetricsObserver::OnLoadedResource(
+ const page_load_metrics::ExtraRequestInfo& extra_request_info) {
+ if (extra_request_info.was_cached) {
+ cache_bytes_ += extra_request_info.raw_body_bytes;
+ } else {
+ network_bytes_ += extra_request_info.raw_body_bytes;
+ }
+}
+
+page_load_metrics::PageLoadMetricsObserver::ObservePolicy
+TabRestorePageLoadMetricsObserver::FlushMetricsOnAppEnterBackground(
+ const page_load_metrics::PageLoadTiming& timing,
+ const page_load_metrics::PageLoadExtraInfo& info) {
+ // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the
+ // app is about to be backgrounded, as part of the Activity.onPause()
+ // flow. After this method is invoked, Chrome may be killed without further
+ // notification, so we record final metrics collected up to this point.
+ if (!info.did_commit) {
+ RecordByteHistograms();
+ }
+ return STOP_OBSERVING;
+}
+
+void TabRestorePageLoadMetricsObserver::OnComplete(
+ const page_load_metrics::PageLoadTiming& timing,
+ const page_load_metrics::PageLoadExtraInfo& info) {
+ RecordByteHistograms();
+}
+
+void TabRestorePageLoadMetricsObserver::RecordByteHistograms() {
+ PAGE_BYTES_HISTOGRAM(kHistogramNetworkBytes, network_bytes_);
+ PAGE_BYTES_HISTOGRAM(kHistogramCacheBytes, cache_bytes_);
+ PAGE_BYTES_HISTOGRAM(kHistogramTotalBytes, network_bytes_ + cache_bytes_);
+}
+
+bool TabRestorePageLoadMetricsObserver::IsTabRestore(
+ content::NavigationHandle* navigation_handle) {
+ // Only count restored tabs, and eliminate forward-back navigations, as
+ // restored tab history is considered a restored navigation until they are
+ // loaded the first time.
+ return navigation_handle->GetRestoreType() != content::RestoreType::NONE &&
+ !(navigation_handle->GetPageTransition() &
+ ui::PAGE_TRANSITION_FORWARD_BACK);
+}

Powered by Google App Engine
This is Rietveld 408576698