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

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: bmcquade review 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 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 // Just in case OnSubresourceFilterGoingAway is called before this point.
156 ContentSubresourceFilterDriverFactory::FromWebContents( 178 if (!activation_decision_) {
157 navigation_handle->GetWebContents()); 179 DCHECK(!scoped_observer_.IsObservingSources());
158 if (subres_filter) 180 return STOP_OBSERVING;
159 LogActivationDecisionMetrics( 181 }
160 navigation_handle, 182
161 subres_filter->GetActivationDecisionForLastCommittedPageLoad()); 183 did_commit_ = true;
184 navigation_handle_ = nullptr;
185 DCHECK(scoped_observer_.IsObservingSources());
Bryan McQuade 2017/06/07 00:28:00 this DCHECK could probably be removed, but it's op
Charlie Harrison 2017/06/07 01:15:10 Yeah I decided to keep it, just to enforce that we
186 LogActivationDecisionMetrics(navigation_handle, *activation_decision_);
187 scoped_observer_.RemoveAll();
162 return CONTINUE_OBSERVING; 188 return CONTINUE_OBSERVING;
163 } 189 }
164 190
165 void SubresourceFilterMetricsObserver::OnComplete( 191 void SubresourceFilterMetricsObserver::OnComplete(
166 const page_load_metrics::mojom::PageLoadTiming& timing, 192 const page_load_metrics::mojom::PageLoadTiming& timing,
167 const page_load_metrics::PageLoadExtraInfo& info) { 193 const page_load_metrics::PageLoadExtraInfo& info) {
168 OnGoingAway(timing, info, base::TimeTicks()); 194 OnGoingAway(timing, info, base::TimeTicks());
169 } 195 }
170 196
171 void SubresourceFilterMetricsObserver::OnLoadedResource( 197 void SubresourceFilterMetricsObserver::OnLoadedResource(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 UMA_HISTOGRAM_BOOLEAN(internal::kHistogramSubresourceFilterCount, true); 317 UMA_HISTOGRAM_BOOLEAN(internal::kHistogramSubresourceFilterCount, true);
292 } 318 }
293 } 319 }
294 320
295 void SubresourceFilterMetricsObserver::MediaStartedPlaying( 321 void SubresourceFilterMetricsObserver::MediaStartedPlaying(
296 const content::WebContentsObserver::MediaPlayerInfo& video_type, 322 const content::WebContentsObserver::MediaPlayerInfo& video_type,
297 bool is_in_main_frame) { 323 bool is_in_main_frame) {
298 played_media_ = true; 324 played_media_ = true;
299 } 325 }
300 326
327 void SubresourceFilterMetricsObserver::OnSubresourceFilterGoingAway() {
328 scoped_observer_.RemoveAll();
329 }
330
331 void SubresourceFilterMetricsObserver::OnPageActivationComputed(
332 content::NavigationHandle* navigation_handle,
333 subresource_filter::ActivationDecision activation_decision,
334 const subresource_filter::ActivationState& activation_state) {
335 // Make sure we don't get notifications from subsequent navigations.
336 if (navigation_handle != navigation_handle_)
337 return;
338 // Ensure this will always be called at most once before commit.
339 DCHECK(!did_commit_);
340 DCHECK(!activation_decision_);
341 activation_decision_ = activation_decision;
342 }
343
301 void SubresourceFilterMetricsObserver::OnGoingAway( 344 void SubresourceFilterMetricsObserver::OnGoingAway(
302 const page_load_metrics::mojom::PageLoadTiming& timing, 345 const page_load_metrics::mojom::PageLoadTiming& timing,
303 const page_load_metrics::PageLoadExtraInfo& info, 346 const page_load_metrics::PageLoadExtraInfo& info,
304 base::TimeTicks app_background_time) { 347 base::TimeTicks app_background_time) {
305 if (!subresource_filter_observed_) 348 if (!subresource_filter_observed_)
306 return; 349 return;
307 350
308 PAGE_RESOURCE_COUNT_HISTOGRAM( 351 PAGE_RESOURCE_COUNT_HISTOGRAM(
309 internal::kHistogramSubresourceFilterNetworkResources, 352 internal::kHistogramSubresourceFilterNetworkResources,
310 num_network_resources_); 353 num_network_resources_);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 foreground_duration.value()); 410 foreground_duration.value());
368 if (timing.paint_timing->first_paint && 411 if (timing.paint_timing->first_paint &&
369 timing.paint_timing->first_paint < foreground_duration) { 412 timing.paint_timing->first_paint < foreground_duration) {
370 PAGE_LOAD_LONG_HISTOGRAM( 413 PAGE_LOAD_LONG_HISTOGRAM(
371 internal::kHistogramSubresourceFilterForegroundDurationAfterPaint, 414 internal::kHistogramSubresourceFilterForegroundDurationAfterPaint,
372 foreground_duration.value() - 415 foreground_duration.value() -
373 timing.paint_timing->first_paint.value()); 416 timing.paint_timing->first_paint.value());
374 } 417 }
375 } 418 }
376 } 419 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698