| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/previews_page_load_metrics_
observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/previews_page_load_metrics_
observer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/optional.h" | 9 #include "base/optional.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." | 32 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." |
| 33 "NavigationToLoadEventFired"; | 33 "NavigationToLoadEventFired"; |
| 34 const char kHistogramOfflinePreviewsFirstContentfulPaint[] = | 34 const char kHistogramOfflinePreviewsFirstContentfulPaint[] = |
| 35 "PageLoad.Clients.Previews.OfflinePages.PaintTiming." | 35 "PageLoad.Clients.Previews.OfflinePages.PaintTiming." |
| 36 "NavigationToFirstContentfulPaint"; | 36 "NavigationToFirstContentfulPaint"; |
| 37 const char kHistogramOfflinePreviewsParseStart[] = | 37 const char kHistogramOfflinePreviewsParseStart[] = |
| 38 "PageLoad.Clients.Previews.OfflinePages.ParseTiming.NavigationToParseStart"; | 38 "PageLoad.Clients.Previews.OfflinePages.ParseTiming.NavigationToParseStart"; |
| 39 | 39 |
| 40 } // namespace internal | 40 } // namespace internal |
| 41 | 41 |
| 42 PreviewsPageLoadMetricsObserver::PreviewsPageLoadMetricsObserver() | 42 PreviewsPageLoadMetricsObserver::PreviewsPageLoadMetricsObserver() {} |
| 43 : is_offline_preview_(false) {} | |
| 44 | 43 |
| 45 PreviewsPageLoadMetricsObserver::~PreviewsPageLoadMetricsObserver() {} | 44 PreviewsPageLoadMetricsObserver::~PreviewsPageLoadMetricsObserver() {} |
| 46 | 45 |
| 47 void PreviewsPageLoadMetricsObserver::OnCommit( | 46 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 47 PreviewsPageLoadMetricsObserver::OnCommit( |
| 48 content::NavigationHandle* navigation_handle) { | 48 content::NavigationHandle* navigation_handle) { |
| 49 is_offline_preview_ = IsOfflinePreview(navigation_handle->GetWebContents()); | 49 return IsOfflinePreview(navigation_handle->GetWebContents()) |
| 50 ? CONTINUE_OBSERVING |
| 51 : STOP_OBSERVING; |
| 50 } | 52 } |
| 51 | 53 |
| 52 void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( | 54 void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( |
| 53 const page_load_metrics::PageLoadTiming& timing, | 55 const page_load_metrics::PageLoadTiming& timing, |
| 54 const page_load_metrics::PageLoadExtraInfo& info) { | 56 const page_load_metrics::PageLoadExtraInfo& info) { |
| 55 if (!is_offline_preview_ || | 57 if (!WasStartedInForegroundOptionalEventInForeground( |
| 56 !WasStartedInForegroundOptionalEventInForeground( | |
| 57 timing.dom_content_loaded_event_start, info)) { | 58 timing.dom_content_loaded_event_start, info)) { |
| 58 return; | 59 return; |
| 59 } | 60 } |
| 60 PAGE_LOAD_HISTOGRAM( | 61 PAGE_LOAD_HISTOGRAM( |
| 61 internal::kHistogramOfflinePreviewsDOMContentLoadedEventFired, | 62 internal::kHistogramOfflinePreviewsDOMContentLoadedEventFired, |
| 62 timing.dom_content_loaded_event_start.value()); | 63 timing.dom_content_loaded_event_start.value()); |
| 63 } | 64 } |
| 64 | 65 |
| 65 void PreviewsPageLoadMetricsObserver::OnLoadEventStart( | 66 void PreviewsPageLoadMetricsObserver::OnLoadEventStart( |
| 66 const page_load_metrics::PageLoadTiming& timing, | 67 const page_load_metrics::PageLoadTiming& timing, |
| 67 const page_load_metrics::PageLoadExtraInfo& info) { | 68 const page_load_metrics::PageLoadExtraInfo& info) { |
| 68 if (!is_offline_preview_ || | 69 if (!WasStartedInForegroundOptionalEventInForeground( |
| 69 !WasStartedInForegroundOptionalEventInForeground( | |
| 70 timing.dom_content_loaded_event_start, info)) { | 70 timing.dom_content_loaded_event_start, info)) { |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsLoadEventFired, | 73 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsLoadEventFired, |
| 74 timing.load_event_start.value()); | 74 timing.load_event_start.value()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void PreviewsPageLoadMetricsObserver::OnFirstLayout( | 77 void PreviewsPageLoadMetricsObserver::OnFirstLayout( |
| 78 const page_load_metrics::PageLoadTiming& timing, | 78 const page_load_metrics::PageLoadTiming& timing, |
| 79 const page_load_metrics::PageLoadExtraInfo& info) { | 79 const page_load_metrics::PageLoadExtraInfo& info) { |
| 80 if (!is_offline_preview_ || | 80 if (!WasStartedInForegroundOptionalEventInForeground( |
| 81 !WasStartedInForegroundOptionalEventInForeground( | |
| 82 timing.dom_content_loaded_event_start, info)) { | 81 timing.dom_content_loaded_event_start, info)) { |
| 83 return; | 82 return; |
| 84 } | 83 } |
| 85 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsFirstLayout, | 84 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsFirstLayout, |
| 86 timing.first_layout.value()); | 85 timing.first_layout.value()); |
| 87 } | 86 } |
| 88 | 87 |
| 89 void PreviewsPageLoadMetricsObserver::OnFirstContentfulPaint( | 88 void PreviewsPageLoadMetricsObserver::OnFirstContentfulPaint( |
| 90 const page_load_metrics::PageLoadTiming& timing, | 89 const page_load_metrics::PageLoadTiming& timing, |
| 91 const page_load_metrics::PageLoadExtraInfo& info) { | 90 const page_load_metrics::PageLoadExtraInfo& info) { |
| 92 if (!is_offline_preview_ || | 91 if (!WasStartedInForegroundOptionalEventInForeground( |
| 93 !WasStartedInForegroundOptionalEventInForeground( | |
| 94 timing.dom_content_loaded_event_start, info)) { | 92 timing.dom_content_loaded_event_start, info)) { |
| 95 return; | 93 return; |
| 96 } | 94 } |
| 97 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsFirstContentfulPaint, | 95 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsFirstContentfulPaint, |
| 98 timing.first_contentful_paint.value()); | 96 timing.first_contentful_paint.value()); |
| 99 } | 97 } |
| 100 | 98 |
| 101 void PreviewsPageLoadMetricsObserver::OnParseStart( | 99 void PreviewsPageLoadMetricsObserver::OnParseStart( |
| 102 const page_load_metrics::PageLoadTiming& timing, | 100 const page_load_metrics::PageLoadTiming& timing, |
| 103 const page_load_metrics::PageLoadExtraInfo& info) { | 101 const page_load_metrics::PageLoadExtraInfo& info) { |
| 104 if (!is_offline_preview_ || | 102 if (!WasStartedInForegroundOptionalEventInForeground( |
| 105 !WasStartedInForegroundOptionalEventInForeground( | |
| 106 timing.dom_content_loaded_event_start, info)) { | 103 timing.dom_content_loaded_event_start, info)) { |
| 107 return; | 104 return; |
| 108 } | 105 } |
| 109 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsParseStart, | 106 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsParseStart, |
| 110 timing.parse_start.value()); | 107 timing.parse_start.value()); |
| 111 } | 108 } |
| 112 | 109 |
| 113 bool PreviewsPageLoadMetricsObserver::IsOfflinePreview( | 110 bool PreviewsPageLoadMetricsObserver::IsOfflinePreview( |
| 114 content::WebContents* web_contents) const { | 111 content::WebContents* web_contents) const { |
| 115 #if BUILDFLAG(ANDROID_JAVA_UI) | 112 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 116 offline_pages::OfflinePageTabHelper* tab_helper = | 113 offline_pages::OfflinePageTabHelper* tab_helper = |
| 117 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents); | 114 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents); |
| 118 return tab_helper && tab_helper->is_offline_preview(); | 115 return tab_helper && tab_helper->is_offline_preview(); |
| 119 #else | 116 #else |
| 120 return false; | 117 return false; |
| 121 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 118 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 122 } | 119 } |
| 123 | 120 |
| 124 } // namespace previews | 121 } // namespace previews |
| OLD | NEW |