Chromium Code Reviews| Index: chrome/browser/page_load_metrics/observers/previews_page_load_metrics_observer.cc |
| diff --git a/chrome/browser/page_load_metrics/observers/previews_page_load_metrics_observer.cc b/chrome/browser/page_load_metrics/observers/previews_page_load_metrics_observer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b98e6ceefe2e0093dd64ce7d29b3ece16abc01c1 |
| --- /dev/null |
| +++ b/chrome/browser/page_load_metrics/observers/previews_page_load_metrics_observer.cc |
| @@ -0,0 +1,155 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/page_load_metrics/observers/previews_page_load_metrics_observer.h" |
| + |
| +#include <string> |
| + |
| +#include "base/optional.h" |
| +#include "base/time/time.h" |
| +#include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
| +#include "chrome/common/features.h" |
| +#include "chrome/common/page_load_metrics/page_load_timing.h" |
| +#include "content/public/browser/navigation_handle.h" |
| +#include "content/public/browser/web_contents.h" |
| + |
| +#if BUILDFLAG(ANDROID_JAVA_UI) |
| +#include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" |
| +#endif // BUILDFLAG(ANDROID_JAVA_UI) |
| + |
| +namespace previews { |
| + |
| +namespace internal { |
| + |
| +const char kHistogramOfflinePreviewsPrefix[] = |
| + "PageLoad.Clients.Previews.OfflinePages."; |
| +const char kHistogramDOMContentLoadedEventFiredSuffix[] = |
| + "DocumentTiming.NavigationToDOMContentLoadedEventFired"; |
| +const char kHistogramFirstLayoutSuffix[] = |
| + "DocumentTiming.NavigationToFirstLayout"; |
| +const char kHistogramLoadEventFiredSuffix[] = |
| + "DocumentTiming.NavigationToLoadEventFired"; |
| +const char kHistogramFirstContentfulPaintSuffix[] = |
| + "PaintTiming.NavigationToFirstContentfulPaint"; |
| +const char kHistogramFirstImagePaintSuffix[] = |
| + "PaintTiming.NavigationToFirstImagePaint"; |
| +const char kHistogramFirstPaintSuffix[] = "PaintTiming.NavigationToFirstPaint"; |
| +const char kHistogramFirstTextPaintSuffix[] = |
| + "PaintTiming.NavigationToFirstTextPaint"; |
| +const char kHistogramParseStartSuffix[] = "ParseTiming.NavigationToParseStart"; |
| + |
| +} // namespace internal |
| + |
| +PreviewsPageLoadMetricsObserver::PreviewsPageLoadMetricsObserver() |
| + : is_offline_preview_(false) {} |
| + |
| +PreviewsPageLoadMetricsObserver::~PreviewsPageLoadMetricsObserver() {} |
| + |
| +void PreviewsPageLoadMetricsObserver::OnCommit( |
| + content::NavigationHandle* navigation_handle) { |
| + is_offline_preview_ = IsOfflinePreview(navigation_handle->GetWebContents()); |
| +} |
| + |
| +void PreviewsPageLoadMetricsObserver::OnDomContentLoadedEventStart( |
| + const page_load_metrics::PageLoadTiming& timing, |
| + const page_load_metrics::PageLoadExtraInfo& info) { |
| + 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.
|
| + timing.dom_content_loaded_event_start, info)) { |
| + PAGE_LOAD_HISTOGRAM( |
| + std::string(internal::kHistogramOfflinePreviewsPrefix) |
| + .append(internal::kHistogramDOMContentLoadedEventFiredSuffix), |
| + timing.dom_content_loaded_event_start.value()); |
| + } |
| +} |
| + |
| +void PreviewsPageLoadMetricsObserver::OnLoadEventStart( |
| + const page_load_metrics::PageLoadTiming& timing, |
| + const page_load_metrics::PageLoadExtraInfo& info) { |
| + 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
|
| + timing.dom_content_loaded_event_start, info)) { |
| + PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) |
| + .append(internal::kHistogramLoadEventFiredSuffix), |
| + timing.load_event_start.value()); |
| + } |
| +} |
| + |
| +void PreviewsPageLoadMetricsObserver::OnFirstLayout( |
| + const page_load_metrics::PageLoadTiming& timing, |
| + const page_load_metrics::PageLoadExtraInfo& info) { |
| + if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( |
| + timing.dom_content_loaded_event_start, info)) { |
| + PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) |
| + .append(internal::kHistogramFirstLayoutSuffix), |
| + timing.first_layout.value()); |
| + } |
| +} |
| + |
| +void PreviewsPageLoadMetricsObserver::OnFirstPaint( |
| + const page_load_metrics::PageLoadTiming& timing, |
| + const page_load_metrics::PageLoadExtraInfo& info) { |
| + if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( |
| + timing.dom_content_loaded_event_start, info)) { |
| + PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) |
| + .append(internal::kHistogramFirstPaintSuffix), |
| + timing.first_paint.value()); |
| + } |
| +} |
| + |
| +void PreviewsPageLoadMetricsObserver::OnFirstTextPaint( |
| + const page_load_metrics::PageLoadTiming& timing, |
| + const page_load_metrics::PageLoadExtraInfo& info) { |
| + if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( |
| + timing.dom_content_loaded_event_start, info)) { |
| + PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) |
| + .append(internal::kHistogramFirstTextPaintSuffix), |
| + timing.first_text_paint.value()); |
| + } |
| +} |
| + |
| +void PreviewsPageLoadMetricsObserver::OnFirstImagePaint( |
| + const page_load_metrics::PageLoadTiming& timing, |
| + const page_load_metrics::PageLoadExtraInfo& info) { |
| + if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( |
| + timing.dom_content_loaded_event_start, info)) { |
| + PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) |
| + .append(internal::kHistogramFirstImagePaintSuffix), |
| + timing.first_image_paint.value()); |
| + } |
| +} |
| + |
| +void PreviewsPageLoadMetricsObserver::OnFirstContentfulPaint( |
| + const page_load_metrics::PageLoadTiming& timing, |
| + const page_load_metrics::PageLoadExtraInfo& info) { |
| + if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( |
| + timing.dom_content_loaded_event_start, info)) { |
| + PAGE_LOAD_HISTOGRAM( |
| + std::string(internal::kHistogramOfflinePreviewsPrefix) |
| + .append(internal::kHistogramFirstContentfulPaintSuffix), |
| + timing.first_contentful_paint.value()); |
| + } |
| +} |
| + |
| +void PreviewsPageLoadMetricsObserver::OnParseStart( |
| + const page_load_metrics::PageLoadTiming& timing, |
| + const page_load_metrics::PageLoadExtraInfo& info) { |
| + if (is_offline_preview_ && WasStartedInForegroundOptionalEventInForeground( |
| + timing.dom_content_loaded_event_start, info)) { |
| + PAGE_LOAD_HISTOGRAM(std::string(internal::kHistogramOfflinePreviewsPrefix) |
| + .append(internal::kHistogramParseStartSuffix), |
| + timing.parse_start.value()); |
| + } |
| +} |
| + |
| +bool PreviewsPageLoadMetricsObserver::IsOfflinePreview( |
| + content::WebContents* web_contents) const { |
| +#if BUILDFLAG(ANDROID_JAVA_UI) |
| + offline_pages::OfflinePageTabHelper* tab_helper = |
| + offline_pages::OfflinePageTabHelper::FromWebContents(web_contents); |
| + return tab_helper && tab_helper->is_preview(); |
| +#else |
| + return false; |
| +#endif // BUILDFLAG(ANDROID_JAVA_UI) |
| +} |
| + |
| +} // namespace previews |