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

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

Issue 2893183002: [subresource_filter] Use the SubresourceFilterObserver for PageLoadMetrics (Closed)
Patch Set: Notify all stats Created 3 years, 6 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 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
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 auto* observer_manager =
148 subresource_filter::SubresourceFilterObserverManager::FromWebContents(
149 navigation_handle->GetWebContents());
150 // |observer_manager| isn't always constructed in unit tests, or if the master
151 // feature for subresource filtering isn't enabled.
152 if (observer_manager)
153 scoped_observer_.Add(observer_manager);
154 return CONTINUE_OBSERVING;
155 }
156
138 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 157 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
139 SubresourceFilterMetricsObserver::FlushMetricsOnAppEnterBackground( 158 SubresourceFilterMetricsObserver::FlushMetricsOnAppEnterBackground(
140 const page_load_metrics::mojom::PageLoadTiming& timing, 159 const page_load_metrics::mojom::PageLoadTiming& timing,
141 const page_load_metrics::PageLoadExtraInfo& info) { 160 const page_load_metrics::PageLoadExtraInfo& info) {
142 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the 161 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the
143 // app is about to be backgrounded, as part of the Activity.onPause() 162 // 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 163 // flow. After this method is invoked, Chrome may be killed without further
145 // notification, so we record final metrics collected up to this point. 164 // notification, so we record final metrics collected up to this point.
146 if (info.did_commit) 165 if (info.did_commit)
147 OnGoingAway(timing, info, base::TimeTicks::Now()); 166 OnGoingAway(timing, info, base::TimeTicks::Now());
148 return STOP_OBSERVING; 167 return STOP_OBSERVING;
149 } 168 }
150 169
151 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 170 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
152 SubresourceFilterMetricsObserver::OnCommit( 171 SubresourceFilterMetricsObserver::OnCommit(
153 content::NavigationHandle* navigation_handle, 172 content::NavigationHandle* navigation_handle,
154 ukm::SourceId source_id) { 173 ukm::SourceId source_id) {
155 const auto* subres_filter = 174 // If |this| is registered as an observer, it should have received the
156 ContentSubresourceFilterDriverFactory::FromWebContents( 175 // activation decision by now.
157 navigation_handle->GetWebContents()); 176 DCHECK(!scoped_observer_.IsObservingSources() ||
Bryan McQuade 2017/06/05 13:47:04 if we get to the commit and we're no longer observ
Charlie Harrison 2017/06/05 18:32:38 As discussed offline there is some confusion here.
158 if (subres_filter) 177 activation_decision_.has_value());
159 LogActivationDecisionMetrics( 178 if (activation_decision_)
160 navigation_handle, 179 LogActivationDecisionMetrics(navigation_handle, *activation_decision_);
161 subres_filter->GetActivationDecisionForLastCommittedPageLoad());
162 return CONTINUE_OBSERVING; 180 return CONTINUE_OBSERVING;
163 } 181 }
164 182
165 void SubresourceFilterMetricsObserver::OnComplete( 183 void SubresourceFilterMetricsObserver::OnComplete(
166 const page_load_metrics::mojom::PageLoadTiming& timing, 184 const page_load_metrics::mojom::PageLoadTiming& timing,
167 const page_load_metrics::PageLoadExtraInfo& info) { 185 const page_load_metrics::PageLoadExtraInfo& info) {
168 OnGoingAway(timing, info, base::TimeTicks()); 186 OnGoingAway(timing, info, base::TimeTicks());
169 } 187 }
170 188
171 void SubresourceFilterMetricsObserver::OnLoadedResource( 189 void SubresourceFilterMetricsObserver::OnLoadedResource(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 UMA_HISTOGRAM_BOOLEAN(internal::kHistogramSubresourceFilterCount, true); 309 UMA_HISTOGRAM_BOOLEAN(internal::kHistogramSubresourceFilterCount, true);
292 } 310 }
293 } 311 }
294 312
295 void SubresourceFilterMetricsObserver::MediaStartedPlaying( 313 void SubresourceFilterMetricsObserver::MediaStartedPlaying(
296 const content::WebContentsObserver::MediaPlayerInfo& video_type, 314 const content::WebContentsObserver::MediaPlayerInfo& video_type,
297 bool is_in_main_frame) { 315 bool is_in_main_frame) {
298 played_media_ = true; 316 played_media_ = true;
299 } 317 }
300 318
319 void SubresourceFilterMetricsObserver::OnSubresourceFilterGoingAway() {
320 scoped_observer_.RemoveAll();
Bryan McQuade 2017/06/05 13:47:04 does it make sense to move this logic into the bas
Charlie Harrison 2017/06/05 18:32:38 I'm not sure. I think most implementations will wa
321 }
322
323 void SubresourceFilterMetricsObserver::OnPageActivationComputed(
324 content::NavigationHandle* navigation_handle,
325 subresource_filter::ActivationDecision activation_decision,
326 const subresource_filter::ActivationState& activation_state) {
327 activation_decision_ = activation_decision;
Bryan McQuade 2017/06/05 13:47:04 can we add a DCHECK(!did_commit_); here (and set t
Charlie Harrison 2017/06/05 18:32:38 Done, great idea.
328 }
329
301 void SubresourceFilterMetricsObserver::OnGoingAway( 330 void SubresourceFilterMetricsObserver::OnGoingAway(
302 const page_load_metrics::mojom::PageLoadTiming& timing, 331 const page_load_metrics::mojom::PageLoadTiming& timing,
303 const page_load_metrics::PageLoadExtraInfo& info, 332 const page_load_metrics::PageLoadExtraInfo& info,
304 base::TimeTicks app_background_time) { 333 base::TimeTicks app_background_time) {
305 if (!subresource_filter_observed_) 334 if (!subresource_filter_observed_)
306 return; 335 return;
307 336
308 PAGE_RESOURCE_COUNT_HISTOGRAM( 337 PAGE_RESOURCE_COUNT_HISTOGRAM(
309 internal::kHistogramSubresourceFilterNetworkResources, 338 internal::kHistogramSubresourceFilterNetworkResources,
310 num_network_resources_); 339 num_network_resources_);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 foreground_duration.value()); 396 foreground_duration.value());
368 if (timing.paint_timing->first_paint && 397 if (timing.paint_timing->first_paint &&
369 timing.paint_timing->first_paint < foreground_duration) { 398 timing.paint_timing->first_paint < foreground_duration) {
370 PAGE_LOAD_LONG_HISTOGRAM( 399 PAGE_LOAD_LONG_HISTOGRAM(
371 internal::kHistogramSubresourceFilterForegroundDurationAfterPaint, 400 internal::kHistogramSubresourceFilterForegroundDurationAfterPaint,
372 foreground_duration.value() - 401 foreground_duration.value() -
373 timing.paint_timing->first_paint.value()); 402 timing.paint_timing->first_paint.value());
374 } 403 }
375 } 404 }
376 } 405 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698