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

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

Issue 2893633003: [PageLoadMetrics] Don't record an ads histogram if the page hasn't committed (Closed)
Patch Set: Address comments from PS2 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/ads_page_load_metrics_obser ver.h" 5 #include "chrome/browser/page_load_metrics/observers/ads_page_load_metrics_obser ver.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 79
80 AdsPageLoadMetricsObserver::AdsPageLoadMetricsObserver() = default; 80 AdsPageLoadMetricsObserver::AdsPageLoadMetricsObserver() = default;
81 AdsPageLoadMetricsObserver::~AdsPageLoadMetricsObserver() = default; 81 AdsPageLoadMetricsObserver::~AdsPageLoadMetricsObserver() = default;
82 82
83 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 83 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
84 AdsPageLoadMetricsObserver::OnCommit( 84 AdsPageLoadMetricsObserver::OnCommit(
85 content::NavigationHandle* navigation_handle) { 85 content::NavigationHandle* navigation_handle) {
86 DCHECK(ad_frames_data_.empty()); 86 DCHECK(ad_frames_data_.empty());
87 87
88 committed_ = true;
89
88 // The main frame is never considered an ad. 90 // The main frame is never considered an ad.
89 ad_frames_data_[navigation_handle->GetFrameTreeNodeId()] = nullptr; 91 ad_frames_data_[navigation_handle->GetFrameTreeNodeId()] = nullptr;
90 ProcessOngoingNavigationResource(navigation_handle->GetFrameTreeNodeId()); 92 ProcessOngoingNavigationResource(navigation_handle->GetFrameTreeNodeId());
91 return CONTINUE_OBSERVING; 93 return CONTINUE_OBSERVING;
92 } 94 }
93 95
94 page_load_metrics::PageLoadMetricsObserver::ObservePolicy 96 page_load_metrics::PageLoadMetricsObserver::ObservePolicy
95 AdsPageLoadMetricsObserver::OnDidFinishSubFrameNavigation( 97 AdsPageLoadMetricsObserver::OnDidFinishSubFrameNavigation(
96 content::NavigationHandle* navigation_handle) { 98 content::NavigationHandle* navigation_handle) {
97 // Determine if the frame is part of an existing ad, the root of a new ad, 99 // Determine if the frame is part of an existing ad, the root of a new ad,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 extra_request_info.was_cached, extra_request_info.raw_body_bytes, 201 extra_request_info.was_cached, extra_request_info.raw_body_bytes,
200 extra_request_info.original_network_content_length, nullptr, 202 extra_request_info.original_network_content_length, nullptr,
201 extra_request_info.resource_type)); 203 extra_request_info.resource_type));
202 } else { 204 } else {
203 // This is unexpected, it could be: 205 // This is unexpected, it could be:
204 // 1. a resource from a previous navigation that started its resource 206 // 1. a resource from a previous navigation that started its resource
205 // load after this page started navigation. 207 // load after this page started navigation.
206 // 2. possibly a resource from a document.written frame whose frame 208 // 2. possibly a resource from a document.written frame whose frame
207 // failure message has yet to arrive. (uncertain of this) 209 // failure message has yet to arrive. (uncertain of this)
208 } 210 }
209 UMA_HISTOGRAM_ENUMERATION( 211 if (committed_) {
210 "PageLoad.Clients.Ads.Google.ResourceTypeWhenNoFrameFound", 212 UMA_HISTOGRAM_ENUMERATION(
211 extra_request_info.resource_type, content::RESOURCE_TYPE_LAST_TYPE); 213 "PageLoad.Clients.Ads.Google.ResourceTypeWhenNoFrameFound",
214 extra_request_info.resource_type, content::RESOURCE_TYPE_LAST_TYPE);
215 }
212 216
213 return; 217 return;
214 } 218 }
215 219
216 page_bytes_ += extra_request_info.raw_body_bytes; 220 page_bytes_ += extra_request_info.raw_body_bytes;
217 if (!extra_request_info.was_cached) 221 if (!extra_request_info.was_cached)
218 uncached_page_bytes_ += extra_request_info.raw_body_bytes; 222 uncached_page_bytes_ += extra_request_info.raw_body_bytes;
219 223
220 // Determine if the frame (or its ancestor) is an ad, if so attribute the 224 // Determine if the frame (or its ancestor) is an ad, if so attribute the
221 // bytes to the highest ad ancestor. 225 // bytes to the highest ad ancestor.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( 304 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource(
301 FrameTreeNodeId frame_tree_node_id) { 305 FrameTreeNodeId frame_tree_node_id) {
302 const auto& frame_id_and_request = 306 const auto& frame_id_and_request =
303 ongoing_navigation_resources_.find(frame_tree_node_id); 307 ongoing_navigation_resources_.find(frame_tree_node_id);
304 if (frame_id_and_request == ongoing_navigation_resources_.end()) 308 if (frame_id_and_request == ongoing_navigation_resources_.end())
305 return; 309 return;
306 310
307 ProcessLoadedResource(frame_id_and_request->second); 311 ProcessLoadedResource(frame_id_and_request->second);
308 ongoing_navigation_resources_.erase(frame_id_and_request); 312 ongoing_navigation_resources_.erase(frame_id_and_request);
309 } 313 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698