Chromium Code Reviews| 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 kHistogramOfflinePreviewsPrefix[] = | |
| 26 "PageLoad.Clients.Previews.OfflinePages."; | |
| 27 const char kHistogramDOMContentLoadedEventFiredSuffix[] = | |
| 28 "DocumentTiming.NavigationToDOMContentLoadedEventFired"; | |
| 29 const char kHistogramFirstLayoutSuffix[] = | |
| 30 "DocumentTiming.NavigationToFirstLayout"; | |
| 31 const char kHistogramLoadEventFiredSuffix[] = | |
| 32 "DocumentTiming.NavigationToLoadEventFired"; | |
| 33 const char kHistogramFirstContentfulPaintSuffix[] = | |
| 34 "PaintTiming.NavigationToFirstContentfulPaint"; | |
| 35 const char kHistogramFirstImagePaintSuffix[] = | |
| 36 "PaintTiming.NavigationToFirstImagePaint"; | |
| 37 const char kHistogramFirstPaintSuffix[] = "PaintTiming.NavigationToFirstPaint"; | |
| 38 const char kHistogramFirstTextPaintSuffix[] = | |
| 39 "PaintTiming.NavigationToFirstTextPaint"; | |
| 40 const char kHistogramParseStartSuffix[] = "ParseTiming.NavigationToParseStart"; | |
| 41 | |
| 42 } // namespace internal | |
| 43 | |
| 44 PreviewsPageLoadMetricsObserver::PreviewsPageLoadMetricsObserver() | |
| 45 : is_offline_preview_(false) {} | |
| 46 | |
| 47 PreviewsPageLoadMetricsObserver::~PreviewsPageLoadMetricsObserver() {} | |
| 48 | |
| 49 void PreviewsPageLoadMetricsObserver::OnCommit( | |
| 50 content::NavigationHandle* navigation_handle) { | |
| 51 is_offline_preview_ = IsOfflinePreview(navigation_handle->GetWebContents()); | |
| 52 } | |
| 53 | |
| 54 void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( | |
| 55 const page_load_metrics::PageLoadTiming& timing, | |
| 56 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 57 if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( | |
|
tbansal1
2016/08/18 22:04:53
Would it be more readable if the boolean condition
RyanSturm
2016/08/19 19:10:38
Done.
| |
| 58 timing.dom_content_loaded_event_start, info)) { | |
| 59 PAGE_LOAD_HISTOGRAM( | |
| 60 std::string(internal::kHistogramOfflinePreviewsPrefix) | |
| 61 .append(internal::kHistogramDOMContentLoadedEventFiredSuffix), | |
| 62 timing.dom_content_loaded_event_start.value()); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 void PreviewsPageLoadMetricsObserver::OnLoadEventStart( | |
| 67 const page_load_metrics::PageLoadTiming& timing, | |
| 68 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 69 if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( | |
|
tbansal1
2016/08/18 22:04:53
This condition is same as everywhere else. Can it
RyanSturm
2016/08/19 19:10:38
It doesn't really shorten much. It would need to t
| |
| 70 timing.dom_content_loaded_event_start, info)) { | |
| 71 PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) | |
| 72 .append(internal::kHistogramLoadEventFiredSuffix), | |
| 73 timing.load_event_start.value()); | |
| 74 } | |
| 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_ && WasStartedInForegroundOptionalEventInForeground( | |
| 81 timing.dom_content_loaded_event_start, info)) { | |
| 82 PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) | |
| 83 .append(internal::kHistogramFirstLayoutSuffix), | |
| 84 timing.first_layout.value()); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 void PreviewsPageLoadMetricsObserver::OnFirstPaint( | |
| 89 const page_load_metrics::PageLoadTiming& timing, | |
| 90 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 91 if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( | |
| 92 timing.dom_content_loaded_event_start, info)) { | |
| 93 PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) | |
| 94 .append(internal::kHistogramFirstPaintSuffix), | |
| 95 timing.first_paint.value()); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 void PreviewsPageLoadMetricsObserver::OnFirstTextPaint( | |
| 100 const page_load_metrics::PageLoadTiming& timing, | |
| 101 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 102 if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( | |
| 103 timing.dom_content_loaded_event_start, info)) { | |
| 104 PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) | |
| 105 .append(internal::kHistogramFirstTextPaintSuffix), | |
| 106 timing.first_text_paint.value()); | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 void PreviewsPageLoadMetricsObserver::OnFirstImagePaint( | |
| 111 const page_load_metrics::PageLoadTiming& timing, | |
| 112 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 113 if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( | |
| 114 timing.dom_content_loaded_event_start, info)) { | |
| 115 PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) | |
| 116 .append(internal::kHistogramFirstImagePaintSuffix), | |
| 117 timing.first_image_paint.value()); | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 void PreviewsPageLoadMetricsObserver::OnFirstContentfulPaint( | |
| 122 const page_load_metrics::PageLoadTiming& timing, | |
| 123 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 124 if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( | |
| 125 timing.dom_content_loaded_event_start, info)) { | |
| 126 PAGE_LOAD_HISTOGRAM( | |
| 127 std::string(internal::kHistogramOfflinePreviewsPrefix) | |
| 128 .append(internal::kHistogramFirstContentfulPaintSuffix), | |
| 129 timing.first_contentful_paint.value()); | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 void PreviewsPageLoadMetricsObserver::OnParseStart( | |
| 134 const page_load_metrics::PageLoadTiming& timing, | |
| 135 const page_load_metrics::PageLoadExtraInfo& info) { | |
| 136 if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( | |
| 137 timing.dom_content_loaded_event_start, info)) { | |
| 138 PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) | |
| 139 .append(internal::kHistogramParseStartSuffix), | |
| 140 timing.parse_start.value()); | |
| 141 } | |
| 142 } | |
| 143 | |
| 144 bool PreviewsPageLoadMetricsObserver::IsOfflinePreview( | |
| 145 content::WebContents* web_contents) const { | |
| 146 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 147 offline_pages::OfflinePageTabHelper* tab_helper = | |
| 148 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents); | |
| 149 return tab_helper && tab_helper->is_preview(); | |
| 150 #else | |
| 151 return false; | |
| 152 #endif // BUILDFLAG(ANDROID_JAVA_UI) | |
| 153 } | |
| 154 | |
| 155 } // namespace previews | |
| OLD | NEW |