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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // The main frame is never considered an ad. | 88 // The main frame is never considered an ad. |
89 ad_frames_data_[navigation_handle->GetFrameTreeNodeId()] = nullptr; | 89 ad_frames_data_[navigation_handle->GetFrameTreeNodeId()] = nullptr; |
90 ProcessOngoingNavigationResource(navigation_handle->GetFrameTreeNodeId()); | 90 ProcessOngoingNavigationResource(navigation_handle->GetFrameTreeNodeId()); |
91 return CONTINUE_OBSERVING; | 91 return CONTINUE_OBSERVING; |
92 } | 92 } |
93 | 93 |
94 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 94 void AdsPageLoadMetricsObserver::OnDidFinishSubFrameNavigation( |
95 AdsPageLoadMetricsObserver::OnDidFinishSubFrameNavigation( | |
96 content::NavigationHandle* navigation_handle) { | 95 content::NavigationHandle* navigation_handle) { |
97 // Determine if the frame is part of an existing ad, the root of a new ad, | 96 // Determine if the frame is part of an existing ad, the root of a new ad, |
98 // or a non-ad frame. Once a frame is labled as an ad, it is always | 97 // or a non-ad frame. Once a frame is labled as an ad, it is always |
99 // considered an ad, even if it navigates to a non-ad page. This function | 98 // considered an ad, even if it navigates to a non-ad page. This function |
100 // labels all of a page's frames, even those that fail to commit. | 99 // labels all of a page's frames, even those that fail to commit. |
101 FrameTreeNodeId frame_tree_node_id = navigation_handle->GetFrameTreeNodeId(); | 100 FrameTreeNodeId frame_tree_node_id = navigation_handle->GetFrameTreeNodeId(); |
102 content::RenderFrameHost* parent_frame_host = | 101 content::RenderFrameHost* parent_frame_host = |
103 navigation_handle->GetParentFrame(); | 102 navigation_handle->GetParentFrame(); |
104 | 103 |
105 const auto& id_and_data = ad_frames_data_.find(frame_tree_node_id); | 104 const auto& id_and_data = ad_frames_data_.find(frame_tree_node_id); |
106 if (id_and_data != ad_frames_data_.end()) { | 105 if (id_and_data != ad_frames_data_.end()) { |
107 // An existing subframe is navigating again. | 106 // An existing subframe is navigating again. |
108 if (id_and_data->second) { | 107 if (id_and_data->second) { |
109 // The subframe was an ad to begin with, keep tracking it as an ad. | 108 // The subframe was an ad to begin with, keep tracking it as an ad. |
110 ProcessOngoingNavigationResource(frame_tree_node_id); | 109 ProcessOngoingNavigationResource(frame_tree_node_id); |
111 | 110 |
112 if (frame_tree_node_id == id_and_data->second->frame_tree_node_id) { | 111 if (frame_tree_node_id == id_and_data->second->frame_tree_node_id) { |
113 // This is the top-most frame in the ad. | 112 // This is the top-most frame in the ad. |
114 UMA_HISTOGRAM_BOOLEAN( | 113 UMA_HISTOGRAM_BOOLEAN( |
115 "PageLoad.Clients.Ads.Google.Navigations.AdFrameRenavigatedToAd", | 114 "PageLoad.Clients.Ads.Google.Navigations.AdFrameRenavigatedToAd", |
116 FrameIsAd(navigation_handle)); | 115 FrameIsAd(navigation_handle)); |
117 } | 116 } |
118 return CONTINUE_OBSERVING; | 117 return; |
119 } | 118 } |
120 // This frame was previously not an ad, process it as usual. If it had | 119 // This frame was previously not an ad, process it as usual. If it had |
121 // any child frames that were ads, those will still be recorded. | 120 // any child frames that were ads, those will still be recorded. |
122 UMA_HISTOGRAM_BOOLEAN( | 121 UMA_HISTOGRAM_BOOLEAN( |
123 "PageLoad.Clients.Ads.Google.Navigations.NonAdFrameRenavigatedToAd", | 122 "PageLoad.Clients.Ads.Google.Navigations.NonAdFrameRenavigatedToAd", |
124 FrameIsAd(navigation_handle)); | 123 FrameIsAd(navigation_handle)); |
125 } | 124 } |
126 | 125 |
127 // Determine who the parent frame's ad ancestor is. | 126 // Determine who the parent frame's ad ancestor is. |
128 const auto& parent_id_and_data = | 127 const auto& parent_id_and_data = |
129 ad_frames_data_.find(parent_frame_host->GetFrameTreeNodeId()); | 128 ad_frames_data_.find(parent_frame_host->GetFrameTreeNodeId()); |
130 if (parent_id_and_data == ad_frames_data_.end()) { | 129 if (parent_id_and_data == ad_frames_data_.end()) { |
131 // We don't know who the parent for this frame is. One possibility is that | 130 // We don't know who the parent for this frame is. One possibility is that |
132 // it's a frame from a previous navigation. | 131 // it's a frame from a previous navigation. |
133 RecordParentExistsForSubFrame(false /* parent_exists */); | 132 RecordParentExistsForSubFrame(false /* parent_exists */); |
134 | 133 |
135 return CONTINUE_OBSERVING; | 134 return; |
136 } | 135 } |
137 RecordParentExistsForSubFrame(true /* parent_exists */); | 136 RecordParentExistsForSubFrame(true /* parent_exists */); |
138 | 137 |
139 AdFrameData* ad_data = parent_id_and_data->second; | 138 AdFrameData* ad_data = parent_id_and_data->second; |
140 | 139 |
141 if (!ad_data && FrameIsAd(navigation_handle)) { | 140 if (!ad_data && FrameIsAd(navigation_handle)) { |
142 // This frame is not nested within an ad frame but is itself an ad. | 141 // This frame is not nested within an ad frame but is itself an ad. |
143 ad_frames_data_storage_.emplace_back(frame_tree_node_id); | 142 ad_frames_data_storage_.emplace_back(frame_tree_node_id); |
144 ad_data = &ad_frames_data_storage_.back(); | 143 ad_data = &ad_frames_data_storage_.back(); |
145 } | 144 } |
146 | 145 |
147 ad_frames_data_[frame_tree_node_id] = ad_data; | 146 ad_frames_data_[frame_tree_node_id] = ad_data; |
148 | 147 |
149 ProcessOngoingNavigationResource(frame_tree_node_id); | 148 ProcessOngoingNavigationResource(frame_tree_node_id); |
150 return CONTINUE_OBSERVING; | |
151 } | 149 } |
152 | 150 |
153 page_load_metrics::PageLoadMetricsObserver::ObservePolicy | 151 page_load_metrics::PageLoadMetricsObserver::ObservePolicy |
154 AdsPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( | 152 AdsPageLoadMetricsObserver::FlushMetricsOnAppEnterBackground( |
155 const page_load_metrics::PageLoadTiming& timing, | 153 const page_load_metrics::PageLoadTiming& timing, |
156 const page_load_metrics::PageLoadExtraInfo& extra_info) { | 154 const page_load_metrics::PageLoadExtraInfo& extra_info) { |
157 // The browser may come back, but there is no guarantee. To be safe, record | 155 // The browser may come back, but there is no guarantee. To be safe, record |
158 // what we have now and ignore future changes to this navigation. | 156 // what we have now and ignore future changes to this navigation. |
159 if (extra_info.did_commit) | 157 if (extra_info.did_commit) |
160 RecordHistograms(); | 158 RecordHistograms(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( | 298 void AdsPageLoadMetricsObserver::ProcessOngoingNavigationResource( |
301 FrameTreeNodeId frame_tree_node_id) { | 299 FrameTreeNodeId frame_tree_node_id) { |
302 const auto& frame_id_and_request = | 300 const auto& frame_id_and_request = |
303 ongoing_navigation_resources_.find(frame_tree_node_id); | 301 ongoing_navigation_resources_.find(frame_tree_node_id); |
304 if (frame_id_and_request == ongoing_navigation_resources_.end()) | 302 if (frame_id_and_request == ongoing_navigation_resources_.end()) |
305 return; | 303 return; |
306 | 304 |
307 ProcessLoadedResource(frame_id_and_request->second); | 305 ProcessLoadedResource(frame_id_and_request->second); |
308 ongoing_navigation_resources_.erase(frame_id_and_request); | 306 ongoing_navigation_resources_.erase(frame_id_and_request); |
309 } | 307 } |
OLD | NEW |