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/content/browser/subresource_filter_safe_ browsing_activation_throttle.h" | 9 #include "components/subresource_filter/content/browser/subresource_filter_safe_ browsing_activation_throttle.h" |
10 #include "components/subresource_filter/core/common/activation_decision.h" | 10 #include "components/subresource_filter/core/common/activation_decision.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 navigation_handle)) { | 128 navigation_handle)) { |
129 UMA_HISTOGRAM_ENUMERATION( | 129 UMA_HISTOGRAM_ENUMERATION( |
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 SubresourceFilterMetricsObserver::SubresourceFilterMetricsObserver() | |
139 : scoped_observer_(this) {} | |
140 SubresourceFilterMetricsObserver::~SubresourceFilterMetricsObserver() = default; | |
141 | |
142 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | |
143 SubresourceFilterMetricsObserver::OnStart( | |
144 content::NavigationHandle* navigation_handle, | |
145 const GURL& currently_committed_url, | |
146 bool started_in_foreground) { | |
147 navigation_handle_ = navigation_handle; | |
148 auto* observer_manager = | |
149 subresource_filter::SubresourceFilterObserverManager::FromWebContents( | |
150 navigation_handle->GetWebContents()); | |
151 // |observer_manager| isn't constructed if the feature for subresource | |
152 // filtering isn't enabled. | |
153 if (observer_manager) { | |
154 scoped_observer_.Add(observer_manager); | |
155 return CONTINUE_OBSERVING; | |
156 } | |
157 return STOP_OBSERVING; | |
158 } | |
159 | |
138 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 160 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
139 SubresourceFilterMetricsObserver::FlushMetricsOnAppEnterBackground( | 161 SubresourceFilterMetricsObserver::FlushMetricsOnAppEnterBackground( |
140 const page_load_metrics::mojom::PageLoadTiming& timing, | 162 const page_load_metrics::mojom::PageLoadTiming& timing, |
141 const page_load_metrics::PageLoadExtraInfo& info) { | 163 const page_load_metrics::PageLoadExtraInfo& info) { |
142 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the | 164 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the |
143 // app is about to be backgrounded, as part of the Activity.onPause() | 165 // 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 | 166 // flow. After this method is invoked, Chrome may be killed without further |
145 // notification, so we record final metrics collected up to this point. | 167 // notification, so we record final metrics collected up to this point. |
146 if (info.did_commit) | 168 if (info.did_commit) |
147 OnGoingAway(timing, info, base::TimeTicks::Now()); | 169 OnGoingAway(timing, info, base::TimeTicks::Now()); |
148 return STOP_OBSERVING; | 170 return STOP_OBSERVING; |
149 } | 171 } |
150 | 172 |
151 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 173 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
152 SubresourceFilterMetricsObserver::OnCommit( | 174 SubresourceFilterMetricsObserver::OnCommit( |
153 content::NavigationHandle* navigation_handle, | 175 content::NavigationHandle* navigation_handle, |
154 ukm::SourceId source_id) { | 176 ukm::SourceId source_id) { |
155 const auto* subres_filter = | 177 did_commit_ = true; |
156 ContentSubresourceFilterDriverFactory::FromWebContents( | 178 navigation_handle_ = nullptr; |
157 navigation_handle->GetWebContents()); | 179 DCHECK(scoped_observer_.IsObservingSources()); |
158 if (subres_filter) | 180 DCHECK(activation_decision_.has_value()); |
159 LogActivationDecisionMetrics( | 181 LogActivationDecisionMetrics(navigation_handle, *activation_decision_); |
160 navigation_handle, | 182 scoped_observer_.RemoveAll(); |
161 subres_filter->GetActivationDecisionForLastCommittedPageLoad()); | |
162 return CONTINUE_OBSERVING; | 183 return CONTINUE_OBSERVING; |
163 } | 184 } |
164 | 185 |
165 void SubresourceFilterMetricsObserver::OnComplete( | 186 void SubresourceFilterMetricsObserver::OnComplete( |
166 const page_load_metrics::mojom::PageLoadTiming& timing, | 187 const page_load_metrics::mojom::PageLoadTiming& timing, |
167 const page_load_metrics::PageLoadExtraInfo& info) { | 188 const page_load_metrics::PageLoadExtraInfo& info) { |
168 OnGoingAway(timing, info, base::TimeTicks()); | 189 OnGoingAway(timing, info, base::TimeTicks()); |
169 } | 190 } |
170 | 191 |
171 void SubresourceFilterMetricsObserver::OnLoadedResource( | 192 void SubresourceFilterMetricsObserver::OnLoadedResource( |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 UMA_HISTOGRAM_BOOLEAN(internal::kHistogramSubresourceFilterCount, true); | 312 UMA_HISTOGRAM_BOOLEAN(internal::kHistogramSubresourceFilterCount, true); |
292 } | 313 } |
293 } | 314 } |
294 | 315 |
295 void SubresourceFilterMetricsObserver::MediaStartedPlaying( | 316 void SubresourceFilterMetricsObserver::MediaStartedPlaying( |
296 const content::WebContentsObserver::MediaPlayerInfo& video_type, | 317 const content::WebContentsObserver::MediaPlayerInfo& video_type, |
297 bool is_in_main_frame) { | 318 bool is_in_main_frame) { |
298 played_media_ = true; | 319 played_media_ = true; |
299 } | 320 } |
300 | 321 |
322 void SubresourceFilterMetricsObserver::OnSubresourceFilterGoingAway() { | |
323 scoped_observer_.RemoveAll(); | |
Bryan McQuade
2017/06/07 00:03:24
can this ever be invoked before commit, in which c
Charlie Harrison
2017/06/07 00:26:40
It shouldn't happen but we can guard against it in
| |
324 } | |
325 | |
326 void SubresourceFilterMetricsObserver::OnPageActivationComputed( | |
327 content::NavigationHandle* navigation_handle, | |
328 subresource_filter::ActivationDecision activation_decision, | |
329 const subresource_filter::ActivationState& activation_state) { | |
330 // Make sure we don't get notifications from subsequent navigations. | |
331 if (navigation_handle != navigation_handle_) | |
332 return; | |
333 // Ensure this will always be called at most once before commit. | |
334 DCHECK(!did_commit_); | |
335 DCHECK(!activation_decision_); | |
336 activation_decision_ = activation_decision; | |
337 } | |
338 | |
301 void SubresourceFilterMetricsObserver::OnGoingAway( | 339 void SubresourceFilterMetricsObserver::OnGoingAway( |
302 const page_load_metrics::mojom::PageLoadTiming& timing, | 340 const page_load_metrics::mojom::PageLoadTiming& timing, |
303 const page_load_metrics::PageLoadExtraInfo& info, | 341 const page_load_metrics::PageLoadExtraInfo& info, |
304 base::TimeTicks app_background_time) { | 342 base::TimeTicks app_background_time) { |
305 if (!subresource_filter_observed_) | 343 if (!subresource_filter_observed_) |
306 return; | 344 return; |
307 | 345 |
308 PAGE_RESOURCE_COUNT_HISTOGRAM( | 346 PAGE_RESOURCE_COUNT_HISTOGRAM( |
309 internal::kHistogramSubresourceFilterNetworkResources, | 347 internal::kHistogramSubresourceFilterNetworkResources, |
310 num_network_resources_); | 348 num_network_resources_); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 foreground_duration.value()); | 405 foreground_duration.value()); |
368 if (timing.paint_timing->first_paint && | 406 if (timing.paint_timing->first_paint && |
369 timing.paint_timing->first_paint < foreground_duration) { | 407 timing.paint_timing->first_paint < foreground_duration) { |
370 PAGE_LOAD_LONG_HISTOGRAM( | 408 PAGE_LOAD_LONG_HISTOGRAM( |
371 internal::kHistogramSubresourceFilterForegroundDurationAfterPaint, | 409 internal::kHistogramSubresourceFilterForegroundDurationAfterPaint, |
372 foreground_duration.value() - | 410 foreground_duration.value() - |
373 timing.paint_timing->first_paint.value()); | 411 timing.paint_timing->first_paint.value()); |
374 } | 412 } |
375 } | 413 } |
376 } | 414 } |
OLD | NEW |