Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/page_load_metrics/observers/https_page_load_metrics_obs erver.h" | |
| 6 | |
| 7 #include "base/metrics/histogram_macros.h" | |
| 8 #include "url/url_constants.h" | |
| 9 | |
| 10 HttpsPageLoadMetricsObserver::HttpsPageLoadMetricsObserver() | |
| 11 : time_travelled_backwards_(false) {} | |
| 12 | |
| 13 void HttpsPageLoadMetricsObserver::OnCommit( | |
| 14 content::NavigationHandle* navigation_handle, | |
| 15 bool started_in_foreground) { | |
| 16 url_ = navigation_handle->GetURL(); | |
| 17 if (started_in_foreground) | |
| 18 OnShown(); | |
| 19 } | |
| 20 | |
| 21 void HttpsPageLoadMetricsObserver::OnHidden() { | |
| 22 base::Time current_time = base::Time::Now(); | |
| 23 currently_in_foreground_ = false; | |
| 24 | |
| 25 // Backwards time travel can occur if (a) the device has gone through a time | |
| 26 // machine, or (b) the client's clock was changed. Record backwards time | |
| 27 // travel to invalidate the statistics for this page. | |
| 28 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.
| |
| 29 time_travelled_backwards_ = true; | |
| 30 return; | |
| 31 } | |
| 32 | |
| 33 foreground_time_ += current_time - last_time_shown_; | |
| 34 } | |
| 35 | |
| 36 void HttpsPageLoadMetricsObserver::OnShown() { | |
| 37 last_time_shown_ = base::Time::Now(); | |
| 38 currently_in_foreground_ = true; | |
| 39 } | |
| 40 | |
| 41 void HttpsPageLoadMetricsObserver::OnComplete( | |
| 42 const page_load_metrics::PageLoadTiming& timing, | |
| 43 const page_load_metrics::PageLoadExtraInfo& extra_info) { | |
| 44 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
| |
| 45 return; | |
| 46 | |
| 47 if (currently_in_foreground_) | |
| 48 OnHidden(); | |
| 49 | |
| 50 if (url_.SchemeIs(url::kHttpsScheme)) | |
| 51 UMA_HISTOGRAM_LONG_TIMES_100("Navigation.Time.HTTPS", foreground_time_); | |
| 52 else if (url_.SchemeIs(url::kHttpScheme)) | |
| 53 UMA_HISTOGRAM_LONG_TIMES_100("Navigation.Time.HTTP", foreground_time_); | |
| 54 else | |
| 55 UMA_HISTOGRAM_LONG_TIMES_100("Navigation.Time.Other", foreground_time_); | |
| 56 } | |
| OLD | NEW |