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/service_worker_page_load_me
trics_observer.h" |
| 6 |
| 7 #include "components/page_load_metrics/browser/page_load_metrics_util.h" |
| 8 #include "third_party/WebKit/public/platform/WebLoadingBehaviorFlag.h" |
| 9 |
| 10 namespace internal { |
| 11 |
| 12 const char kHistogramServiceWorkerFirstContentfulPaint[] = |
| 13 "PageLoad.Clients.ServiceWorker.Timing2.NavigationToFirstContentfulPaint"; |
| 14 const char kBackgroundHistogramServiceWorkerFirstContentfulPaint[] = |
| 15 "PageLoad.Clients.ServiceWorker.Timing2.NavigationToFirstContentfulPaint." |
| 16 "Background"; |
| 17 |
| 18 } // namespace internal |
| 19 |
| 20 ServiceWorkerPageLoadMetricsObserver::ServiceWorkerPageLoadMetricsObserver() {} |
| 21 |
| 22 void ServiceWorkerPageLoadMetricsObserver::OnComplete( |
| 23 const page_load_metrics::PageLoadTiming& timing, |
| 24 const page_load_metrics::PageLoadExtraInfo& info) { |
| 25 if (timing.first_contentful_paint.is_zero()) |
| 26 return; |
| 27 if (info.metadata.behavior_flags & |
| 28 blink::WebLoadingBehaviorFlag:: |
| 29 WebLoadingBehaviorServiceWorkerControlled) { |
| 30 LogServiceWorkerHistograms(timing, info); |
| 31 } |
| 32 } |
| 33 |
| 34 void ServiceWorkerPageLoadMetricsObserver::LogServiceWorkerHistograms( |
| 35 const page_load_metrics::PageLoadTiming& timing, |
| 36 const page_load_metrics::PageLoadExtraInfo& info) { |
| 37 bool foreground_paint = WasStartedInForegroundEventInForeground( |
| 38 timing.first_contentful_paint, info); |
| 39 if (foreground_paint) { |
| 40 PAGE_LOAD_HISTOGRAM(internal::kHistogramServiceWorkerFirstContentfulPaint, |
| 41 timing.first_contentful_paint); |
| 42 } else { |
| 43 PAGE_LOAD_HISTOGRAM( |
| 44 internal::kBackgroundHistogramServiceWorkerFirstContentfulPaint, |
| 45 timing.first_contentful_paint); |
| 46 } |
| 47 } |
OLD | NEW |