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

Unified Diff: chrome/browser/page_load_metrics/observers/https_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: Add comments Created 4 years, 8 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_page_load_metrics_observer.cc
diff --git a/chrome/browser/page_load_metrics/observers/https_page_load_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/https_page_load_metrics_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..092434b0b328b13f2adcec5e1e8d92f1329a5e93
--- /dev/null
+++ b/chrome/browser/page_load_metrics/observers/https_page_load_metrics_observer.cc
@@ -0,0 +1,56 @@
+// 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_page_load_metrics_observer.h"
+
+#include "base/metrics/histogram_macros.h"
+#include "url/url_constants.h"
+
+HttpsPageLoadMetricsObserver::HttpsPageLoadMetricsObserver()
+ : time_travelled_backwards_(false) {}
+
+void HttpsPageLoadMetricsObserver::OnCommit(
+ content::NavigationHandle* navigation_handle,
+ bool started_in_foreground) {
+ url_ = navigation_handle->GetURL();
+ if (started_in_foreground)
+ OnShown();
+}
+
+void HttpsPageLoadMetricsObserver::OnHidden() {
+ base::Time current_time = base::Time::Now();
+ currently_in_foreground_ = false;
+
+ // Backwards time travel can occur if (a) the device has gone through a time
+ // machine, or (b) the client's clock was changed. Record backwards time
+ // travel to invalidate the statistics for this page.
+ if (last_time_shown_ > current_time) {
Charlie Harrison 2016/04/25 13:20:08 If you used TimeTicks you wouldn't have to worry a
felt 2016/04/25 21:30:04 Ahh, good point. Done.
+ time_travelled_backwards_ = true;
+ return;
+ }
+
+ foreground_time_ += current_time - last_time_shown_;
+}
+
+void HttpsPageLoadMetricsObserver::OnShown() {
+ last_time_shown_ = base::Time::Now();
+ currently_in_foreground_ = true;
+}
+
+void HttpsPageLoadMetricsObserver::OnComplete(
+ const page_load_metrics::PageLoadTiming& timing,
+ const page_load_metrics::PageLoadExtraInfo& extra_info) {
+ if (time_travelled_backwards_ || !url_.is_valid())
Charlie Harrison 2016/04/25 13:20:08 You'll also might want to filter out results if th
felt 2016/04/25 21:30:04 Good point. I've switched to using the committed U
+ return;
+
+ if (currently_in_foreground_)
+ OnHidden();
+
+ if (url_.SchemeIs(url::kHttpsScheme))
+ UMA_HISTOGRAM_LONG_TIMES_100("Navigation.Time.HTTPS", foreground_time_);
+ else if (url_.SchemeIs(url::kHttpScheme))
+ UMA_HISTOGRAM_LONG_TIMES_100("Navigation.Time.HTTP", foreground_time_);
+ else
+ UMA_HISTOGRAM_LONG_TIMES_100("Navigation.Time.Other", foreground_time_);
+}

Powered by Google App Engine
This is Rietveld 408576698