OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/subresource_filter_metrics_
observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_
observer.h" |
6 | 6 |
7 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 7 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
8 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" | 8 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" |
9 #include "components/subresource_filter/core/common/activation_decision.h" | 9 #include "components/subresource_filter/core/common/activation_decision.h" |
10 #include "third_party/WebKit/public/platform/WebLoadingBehaviorFlag.h" | 10 #include "third_party/WebKit/public/platform/WebLoadingBehaviorFlag.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 internal::kHistogramSubresourceFilterActivationDecisionReload, | 130 internal::kHistogramSubresourceFilterActivationDecisionReload, |
131 static_cast<int>(decision), | 131 static_cast<int>(decision), |
132 static_cast<int>(ActivationDecision::ACTIVATION_DECISION_MAX)); | 132 static_cast<int>(ActivationDecision::ACTIVATION_DECISION_MAX)); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 } // namespace | 136 } // namespace |
137 | 137 |
138 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 138 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
139 SubresourceFilterMetricsObserver::FlushMetricsOnAppEnterBackground( | 139 SubresourceFilterMetricsObserver::FlushMetricsOnAppEnterBackground( |
140 const page_load_metrics::PageLoadTiming& timing, | 140 const page_load_metrics::mojom::PageLoadTiming& timing, |
141 const page_load_metrics::PageLoadExtraInfo& info) { | 141 const page_load_metrics::PageLoadExtraInfo& info) { |
142 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the | 142 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the |
143 // app is about to be backgrounded, as part of the Activity.onPause() | 143 // app is about to be backgrounded, as part of the Activity.onPause() |
144 // flow. After this method is invoked, Chrome may be killed without further | 144 // flow. After this method is invoked, Chrome may be killed without further |
145 // notification, so we record final metrics collected up to this point. | 145 // notification, so we record final metrics collected up to this point. |
146 if (info.did_commit) | 146 if (info.did_commit) |
147 OnGoingAway(timing, info, base::TimeTicks::Now()); | 147 OnGoingAway(timing, info, base::TimeTicks::Now()); |
148 return STOP_OBSERVING; | 148 return STOP_OBSERVING; |
149 } | 149 } |
150 | 150 |
151 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 151 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
152 SubresourceFilterMetricsObserver::OnCommit( | 152 SubresourceFilterMetricsObserver::OnCommit( |
153 content::NavigationHandle* navigation_handle) { | 153 content::NavigationHandle* navigation_handle) { |
154 const auto* subres_filter = | 154 const auto* subres_filter = |
155 ContentSubresourceFilterDriverFactory::FromWebContents( | 155 ContentSubresourceFilterDriverFactory::FromWebContents( |
156 navigation_handle->GetWebContents()); | 156 navigation_handle->GetWebContents()); |
157 if (subres_filter) | 157 if (subres_filter) |
158 LogActivationDecisionMetrics( | 158 LogActivationDecisionMetrics( |
159 navigation_handle, | 159 navigation_handle, |
160 subres_filter->GetActivationDecisionForLastCommittedPageLoad()); | 160 subres_filter->GetActivationDecisionForLastCommittedPageLoad()); |
161 return CONTINUE_OBSERVING; | 161 return CONTINUE_OBSERVING; |
162 } | 162 } |
163 | 163 |
164 void SubresourceFilterMetricsObserver::OnComplete( | 164 void SubresourceFilterMetricsObserver::OnComplete( |
165 const page_load_metrics::PageLoadTiming& timing, | 165 const page_load_metrics::mojom::PageLoadTiming& timing, |
166 const page_load_metrics::PageLoadExtraInfo& info) { | 166 const page_load_metrics::PageLoadExtraInfo& info) { |
167 OnGoingAway(timing, info, base::TimeTicks()); | 167 OnGoingAway(timing, info, base::TimeTicks()); |
168 } | 168 } |
169 | 169 |
170 void SubresourceFilterMetricsObserver::OnLoadedResource( | 170 void SubresourceFilterMetricsObserver::OnLoadedResource( |
171 const page_load_metrics::ExtraRequestCompleteInfo& | 171 const page_load_metrics::ExtraRequestCompleteInfo& |
172 extra_request_complete_info) { | 172 extra_request_complete_info) { |
173 if (extra_request_complete_info.was_cached) { | 173 if (extra_request_complete_info.was_cached) { |
174 ++num_cache_resources_; | 174 ++num_cache_resources_; |
175 cache_bytes_ += extra_request_complete_info.raw_body_bytes; | 175 cache_bytes_ += extra_request_complete_info.raw_body_bytes; |
176 } else { | 176 } else { |
177 ++num_network_resources_; | 177 ++num_network_resources_; |
178 network_bytes_ += extra_request_complete_info.raw_body_bytes; | 178 network_bytes_ += extra_request_complete_info.raw_body_bytes; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 void SubresourceFilterMetricsObserver::OnParseStop( | 182 void SubresourceFilterMetricsObserver::OnParseStop( |
183 const page_load_metrics::PageLoadTiming& timing, | 183 const page_load_metrics::mojom::PageLoadTiming& timing, |
184 const page_load_metrics::PageLoadExtraInfo& info) { | 184 const page_load_metrics::PageLoadExtraInfo& info) { |
185 if (!subresource_filter_observed_) | 185 if (!subresource_filter_observed_) |
186 return; | 186 return; |
187 | 187 |
188 if (!WasStartedInForegroundOptionalEventInForeground( | 188 if (!WasStartedInForegroundOptionalEventInForeground( |
189 timing.parse_timing.parse_stop, info)) | 189 timing.parse_timing->parse_stop, info)) |
190 return; | 190 return; |
191 | 191 |
192 base::TimeDelta parse_duration = timing.parse_timing.parse_stop.value() - | 192 base::TimeDelta parse_duration = timing.parse_timing->parse_stop.value() - |
193 timing.parse_timing.parse_start.value(); | 193 timing.parse_timing->parse_start.value(); |
194 PAGE_LOAD_HISTOGRAM(internal::kHistogramSubresourceFilterParseDuration, | 194 PAGE_LOAD_HISTOGRAM(internal::kHistogramSubresourceFilterParseDuration, |
195 parse_duration); | 195 parse_duration); |
196 PAGE_LOAD_HISTOGRAM( | 196 PAGE_LOAD_HISTOGRAM( |
197 internal::kHistogramSubresourceFilterParseBlockedOnScriptLoad, | 197 internal::kHistogramSubresourceFilterParseBlockedOnScriptLoad, |
198 timing.parse_timing.parse_blocked_on_script_load_duration.value()); | 198 timing.parse_timing->parse_blocked_on_script_load_duration.value()); |
199 PAGE_LOAD_HISTOGRAM( | 199 PAGE_LOAD_HISTOGRAM( |
200 internal:: | 200 internal:: |
201 kHistogramSubresourceFilterParseBlockedOnScriptLoadDocumentWrite, | 201 kHistogramSubresourceFilterParseBlockedOnScriptLoadDocumentWrite, |
202 timing.parse_timing | 202 timing.parse_timing |
203 .parse_blocked_on_script_load_from_document_write_duration.value()); | 203 ->parse_blocked_on_script_load_from_document_write_duration.value()); |
204 PAGE_LOAD_HISTOGRAM( | 204 PAGE_LOAD_HISTOGRAM( |
205 internal::kHistogramSubresourceFilterParseBlockedOnScriptExecution, | 205 internal::kHistogramSubresourceFilterParseBlockedOnScriptExecution, |
206 timing.parse_timing.parse_blocked_on_script_execution_duration.value()); | 206 timing.parse_timing->parse_blocked_on_script_execution_duration.value()); |
207 PAGE_LOAD_HISTOGRAM( | 207 PAGE_LOAD_HISTOGRAM( |
208 internal:: | 208 internal:: |
209 kHistogramSubresourceFilterParseBlockedOnScriptExecutionDocumentWrite, | 209 kHistogramSubresourceFilterParseBlockedOnScriptExecutionDocumentWrite, |
210 timing.parse_timing | 210 timing.parse_timing |
211 .parse_blocked_on_script_execution_from_document_write_duration | 211 ->parse_blocked_on_script_execution_from_document_write_duration |
212 .value()); | 212 .value()); |
213 } | 213 } |
214 | 214 |
215 void SubresourceFilterMetricsObserver::OnFirstContentfulPaintInPage( | 215 void SubresourceFilterMetricsObserver::OnFirstContentfulPaintInPage( |
216 const page_load_metrics::PageLoadTiming& timing, | 216 const page_load_metrics::mojom::PageLoadTiming& timing, |
217 const page_load_metrics::PageLoadExtraInfo& info) { | 217 const page_load_metrics::PageLoadExtraInfo& info) { |
218 if (!subresource_filter_observed_) | 218 if (!subresource_filter_observed_) |
219 return; | 219 return; |
220 | 220 |
221 if (WasStartedInForegroundOptionalEventInForeground( | 221 if (WasStartedInForegroundOptionalEventInForeground( |
222 timing.paint_timing.first_contentful_paint, info)) { | 222 timing.paint_timing->first_contentful_paint, info)) { |
223 PAGE_LOAD_HISTOGRAM( | 223 PAGE_LOAD_HISTOGRAM( |
224 internal::kHistogramSubresourceFilterFirstContentfulPaint, | 224 internal::kHistogramSubresourceFilterFirstContentfulPaint, |
225 timing.paint_timing.first_contentful_paint.value()); | 225 timing.paint_timing->first_contentful_paint.value()); |
226 PAGE_LOAD_HISTOGRAM( | 226 PAGE_LOAD_HISTOGRAM( |
227 internal::kHistogramSubresourceFilterParseStartToFirstContentfulPaint, | 227 internal::kHistogramSubresourceFilterParseStartToFirstContentfulPaint, |
228 timing.paint_timing.first_contentful_paint.value() - | 228 timing.paint_timing->first_contentful_paint.value() - |
229 timing.parse_timing.parse_start.value()); | 229 timing.parse_timing->parse_start.value()); |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 void SubresourceFilterMetricsObserver:: | 233 void SubresourceFilterMetricsObserver:: |
234 OnFirstMeaningfulPaintInMainFrameDocument( | 234 OnFirstMeaningfulPaintInMainFrameDocument( |
235 const page_load_metrics::PageLoadTiming& timing, | 235 const page_load_metrics::mojom::PageLoadTiming& timing, |
236 const page_load_metrics::PageLoadExtraInfo& info) { | 236 const page_load_metrics::PageLoadExtraInfo& info) { |
237 if (!subresource_filter_observed_) | 237 if (!subresource_filter_observed_) |
238 return; | 238 return; |
239 | 239 |
240 if (WasStartedInForegroundOptionalEventInForeground( | 240 if (WasStartedInForegroundOptionalEventInForeground( |
241 timing.paint_timing.first_meaningful_paint, info)) { | 241 timing.paint_timing->first_meaningful_paint, info)) { |
242 PAGE_LOAD_HISTOGRAM( | 242 PAGE_LOAD_HISTOGRAM( |
243 internal::kHistogramSubresourceFilterFirstMeaningfulPaint, | 243 internal::kHistogramSubresourceFilterFirstMeaningfulPaint, |
244 timing.paint_timing.first_meaningful_paint.value()); | 244 timing.paint_timing->first_meaningful_paint.value()); |
245 PAGE_LOAD_HISTOGRAM( | 245 PAGE_LOAD_HISTOGRAM( |
246 internal::kHistogramSubresourceFilterParseStartToFirstMeaningfulPaint, | 246 internal::kHistogramSubresourceFilterParseStartToFirstMeaningfulPaint, |
247 timing.paint_timing.first_meaningful_paint.value() - | 247 timing.paint_timing->first_meaningful_paint.value() - |
248 timing.parse_timing.parse_start.value()); | 248 timing.parse_timing->parse_start.value()); |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 void SubresourceFilterMetricsObserver::OnDomContentLoadedEventStart( | 252 void SubresourceFilterMetricsObserver::OnDomContentLoadedEventStart( |
253 const page_load_metrics::PageLoadTiming& timing, | 253 const page_load_metrics::mojom::PageLoadTiming& timing, |
254 const page_load_metrics::PageLoadExtraInfo& info) { | 254 const page_load_metrics::PageLoadExtraInfo& info) { |
255 if (!subresource_filter_observed_) | 255 if (!subresource_filter_observed_) |
256 return; | 256 return; |
257 | 257 |
258 if (WasStartedInForegroundOptionalEventInForeground( | 258 if (WasStartedInForegroundOptionalEventInForeground( |
259 timing.document_timing.dom_content_loaded_event_start, info)) { | 259 timing.document_timing->dom_content_loaded_event_start, info)) { |
260 PAGE_LOAD_HISTOGRAM( | 260 PAGE_LOAD_HISTOGRAM( |
261 internal::kHistogramSubresourceFilterDomContentLoaded, | 261 internal::kHistogramSubresourceFilterDomContentLoaded, |
262 timing.document_timing.dom_content_loaded_event_start.value()); | 262 timing.document_timing->dom_content_loaded_event_start.value()); |
263 } | 263 } |
264 } | 264 } |
265 | 265 |
266 void SubresourceFilterMetricsObserver::OnLoadEventStart( | 266 void SubresourceFilterMetricsObserver::OnLoadEventStart( |
267 const page_load_metrics::PageLoadTiming& timing, | 267 const page_load_metrics::mojom::PageLoadTiming& timing, |
268 const page_load_metrics::PageLoadExtraInfo& info) { | 268 const page_load_metrics::PageLoadExtraInfo& info) { |
269 if (!subresource_filter_observed_) | 269 if (!subresource_filter_observed_) |
270 return; | 270 return; |
271 | 271 |
272 if (WasStartedInForegroundOptionalEventInForeground( | 272 if (WasStartedInForegroundOptionalEventInForeground( |
273 timing.document_timing.load_event_start, info)) { | 273 timing.document_timing->load_event_start, info)) { |
274 PAGE_LOAD_HISTOGRAM(internal::kHistogramSubresourceFilterLoad, | 274 PAGE_LOAD_HISTOGRAM(internal::kHistogramSubresourceFilterLoad, |
275 timing.document_timing.load_event_start.value()); | 275 timing.document_timing->load_event_start.value()); |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 void SubresourceFilterMetricsObserver::OnLoadingBehaviorObserved( | 279 void SubresourceFilterMetricsObserver::OnLoadingBehaviorObserved( |
280 const page_load_metrics::PageLoadExtraInfo& info) { | 280 const page_load_metrics::PageLoadExtraInfo& info) { |
281 if (subresource_filter_observed_) | 281 if (subresource_filter_observed_) |
282 return; | 282 return; |
283 | 283 |
284 subresource_filter_observed_ = | 284 subresource_filter_observed_ = |
285 page_load_metrics::DidObserveLoadingBehaviorInAnyFrame( | 285 page_load_metrics::DidObserveLoadingBehaviorInAnyFrame( |
286 info, blink::WebLoadingBehaviorFlag:: | 286 info, blink::WebLoadingBehaviorFlag:: |
287 kWebLoadingBehaviorSubresourceFilterMatch); | 287 kWebLoadingBehaviorSubresourceFilterMatch); |
288 | 288 |
289 if (subresource_filter_observed_) { | 289 if (subresource_filter_observed_) { |
290 UMA_HISTOGRAM_BOOLEAN(internal::kHistogramSubresourceFilterCount, true); | 290 UMA_HISTOGRAM_BOOLEAN(internal::kHistogramSubresourceFilterCount, true); |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 void SubresourceFilterMetricsObserver::MediaStartedPlaying( | 294 void SubresourceFilterMetricsObserver::MediaStartedPlaying( |
295 const content::WebContentsObserver::MediaPlayerInfo& video_type, | 295 const content::WebContentsObserver::MediaPlayerInfo& video_type, |
296 bool is_in_main_frame) { | 296 bool is_in_main_frame) { |
297 played_media_ = true; | 297 played_media_ = true; |
298 } | 298 } |
299 | 299 |
300 void SubresourceFilterMetricsObserver::OnGoingAway( | 300 void SubresourceFilterMetricsObserver::OnGoingAway( |
301 const page_load_metrics::PageLoadTiming& timing, | 301 const page_load_metrics::mojom::PageLoadTiming& timing, |
302 const page_load_metrics::PageLoadExtraInfo& info, | 302 const page_load_metrics::PageLoadExtraInfo& info, |
303 base::TimeTicks app_background_time) { | 303 base::TimeTicks app_background_time) { |
304 if (!subresource_filter_observed_) | 304 if (!subresource_filter_observed_) |
305 return; | 305 return; |
306 | 306 |
307 PAGE_RESOURCE_COUNT_HISTOGRAM( | 307 PAGE_RESOURCE_COUNT_HISTOGRAM( |
308 internal::kHistogramSubresourceFilterNetworkResources, | 308 internal::kHistogramSubresourceFilterNetworkResources, |
309 num_network_resources_); | 309 num_network_resources_); |
310 PAGE_RESOURCE_COUNT_HISTOGRAM( | 310 PAGE_RESOURCE_COUNT_HISTOGRAM( |
311 internal::kHistogramSubresourceFilterCacheResources, | 311 internal::kHistogramSubresourceFilterCacheResources, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 PAGE_BYTES_HISTOGRAM(internal::kHistogramSubresourceFilterNoMediaTotalBytes, | 357 PAGE_BYTES_HISTOGRAM(internal::kHistogramSubresourceFilterNoMediaTotalBytes, |
358 cache_bytes_ + network_bytes_); | 358 cache_bytes_ + network_bytes_); |
359 } | 359 } |
360 | 360 |
361 base::Optional<base::TimeDelta> foreground_duration = | 361 base::Optional<base::TimeDelta> foreground_duration = |
362 GetInitialForegroundDuration(info, app_background_time); | 362 GetInitialForegroundDuration(info, app_background_time); |
363 if (foreground_duration) { | 363 if (foreground_duration) { |
364 PAGE_LOAD_LONG_HISTOGRAM( | 364 PAGE_LOAD_LONG_HISTOGRAM( |
365 internal::kHistogramSubresourceFilterForegroundDuration, | 365 internal::kHistogramSubresourceFilterForegroundDuration, |
366 foreground_duration.value()); | 366 foreground_duration.value()); |
367 if (timing.paint_timing.first_paint && | 367 if (timing.paint_timing->first_paint && |
368 timing.paint_timing.first_paint < foreground_duration) { | 368 timing.paint_timing->first_paint < foreground_duration) { |
369 PAGE_LOAD_LONG_HISTOGRAM( | 369 PAGE_LOAD_LONG_HISTOGRAM( |
370 internal::kHistogramSubresourceFilterForegroundDurationAfterPaint, | 370 internal::kHistogramSubresourceFilterForegroundDurationAfterPaint, |
371 foreground_duration.value() - | 371 foreground_duration.value() - |
372 timing.paint_timing.first_paint.value()); | 372 timing.paint_timing->first_paint.value()); |
373 } | 373 } |
374 } | 374 } |
375 } | 375 } |
OLD | NEW |