| 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/previews_page_load_metrics_
observer.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/optional.h" |
| 10 #include "base/time/time.h" |
| 11 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
| 12 #include "chrome/common/features.h" |
| 13 #include "chrome/common/page_load_metrics/page_load_timing.h" |
| 14 #include "content/public/browser/navigation_handle.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 |
| 17 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 18 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" |
| 19 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 20 |
| 21 namespace previews { |
| 22 |
| 23 namespace internal { |
| 24 |
| 25 const char kHistogramOfflinePreviewsDOMContentLoadedEventFired[] = |
| 26 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." |
| 27 "NavigationToDOMContentLoadedEventFired"; |
| 28 const char kHistogramOfflinePreviewsFirstLayout[] = |
| 29 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." |
| 30 "NavigationToFirstLayout"; |
| 31 const char kHistogramOfflinePreviewsLoadEventFired[] = |
| 32 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." |
| 33 "NavigationToLoadEventFired"; |
| 34 const char kHistogramOfflinePreviewsFirstContentfulPaint[] = |
| 35 "PageLoad.Clients.Previews.OfflinePages.PaintTiming." |
| 36 "NavigationToFirstContentfulPaint"; |
| 37 const char kHistogramOfflinePreviewsParseStart[] = |
| 38 "PageLoad.Clients.Previews.OfflinePages.ParseTiming.NavigationToParseStart"; |
| 39 |
| 40 } // namespace internal |
| 41 |
| 42 PreviewsPageLoadMetricsObserver::PreviewsPageLoadMetricsObserver() |
| 43 : is_offline_preview_(false) {} |
| 44 |
| 45 PreviewsPageLoadMetricsObserver::~PreviewsPageLoadMetricsObserver() {} |
| 46 |
| 47 void PreviewsPageLoadMetricsObserver::OnCommit( |
| 48 content::NavigationHandle* navigation_handle) { |
| 49 is_offline_preview_ = IsOfflinePreview(navigation_handle->GetWebContents()); |
| 50 } |
| 51 |
| 52 void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( |
| 53 const page_load_metrics::PageLoadTiming& timing, |
| 54 const page_load_metrics::PageLoadExtraInfo& info) { |
| 55 if (!is_offline_preview_ || |
| 56 !WasStartedInForegroundOptionalEventInForeground( |
| 57 timing.dom_content_loaded_event_start, info)) { |
| 58 return; |
| 59 } |
| 60 PAGE_LOAD_HISTOGRAM( |
| 61 internal::kHistogramOfflinePreviewsDOMContentLoadedEventFired, |
| 62 timing.dom_content_loaded_event_start.value()); |
| 63 } |
| 64 |
| 65 void PreviewsPageLoadMetricsObserver::OnLoadEventStart( |
| 66 const page_load_metrics::PageLoadTiming& timing, |
| 67 const page_load_metrics::PageLoadExtraInfo& info) { |
| 68 if (!is_offline_preview_ || |
| 69 !WasStartedInForegroundOptionalEventInForeground( |
| 70 timing.dom_content_loaded_event_start, info)) { |
| 71 return; |
| 72 } |
| 73 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsLoadEventFired, |
| 74 timing.load_event_start.value()); |
| 75 } |
| 76 |
| 77 void PreviewsPageLoadMetricsObserver::OnFirstLayout( |
| 78 const page_load_metrics::PageLoadTiming& timing, |
| 79 const page_load_metrics::PageLoadExtraInfo& info) { |
| 80 if (!is_offline_preview_ || |
| 81 !WasStartedInForegroundOptionalEventInForeground( |
| 82 timing.dom_content_loaded_event_start, info)) { |
| 83 return; |
| 84 } |
| 85 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsFirstLayout, |
| 86 timing.first_layout.value()); |
| 87 } |
| 88 |
| 89 void PreviewsPageLoadMetricsObserver::OnFirstContentfulPaint( |
| 90 const page_load_metrics::PageLoadTiming& timing, |
| 91 const page_load_metrics::PageLoadExtraInfo& info) { |
| 92 if (!is_offline_preview_ || |
| 93 !WasStartedInForegroundOptionalEventInForeground( |
| 94 timing.dom_content_loaded_event_start, info)) { |
| 95 return; |
| 96 } |
| 97 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsFirstContentfulPaint, |
| 98 timing.first_contentful_paint.value()); |
| 99 } |
| 100 |
| 101 void PreviewsPageLoadMetricsObserver::OnParseStart( |
| 102 const page_load_metrics::PageLoadTiming& timing, |
| 103 const page_load_metrics::PageLoadExtraInfo& info) { |
| 104 if (!is_offline_preview_ || |
| 105 !WasStartedInForegroundOptionalEventInForeground( |
| 106 timing.dom_content_loaded_event_start, info)) { |
| 107 return; |
| 108 } |
| 109 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsParseStart, |
| 110 timing.parse_start.value()); |
| 111 } |
| 112 |
| 113 bool PreviewsPageLoadMetricsObserver::IsOfflinePreview( |
| 114 content::WebContents* web_contents) const { |
| 115 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 116 offline_pages::OfflinePageTabHelper* tab_helper = |
| 117 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents); |
| 118 return tab_helper && tab_helper->is_offline_preview(); |
| 119 #else |
| 120 return false; |
| 121 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 122 } |
| 123 |
| 124 } // namespace previews |
| OLD | NEW |