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

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

Issue 1913693002: Histogram the amount of time spent on HTTP(S) page loads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Equality operations are hard, let's go trybotting Created 4 years, 7 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/https_engagement_page_load_metrics_observer.cc
diff --git a/chrome/browser/page_load_metrics/observers/https_engagement_page_load_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/https_engagement_page_load_metrics_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1eba05b461a9a4a5e29676264ed5ef587e090ee8
--- /dev/null
+++ b/chrome/browser/page_load_metrics/observers/https_engagement_page_load_metrics_observer.cc
@@ -0,0 +1,59 @@
+// Copyright 2016 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/https_engagement_page_load_metrics_observer.h"
+
+#include "base/metrics/histogram_macros.h"
+#include "url/url_constants.h"
+
+namespace internal {
+const char kHttpsEngagementHistogram[] = "Navigation.EngagementTime.HTTPS";
+const char kHttpEngagementHistogram[] = "Navigation.EngagementTime.HTTP";
+}
+
+HttpsEngagementPageLoadMetricsObserver::HttpsEngagementPageLoadMetricsObserver()
+ : currently_in_foreground_(false) {}
+
+void HttpsEngagementPageLoadMetricsObserver::OnStart(
+ content::NavigationHandle* navigation_handle,
+ const GURL& currently_committed_url,
+ bool started_in_foreground) {
+ if (started_in_foreground)
+ OnShown();
+}
+
+void HttpsEngagementPageLoadMetricsObserver::OnHidden() {
+ if (!currently_in_foreground_)
+ return;
+ foreground_time_ += base::TimeTicks::Now() - last_time_shown_;
+ currently_in_foreground_ = false;
+}
+
+void HttpsEngagementPageLoadMetricsObserver::OnShown() {
+ last_time_shown_ = base::TimeTicks::Now();
+ currently_in_foreground_ = true;
+}
+
+void HttpsEngagementPageLoadMetricsObserver::OnComplete(
+ const page_load_metrics::PageLoadTiming& timing,
+ const page_load_metrics::PageLoadExtraInfo& extra_info) {
+ if (!extra_info.committed_url.is_valid() ||
+ extra_info.time_to_commit.is_zero())
+ return;
+
+ // Don't record anything if the user never saw it.
+ if (!currently_in_foreground_ && foreground_time_.is_zero())
+ return;
+
+ if (currently_in_foreground_)
+ OnHidden();
+
+ if (extra_info.committed_url.SchemeIs(url::kHttpsScheme)) {
+ UMA_HISTOGRAM_LONG_TIMES_100(internal::kHttpsEngagementHistogram,
+ foreground_time_);
+ } else if (extra_info.committed_url.SchemeIs(url::kHttpScheme)) {
+ UMA_HISTOGRAM_LONG_TIMES_100(internal::kHttpEngagementHistogram,
+ foreground_time_);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698