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

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

Issue 2874663005: [Page Load Metrics] Add mojom file to page load metrics. (Closed)
Patch Set: Remove unnecessary variable Created 3 years, 7 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
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/amp_page_load_metrics_obser ver.h" 5 #include "chrome/browser/page_load_metrics/observers/amp_page_load_metrics_obser ver.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/optional.h" 9 #include "base/optional.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 71 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
72 AMPPageLoadMetricsObserver::OnCommit( 72 AMPPageLoadMetricsObserver::OnCommit(
73 content::NavigationHandle* navigation_handle) { 73 content::NavigationHandle* navigation_handle) {
74 view_type_ = GetAMPViewType(navigation_handle->GetURL()); 74 view_type_ = GetAMPViewType(navigation_handle->GetURL());
75 return (view_type_ != AMPViewType::NONE) ? CONTINUE_OBSERVING 75 return (view_type_ != AMPViewType::NONE) ? CONTINUE_OBSERVING
76 : STOP_OBSERVING; 76 : STOP_OBSERVING;
77 } 77 }
78 78
79 void AMPPageLoadMetricsObserver::OnDomContentLoadedEventStart( 79 void AMPPageLoadMetricsObserver::OnDomContentLoadedEventStart(
80 const page_load_metrics::PageLoadTiming& timing, 80 const page_load_metrics::mojom::PageLoadTiming& timing,
81 const page_load_metrics::PageLoadExtraInfo& info) { 81 const page_load_metrics::PageLoadExtraInfo& info) {
82 if (!WasStartedInForegroundOptionalEventInForeground( 82 if (!WasStartedInForegroundOptionalEventInForeground(
83 timing.document_timing.dom_content_loaded_event_start, info)) { 83 timing.document_timing->dom_content_loaded_event_start, info)) {
84 return; 84 return;
85 } 85 }
86 RECORD_HISTOGRAM_FOR_TYPE( 86 RECORD_HISTOGRAM_FOR_TYPE(
87 kHistogramAMPDOMContentLoadedEventFired, view_type_, 87 kHistogramAMPDOMContentLoadedEventFired, view_type_,
88 timing.document_timing.dom_content_loaded_event_start.value()); 88 timing.document_timing->dom_content_loaded_event_start.value());
89 } 89 }
90 90
91 void AMPPageLoadMetricsObserver::OnLoadEventStart( 91 void AMPPageLoadMetricsObserver::OnLoadEventStart(
92 const page_load_metrics::PageLoadTiming& timing, 92 const page_load_metrics::mojom::PageLoadTiming& timing,
93 const page_load_metrics::PageLoadExtraInfo& info) { 93 const page_load_metrics::PageLoadExtraInfo& info) {
94 if (!WasStartedInForegroundOptionalEventInForeground( 94 if (!WasStartedInForegroundOptionalEventInForeground(
95 timing.document_timing.load_event_start, info)) { 95 timing.document_timing->load_event_start, info)) {
96 return; 96 return;
97 } 97 }
98 RECORD_HISTOGRAM_FOR_TYPE(kHistogramAMPLoadEventFired, view_type_, 98 RECORD_HISTOGRAM_FOR_TYPE(kHistogramAMPLoadEventFired, view_type_,
99 timing.document_timing.load_event_start.value()); 99 timing.document_timing->load_event_start.value());
100 } 100 }
101 101
102 void AMPPageLoadMetricsObserver::OnFirstLayout( 102 void AMPPageLoadMetricsObserver::OnFirstLayout(
103 const page_load_metrics::PageLoadTiming& timing, 103 const page_load_metrics::mojom::PageLoadTiming& timing,
104 const page_load_metrics::PageLoadExtraInfo& info) { 104 const page_load_metrics::PageLoadExtraInfo& info) {
105 if (!WasStartedInForegroundOptionalEventInForeground( 105 if (!WasStartedInForegroundOptionalEventInForeground(
106 timing.document_timing.first_layout, info)) { 106 timing.document_timing->first_layout, info)) {
107 return; 107 return;
108 } 108 }
109 RECORD_HISTOGRAM_FOR_TYPE(kHistogramAMPFirstLayout, view_type_, 109 RECORD_HISTOGRAM_FOR_TYPE(kHistogramAMPFirstLayout, view_type_,
110 timing.document_timing.first_layout.value()); 110 timing.document_timing->first_layout.value());
111 } 111 }
112 112
113 void AMPPageLoadMetricsObserver::OnFirstContentfulPaintInPage( 113 void AMPPageLoadMetricsObserver::OnFirstContentfulPaintInPage(
114 const page_load_metrics::PageLoadTiming& timing, 114 const page_load_metrics::mojom::PageLoadTiming& timing,
115 const page_load_metrics::PageLoadExtraInfo& info) { 115 const page_load_metrics::PageLoadExtraInfo& info) {
116 if (!WasStartedInForegroundOptionalEventInForeground( 116 if (!WasStartedInForegroundOptionalEventInForeground(
117 timing.paint_timing.first_contentful_paint, info)) { 117 timing.paint_timing->first_contentful_paint, info)) {
118 return; 118 return;
119 } 119 }
120 RECORD_HISTOGRAM_FOR_TYPE(kHistogramAMPFirstContentfulPaint, view_type_, 120 RECORD_HISTOGRAM_FOR_TYPE(
121 timing.paint_timing.first_contentful_paint.value()); 121 kHistogramAMPFirstContentfulPaint, view_type_,
122 timing.paint_timing->first_contentful_paint.value());
122 } 123 }
123 124
124 void AMPPageLoadMetricsObserver::OnParseStart( 125 void AMPPageLoadMetricsObserver::OnParseStart(
125 const page_load_metrics::PageLoadTiming& timing, 126 const page_load_metrics::mojom::PageLoadTiming& timing,
126 const page_load_metrics::PageLoadExtraInfo& info) { 127 const page_load_metrics::PageLoadExtraInfo& info) {
127 if (!WasStartedInForegroundOptionalEventInForeground( 128 if (!WasStartedInForegroundOptionalEventInForeground(
128 timing.parse_timing.parse_start, info)) { 129 timing.parse_timing->parse_start, info)) {
129 return; 130 return;
130 } 131 }
131 RECORD_HISTOGRAM_FOR_TYPE(kHistogramAMPParseStart, view_type_, 132 RECORD_HISTOGRAM_FOR_TYPE(kHistogramAMPParseStart, view_type_,
132 timing.parse_timing.parse_start.value()); 133 timing.parse_timing->parse_start.value());
133 } 134 }
134 135
135 // static 136 // static
136 AMPPageLoadMetricsObserver::AMPViewType 137 AMPPageLoadMetricsObserver::AMPViewType
137 AMPPageLoadMetricsObserver::GetAMPViewType(const GURL& url) { 138 AMPPageLoadMetricsObserver::GetAMPViewType(const GURL& url) {
138 if (base::EndsWith(url.host(), kAmpCacheHostSuffix, 139 if (base::EndsWith(url.host(), kAmpCacheHostSuffix,
139 base::CompareCase::INSENSITIVE_ASCII)) { 140 base::CompareCase::INSENSITIVE_ASCII)) {
140 return AMPViewType::AMP_CACHE; 141 return AMPViewType::AMP_CACHE;
141 } 142 }
142 143
143 base::Optional<std::string> google_hostname_prefix = 144 base::Optional<std::string> google_hostname_prefix =
144 page_load_metrics::GetGoogleHostnamePrefix(url); 145 page_load_metrics::GetGoogleHostnamePrefix(url);
145 if (!google_hostname_prefix.has_value()) 146 if (!google_hostname_prefix.has_value())
146 return AMPViewType::NONE; 147 return AMPViewType::NONE;
147 148
148 if (google_hostname_prefix.value() == "www" && 149 if (google_hostname_prefix.value() == "www" &&
149 base::StartsWith(url.path_piece(), "/amp/", 150 base::StartsWith(url.path_piece(), "/amp/",
150 base::CompareCase::SENSITIVE)) { 151 base::CompareCase::SENSITIVE)) {
151 return AMPViewType::GOOGLE_SEARCH_AMP_VIEWER; 152 return AMPViewType::GOOGLE_SEARCH_AMP_VIEWER;
152 } 153 }
153 154
154 if (google_hostname_prefix.value() == "news" && 155 if (google_hostname_prefix.value() == "news" &&
155 url.path_piece() == "/news/amp") { 156 url.path_piece() == "/news/amp") {
156 return AMPViewType::GOOGLE_NEWS_AMP_VIEWER; 157 return AMPViewType::GOOGLE_NEWS_AMP_VIEWER;
157 } 158 }
158 return AMPViewType::NONE; 159 return AMPViewType::NONE;
159 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698