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

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: fix optional decl 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 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 navigation_handle->GetPageTransition())) { 128 navigation_handle->GetPageTransition())) {
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
138 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 142 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
139 SubresourceFilterMetricsObserver::FlushMetricsOnAppEnterBackground( 143 SubresourceFilterMetricsObserver::FlushMetricsOnAppEnterBackground(
140 const page_load_metrics::mojom::PageLoadTiming& timing, 144 const page_load_metrics::mojom::PageLoadTiming& timing,
141 const page_load_metrics::PageLoadExtraInfo& info) { 145 const page_load_metrics::PageLoadExtraInfo& info) {
142 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the 146 // FlushMetricsOnAppEnterBackground is invoked on Android in cases where the
143 // app is about to be backgrounded, as part of the Activity.onPause() 147 // 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 148 // flow. After this method is invoked, Chrome may be killed without further
145 // notification, so we record final metrics collected up to this point. 149 // notification, so we record final metrics collected up to this point.
146 if (info.did_commit) 150 if (info.did_commit)
147 OnGoingAway(timing, info, base::TimeTicks::Now()); 151 OnGoingAway(timing, info, base::TimeTicks::Now());
148 return STOP_OBSERVING; 152 return STOP_OBSERVING;
149 } 153 }
154 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
155 SubresourceFilterMetricsObserver::OnStart(
156 content::NavigationHandle* navigation_handle,
157 const GURL& currently_committed_url,
158 bool started_in_foreground) {
159 auto* observer_manager =
160 subresource_filter::SubresourceFilterObserverManager::FromWebContents(
161 navigation_handle->GetWebContents());
162 if (observer_manager)
Bryan McQuade 2017/05/23 19:31:57 what are the cases where observer manager won't ex
Charlie Harrison 2017/05/23 19:58:50 Only tests :/ I can add a comment.
163 scoped_observer_.Add(observer_manager);
164 return CONTINUE_OBSERVING;
165 }
150 166
151 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 167 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
152 SubresourceFilterMetricsObserver::OnCommit( 168 SubresourceFilterMetricsObserver::OnCommit(
Bryan McQuade 2017/05/23 19:31:57 i think we discussed this, but the activation deci
Charlie Harrison 2017/05/23 19:58:50 Done.
153 content::NavigationHandle* navigation_handle) { 169 content::NavigationHandle* navigation_handle) {
154 const auto* subres_filter = 170 if (activation_decision_)
155 ContentSubresourceFilterDriverFactory::FromWebContents( 171 LogActivationDecisionMetrics(navigation_handle, *activation_decision_);
156 navigation_handle->GetWebContents());
157 if (subres_filter)
158 LogActivationDecisionMetrics(
159 navigation_handle,
160 subres_filter->GetActivationDecisionForLastCommittedPageLoad());
161 return CONTINUE_OBSERVING; 172 return CONTINUE_OBSERVING;
162 } 173 }
163 174
164 void SubresourceFilterMetricsObserver::OnComplete( 175 void SubresourceFilterMetricsObserver::OnComplete(
165 const page_load_metrics::mojom::PageLoadTiming& timing, 176 const page_load_metrics::mojom::PageLoadTiming& timing,
166 const page_load_metrics::PageLoadExtraInfo& info) { 177 const page_load_metrics::PageLoadExtraInfo& info) {
167 OnGoingAway(timing, info, base::TimeTicks()); 178 OnGoingAway(timing, info, base::TimeTicks());
168 } 179 }
169 180
170 void SubresourceFilterMetricsObserver::OnLoadedResource( 181 void SubresourceFilterMetricsObserver::OnLoadedResource(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 UMA_HISTOGRAM_BOOLEAN(internal::kHistogramSubresourceFilterCount, true); 301 UMA_HISTOGRAM_BOOLEAN(internal::kHistogramSubresourceFilterCount, true);
291 } 302 }
292 } 303 }
293 304
294 void SubresourceFilterMetricsObserver::MediaStartedPlaying( 305 void SubresourceFilterMetricsObserver::MediaStartedPlaying(
295 const content::WebContentsObserver::MediaPlayerInfo& video_type, 306 const content::WebContentsObserver::MediaPlayerInfo& video_type,
296 bool is_in_main_frame) { 307 bool is_in_main_frame) {
297 played_media_ = true; 308 played_media_ = true;
298 } 309 }
299 310
311 void SubresourceFilterMetricsObserver::OnPageActivationComputed(
312 content::NavigationHandle* navigation_handle,
313 subresource_filter::ActivationDecision activation_decision,
314 const subresource_filter::ActivationState& activation_state) {
315 activation_decision_ = activation_decision;
316 }
317
300 void SubresourceFilterMetricsObserver::OnGoingAway( 318 void SubresourceFilterMetricsObserver::OnGoingAway(
301 const page_load_metrics::mojom::PageLoadTiming& timing, 319 const page_load_metrics::mojom::PageLoadTiming& timing,
302 const page_load_metrics::PageLoadExtraInfo& info, 320 const page_load_metrics::PageLoadExtraInfo& info,
303 base::TimeTicks app_background_time) { 321 base::TimeTicks app_background_time) {
304 if (!subresource_filter_observed_) 322 if (!subresource_filter_observed_)
305 return; 323 return;
306 324
307 PAGE_RESOURCE_COUNT_HISTOGRAM( 325 PAGE_RESOURCE_COUNT_HISTOGRAM(
308 internal::kHistogramSubresourceFilterNetworkResources, 326 internal::kHistogramSubresourceFilterNetworkResources,
309 num_network_resources_); 327 num_network_resources_);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 foreground_duration.value()); 384 foreground_duration.value());
367 if (timing.paint_timing->first_paint && 385 if (timing.paint_timing->first_paint &&
368 timing.paint_timing->first_paint < foreground_duration) { 386 timing.paint_timing->first_paint < foreground_duration) {
369 PAGE_LOAD_LONG_HISTOGRAM( 387 PAGE_LOAD_LONG_HISTOGRAM(
370 internal::kHistogramSubresourceFilterForegroundDurationAfterPaint, 388 internal::kHistogramSubresourceFilterForegroundDurationAfterPaint,
371 foreground_duration.value() - 389 foreground_duration.value() -
372 timing.paint_timing->first_paint.value()); 390 timing.paint_timing->first_paint.value());
373 } 391 }
374 } 392 }
375 } 393 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698