Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(581)

Side by Side Diff: chrome/browser/page_load_metrics/observers/previews_page_load_metrics_observer.cc

Issue 2245213002: Add PageLoad.* metrics for Offline Previews (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: csharrison comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 kHistogramDOMContentLoadedEventFired[] =
26 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming."
27 "NavigationToDOMContentLoadedEventFired";
28 const char kHistogramFirstLayout[] =
29 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming."
30 "NavigationToFirstLayout";
31 const char kHistogramLoadEventFired[] =
32 "PageLoad.Clients.Previews.OfflinePages.DocumentTiming."
33 "NavigationToLoadEventFired";
34 const char kHistogramFirstContentfulPaint[] =
35 "PageLoad.Clients.Previews.OfflinePages.PaintTiming."
36 "NavigationToFirstContentfulPaint";
37 const char kHistogramParseStart[] =
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(internal::kHistogramDOMContentLoadedEventFired,
61 timing.dom_content_loaded_event_start.value());
62 }
63
64 void PreviewsPageLoadMetricsObserver::OnLoadEventStart(
65 const page_load_metrics::PageLoadTiming& timing,
66 const page_load_metrics::PageLoadExtraInfo& info) {
67 if (!is_offline_preview_ ||
68 !WasStartedInForegroundOptionalEventInForeground(
69 timing.dom_content_loaded_event_start, info)) {
70 return;
71 }
72 PAGE_LOAD_HISTOGRAM(internal::kHistogramLoadEventFired,
73 timing.load_event_start.value());
74 }
75
76 void PreviewsPageLoadMetricsObserver::OnFirstLayout(
77 const page_load_metrics::PageLoadTiming& timing,
78 const page_load_metrics::PageLoadExtraInfo& info) {
79 if (!is_offline_preview_ ||
80 !WasStartedInForegroundOptionalEventInForeground(
81 timing.dom_content_loaded_event_start, info)) {
82 return;
83 }
84 PAGE_LOAD_HISTOGRAM(internal::kHistogramFirstLayout,
85 timing.first_layout.value());
86 }
87
88 void PreviewsPageLoadMetricsObserver::OnFirstContentfulPaint(
89 const page_load_metrics::PageLoadTiming& timing,
90 const page_load_metrics::PageLoadExtraInfo& info) {
91 if (!is_offline_preview_ ||
92 !WasStartedInForegroundOptionalEventInForeground(
93 timing.dom_content_loaded_event_start, info)) {
94 return;
95 }
96 PAGE_LOAD_HISTOGRAM(internal::kHistogramFirstContentfulPaint,
97 timing.first_contentful_paint.value());
98 }
99
100 void PreviewsPageLoadMetricsObserver::OnParseStart(
101 const page_load_metrics::PageLoadTiming& timing,
102 const page_load_metrics::PageLoadExtraInfo& info) {
103 if (!is_offline_preview_ ||
104 !WasStartedInForegroundOptionalEventInForeground(
105 timing.dom_content_loaded_event_start, info)) {
106 return;
107 }
108 PAGE_LOAD_HISTOGRAM(internal::kHistogramParseStart,
109 timing.parse_start.value());
110 }
111
112 bool PreviewsPageLoadMetricsObserver::IsOfflinePreview(
113 content::WebContents* web_contents) const {
114 #if BUILDFLAG(ANDROID_JAVA_UI)
115 offline_pages::OfflinePageTabHelper* tab_helper =
116 offline_pages::OfflinePageTabHelper::FromWebContents(web_contents);
117 return tab_helper && tab_helper->is_offline_preview();
118 #else
119 return false;
120 #endif // BUILDFLAG(ANDROID_JAVA_UI)
121 }
122
123 } // namespace previews
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698