| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/page_load_metrics/observers/stale_while_revalidate_metr
ics_observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/stale_while_revalidate_metr
ics_observer.h" |
| 6 | 6 |
| 7 #include "components/page_load_metrics/browser/page_load_metrics_util.h" | 7 #include "components/page_load_metrics/browser/page_load_metrics_util.h" |
| 8 #include "components/page_load_metrics/common/page_load_timing.h" | 8 #include "components/page_load_metrics/common/page_load_timing.h" |
| 9 #include "content/public/browser/navigation_handle.h" | 9 #include "content/public/browser/navigation_handle.h" |
| 10 #include "net/base/stale_while_revalidate_experiment_domains.h" | 10 #include "net/base/stale_while_revalidate_experiment_domains.h" |
| 11 | 11 |
| 12 namespace chrome { | 12 namespace chrome { |
| 13 | 13 |
| 14 StaleWhileRevalidateMetricsObserver::StaleWhileRevalidateMetricsObserver( | 14 StaleWhileRevalidateMetricsObserver::StaleWhileRevalidateMetricsObserver( |
| 15 page_load_metrics::PageLoadMetricsObservable* metrics) | 15 page_load_metrics::PageLoadMetricsObservable* metrics) |
| 16 : is_interesting_domain_(false), metrics_(metrics) {} | 16 : is_interesting_domain_(false), metrics_(metrics) {} |
| 17 | 17 |
| 18 void StaleWhileRevalidateMetricsObserver::OnCommit( | 18 void StaleWhileRevalidateMetricsObserver::OnCommit( |
| 19 content::NavigationHandle* navigation_handle) { | 19 content::NavigationHandle* navigation_handle) { |
| 20 is_interesting_domain_ = net::IsHostInStaleWhileRevalidateExperimentDomain( | 20 is_interesting_domain_ = net::IsHostInStaleWhileRevalidateExperimentDomain( |
| 21 navigation_handle->GetURL().host()); | 21 navigation_handle->GetURL().host()); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void StaleWhileRevalidateMetricsObserver::OnComplete( | 24 void StaleWhileRevalidateMetricsObserver::OnComplete( |
| 25 const page_load_metrics::PageLoadTiming& timing, | 25 const page_load_metrics::PageLoadTiming& timing, |
| 26 const page_load_metrics::PageLoadExtraInfo& extra_info) { | 26 const page_load_metrics::PageLoadExtraInfo& extra_info) { |
| 27 using page_load_metrics::EventOccurredInForeground; |
| 28 |
| 27 if (!is_interesting_domain_) | 29 if (!is_interesting_domain_) |
| 28 return; | 30 return; |
| 29 | 31 |
| 30 if (!timing.load_event_start.is_zero()) { | 32 // A page load that started in the background usually means a prerender. The |
| 33 // performance metrics for a prerender aren't directly comparable to normal |
| 34 // foreground page loads, so just drop them. |
| 35 if (!extra_info.started_in_foreground) |
| 36 return; |
| 37 |
| 38 const base::TimeDelta& first_background = extra_info.first_background_time; |
| 39 |
| 40 if (EventOccurredInForeground(timing.load_event_start, first_background)) { |
| 31 PAGE_LOAD_HISTOGRAM( | 41 PAGE_LOAD_HISTOGRAM( |
| 32 "PageLoad.Clients.StaleWhileRevalidateExperiment.Timing2." | 42 "PageLoad.Clients.StaleWhileRevalidateExperiment.Timing2." |
| 33 "NavigationToLoadEventFired", | 43 "NavigationToLoadEventFired", |
| 34 timing.load_event_start); | 44 timing.load_event_start); |
| 35 } | 45 } |
| 36 if (!timing.first_layout.is_zero()) { | 46 if (EventOccurredInForeground(timing.first_layout, first_background)) { |
| 37 PAGE_LOAD_HISTOGRAM( | 47 PAGE_LOAD_HISTOGRAM( |
| 38 "PageLoad.Clients.StaleWhileRevalidateExperiment.Timing2." | 48 "PageLoad.Clients.StaleWhileRevalidateExperiment.Timing2." |
| 39 "NavigationToFirstLayout", | 49 "NavigationToFirstLayout", |
| 40 timing.first_layout); | 50 timing.first_layout); |
| 41 } | 51 } |
| 42 if (!timing.first_text_paint.is_zero()) { | 52 if (EventOccurredInForeground(timing.first_text_paint, first_background)) { |
| 43 PAGE_LOAD_HISTOGRAM( | 53 PAGE_LOAD_HISTOGRAM( |
| 44 "PageLoad.Clients.StaleWhileRevalidateExperiment.Timing2." | 54 "PageLoad.Clients.StaleWhileRevalidateExperiment.Timing2." |
| 45 "NavigationToFirstTextPaint", | 55 "NavigationToFirstTextPaint", |
| 46 timing.first_text_paint); | 56 timing.first_text_paint); |
| 47 } | 57 } |
| 48 } | 58 } |
| 49 | 59 |
| 50 void StaleWhileRevalidateMetricsObserver::OnPageLoadMetricsGoingAway() { | 60 void StaleWhileRevalidateMetricsObserver::OnPageLoadMetricsGoingAway() { |
| 51 metrics_->RemoveObserver(this); | 61 metrics_->RemoveObserver(this); |
| 52 delete this; | 62 delete this; |
| 53 } | 63 } |
| 54 | 64 |
| 55 } // namespace chrome | 65 } // namespace chrome |
| OLD | NEW |