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/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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 "PageLoad.Clients.Ads.Google.Navigations.AdFrameRenavigatedToAd", | 110 "PageLoad.Clients.Ads.Google.Navigations.AdFrameRenavigatedToAd", |
111 FrameIsAd(navigation_handle)); | 111 FrameIsAd(navigation_handle)); |
112 } | 112 } |
113 return CONTINUE_OBSERVING; | 113 return CONTINUE_OBSERVING; |
114 } | 114 } |
115 // This frame was previously not an ad, process it as usual. If it had | 115 // This frame was previously not an ad, process it as usual. If it had |
116 // any child frames that were ads, those will still be recorded. | 116 // any child frames that were ads, those will still be recorded. |
117 UMA_HISTOGRAM_BOOLEAN( | 117 UMA_HISTOGRAM_BOOLEAN( |
118 "PageLoad.Clients.Ads.Google.Navigations.NonAdFrameRenavigatedToAd", | 118 "PageLoad.Clients.Ads.Google.Navigations.NonAdFrameRenavigatedToAd", |
119 FrameIsAd(navigation_handle)); | 119 FrameIsAd(navigation_handle)); |
120 } else if (navigation_handle->IsParentMainFrame()) { | |
121 top_level_subframe_count_ += 1; | |
122 } | 120 } |
123 | 121 |
124 // Determine who the parent frame's ad ancestor is. | 122 // Determine who the parent frame's ad ancestor is. |
125 const auto& parent_id_and_data = | 123 const auto& parent_id_and_data = |
126 ad_frames_data_.find(parent_frame_host->GetFrameTreeNodeId()); | 124 ad_frames_data_.find(parent_frame_host->GetFrameTreeNodeId()); |
127 DCHECK(parent_id_and_data != ad_frames_data_.end()); | 125 DCHECK(parent_id_and_data != ad_frames_data_.end()); |
128 AdFrameData* ad_data = parent_id_and_data->second; | 126 AdFrameData* ad_data = parent_id_and_data->second; |
129 | 127 |
130 if (!ad_data && FrameIsAd(navigation_handle)) { | 128 if (!ad_data && FrameIsAd(navigation_handle)) { |
131 // This frame is not nested within an ad frame but is itself an ad. | 129 // This frame is not nested within an ad frame but is itself an ad. |
132 ad_frames_data_storage_.emplace_back(frame_tree_node_id); | 130 ad_frames_data_storage_.emplace_back(frame_tree_node_id); |
133 ad_data = &ad_frames_data_storage_.back(); | 131 ad_data = &ad_frames_data_storage_.back(); |
134 } | 132 } |
135 | 133 |
136 ad_frames_data_[frame_tree_node_id] = ad_data; | 134 ad_frames_data_[frame_tree_node_id] = ad_data; |
137 | 135 |
138 if (navigation_handle->IsParentMainFrame() && ad_data) | |
139 top_level_ad_frame_count_ += 1; | |
140 | |
141 ProcessOngoingNavigationResource(frame_tree_node_id); | 136 ProcessOngoingNavigationResource(frame_tree_node_id); |
142 return CONTINUE_OBSERVING; | 137 return CONTINUE_OBSERVING; |
143 } | 138 } |
144 | 139 |
145 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 140 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
146 AdsPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( | 141 AdsPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( |
147 const page_load_metrics::PageLoadTiming& timing, | 142 const page_load_metrics::PageLoadTiming& timing, |
148 const page_load_metrics::PageLoadExtraInfo& extra_info) { | 143 const page_load_metrics::PageLoadExtraInfo& extra_info) { |
149 // The browser may come back, but there is no guarantee. To be safe, record | 144 // The browser may come back, but there is no guarantee. To be safe, record |
150 // what we have now and ignore future changes to this navigation. | 145 // what we have now and ignore future changes to this navigation. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 if (!extra_request_info.was_cached) { | 203 if (!extra_request_info.was_cached) { |
209 ancestor_data->frame_bytes_uncached += extra_request_info.raw_body_bytes; | 204 ancestor_data->frame_bytes_uncached += extra_request_info.raw_body_bytes; |
210 } | 205 } |
211 } | 206 } |
212 } | 207 } |
213 | 208 |
214 void AdsPageLoadMetricsObserver::RecordHistograms() { | 209 void AdsPageLoadMetricsObserver::RecordHistograms() { |
215 if (page_bytes_ == 0) | 210 if (page_bytes_ == 0) |
216 return; | 211 return; |
217 | 212 |
| 213 int non_zero_ad_frames = 0; |
218 size_t total_ad_frame_bytes = 0; | 214 size_t total_ad_frame_bytes = 0; |
219 size_t uncached_ad_frame_bytes = 0; | 215 size_t uncached_ad_frame_bytes = 0; |
220 | 216 |
221 UMA_HISTOGRAM_COUNTS_1000( | 217 for (const AdFrameData& ad_frame_data : ad_frames_data_storage_) { |
222 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", | 218 if (ad_frame_data.frame_bytes == 0) |
223 ad_frames_data_storage_.size()); | 219 continue; |
224 | 220 |
225 // Don't post UMA for pages that don't have ads. | 221 non_zero_ad_frames += 1; |
226 if (ad_frames_data_storage_.empty()) | |
227 return; | |
228 | |
229 for (const AdFrameData& ad_frame_data : ad_frames_data_storage_) { | |
230 total_ad_frame_bytes += ad_frame_data.frame_bytes; | 222 total_ad_frame_bytes += ad_frame_data.frame_bytes; |
231 uncached_ad_frame_bytes += ad_frame_data.frame_bytes_uncached; | 223 uncached_ad_frame_bytes += ad_frame_data.frame_bytes_uncached; |
232 | 224 |
233 PAGE_BYTES_HISTOGRAM( | 225 PAGE_BYTES_HISTOGRAM( |
234 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Total", | 226 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Total", |
235 ad_frame_data.frame_bytes); | 227 ad_frame_data.frame_bytes); |
236 PAGE_BYTES_HISTOGRAM( | 228 PAGE_BYTES_HISTOGRAM( |
237 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Network", | 229 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.Network", |
238 ad_frame_data.frame_bytes_uncached); | 230 ad_frame_data.frame_bytes_uncached); |
239 if (ad_frame_data.frame_bytes > 0) { | 231 UMA_HISTOGRAM_PERCENTAGE( |
240 UMA_HISTOGRAM_PERCENTAGE( | 232 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", |
241 "PageLoad.Clients.Ads.Google.Bytes.AdFrames.PerFrame.PercentNetwork", | 233 ad_frame_data.frame_bytes_uncached * 100 / ad_frame_data.frame_bytes); |
242 ad_frame_data.frame_bytes_uncached * 100 / ad_frame_data.frame_bytes); | |
243 } | |
244 } | 234 } |
245 | 235 |
246 UMA_HISTOGRAM_COUNTS_1000( | 236 UMA_HISTOGRAM_COUNTS_1000( |
247 "PageLoad.Clients.Ads.Google.FrameCounts.MainFrameParent.TotalFrames", | 237 "PageLoad.Clients.Ads.Google.FrameCounts.AnyParentFrame.AdFrames", |
248 top_level_subframe_count_); | 238 non_zero_ad_frames); |
249 UMA_HISTOGRAM_COUNTS_1000( | |
250 "PageLoad.Clients.Ads.Google.FrameCounts.MainFrameParent.AdFrames", | |
251 top_level_ad_frame_count_); | |
252 | 239 |
253 DCHECK_LT(0, top_level_subframe_count_); // Because ad frames isn't empty. | 240 // Don't post UMA for pages that don't have ads. |
254 UMA_HISTOGRAM_PERCENTAGE( | 241 if (non_zero_ad_frames == 0) |
255 "PageLoad.Clients.Ads.Google.FrameCounts.MainFrameParent.PercentAdFrames", | 242 return; |
256 top_level_ad_frame_count_ * 100 / top_level_subframe_count_); | |
257 | 243 |
258 PAGE_BYTES_HISTOGRAM( | 244 PAGE_BYTES_HISTOGRAM( |
259 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Aggregate.Total", | 245 "PageLoad.Clients.Ads.Google.Bytes.NonAdFrames.Aggregate.Total", |
260 page_bytes_ - total_ad_frame_bytes); | 246 page_bytes_ - total_ad_frame_bytes); |
261 | 247 |
262 PAGE_BYTES_HISTOGRAM("PageLoad.Clients.Ads.Google.Bytes.FullPage.Total", | 248 PAGE_BYTES_HISTOGRAM("PageLoad.Clients.Ads.Google.Bytes.FullPage.Total", |
263 page_bytes_); | 249 page_bytes_); |
264 PAGE_BYTES_HISTOGRAM("PageLoad.Clients.Ads.Google.Bytes.FullPage.Network", | 250 PAGE_BYTES_HISTOGRAM("PageLoad.Clients.Ads.Google.Bytes.FullPage.Network", |
265 uncached_page_bytes_); | 251 uncached_page_bytes_); |
266 if (page_bytes_) { | 252 if (page_bytes_) { |
(...skipping 24 matching lines...) Expand all Loading... |
291 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( | 277 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( |
292 FrameTreeNodeId frame_tree_node_id) { | 278 FrameTreeNodeId frame_tree_node_id) { |
293 const auto& frame_id_and_request = | 279 const auto& frame_id_and_request = |
294 ongoing_navigation_resources_.find(frame_tree_node_id); | 280 ongoing_navigation_resources_.find(frame_tree_node_id); |
295 if (frame_id_and_request == ongoing_navigation_resources_.end()) | 281 if (frame_id_and_request == ongoing_navigation_resources_.end()) |
296 return; | 282 return; |
297 | 283 |
298 ProcessLoadedResource(frame_id_and_request->second); | 284 ProcessLoadedResource(frame_id_and_request->second); |
299 ongoing_navigation_resources_.erase(frame_id_and_request); | 285 ongoing_navigation_resources_.erase(frame_id_and_request); |
300 } | 286 } |
OLD | NEW |