| 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" |
| 11 #include "chrome/browser/loader/chrome_navigation_data.h" |
| 11 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 12 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
| 12 #include "chrome/common/features.h" | 13 #include "chrome/common/features.h" |
| 13 #include "chrome/common/page_load_metrics/page_load_timing.h" | 14 #include "chrome/common/page_load_metrics/page_load_timing.h" |
| 15 #include "components/offline_pages/loaded_offline_page_info.h" |
| 14 #include "content/public/browser/navigation_handle.h" | 16 #include "content/public/browser/navigation_handle.h" |
| 15 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 16 | 18 |
| 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 { | 19 namespace previews { |
| 22 | 20 |
| 23 namespace internal { | 21 namespace internal { |
| 24 | 22 |
| 25 const char kHistogramOfflinePreviewsDOMContentLoadedEventFired[] = | 23 const char kHistogramOfflinePreviewsDOMContentLoadedEventFired[] = |
| 26 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." | 24 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." |
| 27 "NavigationToDOMContentLoadedEventFired"; | 25 "NavigationToDOMContentLoadedEventFired"; |
| 28 const char kHistogramOfflinePreviewsFirstLayout[] = | 26 const char kHistogramOfflinePreviewsFirstLayout[] = |
| 29 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." | 27 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." |
| 30 "NavigationToFirstLayout"; | 28 "NavigationToFirstLayout"; |
| 31 const char kHistogramOfflinePreviewsLoadEventFired[] = | 29 const char kHistogramOfflinePreviewsLoadEventFired[] = |
| 32 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." | 30 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming." |
| 33 "NavigationToLoadEventFired"; | 31 "NavigationToLoadEventFired"; |
| 34 const char kHistogramOfflinePreviewsFirstContentfulPaint[] = | 32 const char kHistogramOfflinePreviewsFirstContentfulPaint[] = |
| 35 "PageLoad.Clients.Previews.OfflinePages.PaintTiming." | 33 "PageLoad.Clients.Previews.OfflinePages.PaintTiming." |
| 36 "NavigationToFirstContentfulPaint"; | 34 "NavigationToFirstContentfulPaint"; |
| 37 const char kHistogramOfflinePreviewsParseStart[] = | 35 const char kHistogramOfflinePreviewsParseStart[] = |
| 38 "PageLoad.Clients.Previews.OfflinePages.ParseTiming.NavigationToParseStart"; | 36 "PageLoad.Clients.Previews.OfflinePages.ParseTiming.NavigationToParseStart"; |
| 39 | 37 |
| 40 } // namespace internal | 38 } // namespace internal |
| 41 | 39 |
| 42 PreviewsPageLoadMetricsObserver::PreviewsPageLoadMetricsObserver() {} | 40 PreviewsPageLoadMetricsObserver::PreviewsPageLoadMetricsObserver() {} |
| 43 | 41 |
| 44 PreviewsPageLoadMetricsObserver::~PreviewsPageLoadMetricsObserver() {} | 42 PreviewsPageLoadMetricsObserver::~PreviewsPageLoadMetricsObserver() {} |
| 45 | 43 |
| 46 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 44 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 47 PreviewsPageLoadMetricsObserver::OnCommit( | 45 PreviewsPageLoadMetricsObserver::OnCommit( |
| 48 content::NavigationHandle* navigation_handle) { | 46 content::NavigationHandle* navigation_handle) { |
| 49 return IsOfflinePreview(navigation_handle->GetWebContents()) | 47 ChromeNavigationData* chrome_navigation_data = |
| 50 ? CONTINUE_OBSERVING | 48 ChromeNavigationData::GetForNavigationHandle(navigation_handle); |
| 51 : STOP_OBSERVING; | 49 if (!chrome_navigation_data) |
| 50 return STOP_OBSERVING; |
| 51 offline_pages::LoadedOfflinePageInfo* info = |
| 52 chrome_navigation_data->GetLoadedOfflinePageInfo(); |
| 53 return info && info->is_offline_preview() ? CONTINUE_OBSERVING |
| 54 : STOP_OBSERVING; |
| 52 } | 55 } |
| 53 | 56 |
| 54 void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( | 57 void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( |
| 55 const page_load_metrics::PageLoadTiming& timing, | 58 const page_load_metrics::PageLoadTiming& timing, |
| 56 const page_load_metrics::PageLoadExtraInfo& info) { | 59 const page_load_metrics::PageLoadExtraInfo& info) { |
| 57 if (!WasStartedInForegroundOptionalEventInForeground( | 60 if (!WasStartedInForegroundOptionalEventInForeground( |
| 58 timing.dom_content_loaded_event_start, info)) { | 61 timing.dom_content_loaded_event_start, info)) { |
| 59 return; | 62 return; |
| 60 } | 63 } |
| 61 PAGE_LOAD_HISTOGRAM( | 64 PAGE_LOAD_HISTOGRAM( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 const page_load_metrics::PageLoadTiming& timing, | 103 const page_load_metrics::PageLoadTiming& timing, |
| 101 const page_load_metrics::PageLoadExtraInfo& info) { | 104 const page_load_metrics::PageLoadExtraInfo& info) { |
| 102 if (!WasStartedInForegroundOptionalEventInForeground( | 105 if (!WasStartedInForegroundOptionalEventInForeground( |
| 103 timing.dom_content_loaded_event_start, info)) { | 106 timing.dom_content_loaded_event_start, info)) { |
| 104 return; | 107 return; |
| 105 } | 108 } |
| 106 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsParseStart, | 109 PAGE_LOAD_HISTOGRAM(internal::kHistogramOfflinePreviewsParseStart, |
| 107 timing.parse_start.value()); | 110 timing.parse_start.value()); |
| 108 } | 111 } |
| 109 | 112 |
| 110 bool PreviewsPageLoadMetricsObserver::IsOfflinePreview( | |
| 111 content::WebContents* web_contents) const { | |
| 112 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 113 offline_pages::OfflinePageTabHelper* tab_helper = | |
| 114 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents); | |
| 115 return tab_helper && tab_helper->is_offline_preview(); | |
| 116 #else | |
| 117 return false; | |
| 118 #endif // BUILDFLAG(ANDROID_JAVA_UI) | |
| 119 } | |
| 120 | |
| 121 } // namespace previews | 113 } // namespace previews |
| OLD | NEW |