| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 AdsPageLoadMetricsObserver::OnCommit( | 79 AdsPageLoadMetricsObserver::OnCommit( |
| 80 content::NavigationHandle* navigation_handle) { | 80 content::NavigationHandle* navigation_handle) { |
| 81 DCHECK(ad_frames_data_.empty()); | 81 DCHECK(ad_frames_data_.empty()); |
| 82 | 82 |
| 83 // The main frame is never considered an ad. | 83 // The main frame is never considered an ad. |
| 84 ad_frames_data_[navigation_handle->GetFrameTreeNodeId()] = nullptr; | 84 ad_frames_data_[navigation_handle->GetFrameTreeNodeId()] = nullptr; |
| 85 ProcessOngoingNavigationResource(navigation_handle->GetFrameTreeNodeId()); | 85 ProcessOngoingNavigationResource(navigation_handle->GetFrameTreeNodeId()); |
| 86 return CONTINUE_OBSERVING; | 86 return CONTINUE_OBSERVING; |
| 87 } | 87 } |
| 88 | 88 |
| 89 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 89 void AdsPageLoadMetricsObserver::OnDidFinishSubFrameNavigation( |
| 90 AdsPageLoadMetricsObserver::OnDidFinishSubFrameNavigation( | |
| 91 content::NavigationHandle* navigation_handle) { | 90 content::NavigationHandle* navigation_handle) { |
| 92 // Determine if the frame is part of an existing ad, the root of a new ad, | 91 // Determine if the frame is part of an existing ad, the root of a new ad, |
| 93 // or a non-ad frame. Once a frame is labled as an ad, it is always | 92 // or a non-ad frame. Once a frame is labled as an ad, it is always |
| 94 // considered an ad, even if it navigates to a non-ad page. This function | 93 // considered an ad, even if it navigates to a non-ad page. This function |
| 95 // labels all of a page's frames, even those that fail to commit. | 94 // labels all of a page's frames, even those that fail to commit. |
| 96 FrameTreeNodeId frame_tree_node_id = navigation_handle->GetFrameTreeNodeId(); | 95 FrameTreeNodeId frame_tree_node_id = navigation_handle->GetFrameTreeNodeId(); |
| 97 content::RenderFrameHost* parent_frame_host = | 96 content::RenderFrameHost* parent_frame_host = |
| 98 navigation_handle->GetParentFrame(); | 97 navigation_handle->GetParentFrame(); |
| 99 | 98 |
| 100 const auto& id_and_data = ad_frames_data_.find(frame_tree_node_id); | 99 const auto& id_and_data = ad_frames_data_.find(frame_tree_node_id); |
| 101 if (id_and_data != ad_frames_data_.end()) { | 100 if (id_and_data != ad_frames_data_.end()) { |
| 102 // An existing subframe is navigating again. | 101 // An existing subframe is navigating again. |
| 103 if (id_and_data->second) { | 102 if (id_and_data->second) { |
| 104 // The subframe was an ad to begin with, keep tracking it as an ad. | 103 // The subframe was an ad to begin with, keep tracking it as an ad. |
| 105 ProcessOngoingNavigationResource(frame_tree_node_id); | 104 ProcessOngoingNavigationResource(frame_tree_node_id); |
| 106 | 105 |
| 107 if (frame_tree_node_id == id_and_data->second->frame_tree_node_id) { | 106 if (frame_tree_node_id == id_and_data->second->frame_tree_node_id) { |
| 108 // This is the top-most frame in the ad. | 107 // This is the top-most frame in the ad. |
| 109 UMA_HISTOGRAM_BOOLEAN( | 108 UMA_HISTOGRAM_BOOLEAN( |
| 110 "PageLoad.Clients.Ads.Google.Navigations.AdFrameRenavigatedToAd", | 109 "PageLoad.Clients.Ads.Google.Navigations.AdFrameRenavigatedToAd", |
| 111 FrameIsAd(navigation_handle)); | 110 FrameIsAd(navigation_handle)); |
| 112 } | 111 } |
| 113 return CONTINUE_OBSERVING; | 112 return; |
| 114 } | 113 } |
| 115 // This frame was previously not an ad, process it as usual. If it had | 114 // 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. | 115 // any child frames that were ads, those will still be recorded. |
| 117 UMA_HISTOGRAM_BOOLEAN( | 116 UMA_HISTOGRAM_BOOLEAN( |
| 118 "PageLoad.Clients.Ads.Google.Navigations.NonAdFrameRenavigatedToAd", | 117 "PageLoad.Clients.Ads.Google.Navigations.NonAdFrameRenavigatedToAd", |
| 119 FrameIsAd(navigation_handle)); | 118 FrameIsAd(navigation_handle)); |
| 120 } | 119 } |
| 121 | 120 |
| 122 // Determine who the parent frame's ad ancestor is. | 121 // Determine who the parent frame's ad ancestor is. |
| 123 const auto& parent_id_and_data = | 122 const auto& parent_id_and_data = |
| 124 ad_frames_data_.find(parent_frame_host->GetFrameTreeNodeId()); | 123 ad_frames_data_.find(parent_frame_host->GetFrameTreeNodeId()); |
| 125 DCHECK(parent_id_and_data != ad_frames_data_.end()); | 124 DCHECK(parent_id_and_data != ad_frames_data_.end()); |
| 126 AdFrameData* ad_data = parent_id_and_data->second; | 125 AdFrameData* ad_data = parent_id_and_data->second; |
| 127 | 126 |
| 128 if (!ad_data && FrameIsAd(navigation_handle)) { | 127 if (!ad_data && FrameIsAd(navigation_handle)) { |
| 129 // This frame is not nested within an ad frame but is itself an ad. | 128 // This frame is not nested within an ad frame but is itself an ad. |
| 130 ad_frames_data_storage_.emplace_back(frame_tree_node_id); | 129 ad_frames_data_storage_.emplace_back(frame_tree_node_id); |
| 131 ad_data = &ad_frames_data_storage_.back(); | 130 ad_data = &ad_frames_data_storage_.back(); |
| 132 } | 131 } |
| 133 | 132 |
| 134 ad_frames_data_[frame_tree_node_id] = ad_data; | 133 ad_frames_data_[frame_tree_node_id] = ad_data; |
| 135 | 134 |
| 136 ProcessOngoingNavigationResource(frame_tree_node_id); | 135 ProcessOngoingNavigationResource(frame_tree_node_id); |
| 137 return CONTINUE_OBSERVING; | |
| 138 } | 136 } |
| 139 | 137 |
| 140 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 138 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
| 141 AdsPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( | 139 AdsPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( |
| 142 const page_load_metrics::PageLoadTiming& timing, | 140 const page_load_metrics::PageLoadTiming& timing, |
| 143 const page_load_metrics::PageLoadExtraInfo& extra_info) { | 141 const page_load_metrics::PageLoadExtraInfo& extra_info) { |
| 144 // The browser may come back, but there is no guarantee. To be safe, record | 142 // The browser may come back, but there is no guarantee. To be safe, record |
| 145 // what we have now and ignore future changes to this navigation. | 143 // what we have now and ignore future changes to this navigation. |
| 146 if (extra_info.did_commit) | 144 if (extra_info.did_commit) |
| 147 RecordHistograms(); | 145 RecordHistograms(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( | 275 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( |
| 278 FrameTreeNodeId frame_tree_node_id) { | 276 FrameTreeNodeId frame_tree_node_id) { |
| 279 const auto& frame_id_and_request = | 277 const auto& frame_id_and_request = |
| 280 ongoing_navigation_resources_.find(frame_tree_node_id); | 278 ongoing_navigation_resources_.find(frame_tree_node_id); |
| 281 if (frame_id_and_request == ongoing_navigation_resources_.end()) | 279 if (frame_id_and_request == ongoing_navigation_resources_.end()) |
| 282 return; | 280 return; |
| 283 | 281 |
| 284 ProcessLoadedResource(frame_id_and_request->second); | 282 ProcessLoadedResource(frame_id_and_request->second); |
| 285 ongoing_navigation_resources_.erase(frame_id_and_request); | 283 ongoing_navigation_resources_.erase(frame_id_and_request); |
| 286 } | 284 } |
| OLD | NEW |