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

Side by Side Diff: chrome/browser/data_use_measurement/chrome_data_use_ascriber.cc

Issue 2914923002: Fixing removing entries from DUA too early. (Closed)
Patch Set: nit Created 3 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/data_use_measurement/chrome_data_use_ascriber_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/data_use_measurement/chrome_data_use_ascriber.h" 5 #include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "chrome/browser/data_use_measurement/chrome_data_use_recorder.h" 10 #include "chrome/browser/data_use_measurement/chrome_data_use_recorder.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // GetOrCreateDataUseRecorderEntry is not needed. The entry gets created in 188 // GetOrCreateDataUseRecorderEntry is not needed. The entry gets created in
189 // DataUseAscriber::OnBeforeUrlRequest(). 189 // DataUseAscriber::OnBeforeUrlRequest().
190 const DataUseRecorderEntry entry = GetOrCreateDataUseRecorderEntry(request); 190 const DataUseRecorderEntry entry = GetOrCreateDataUseRecorderEntry(request);
191 191
192 if (entry == data_use_recorders_.end()) 192 if (entry == data_use_recorders_.end())
193 return; 193 return;
194 194
195 for (auto& observer : observers_) 195 for (auto& observer : observers_)
196 observer.OnPageResourceLoad(*request, &entry->data_use()); 196 observer.OnPageResourceLoad(*request, &entry->data_use());
197 197
198 bool will_datause_complete = false; 198 const auto frame_iter =
199 main_render_frame_data_use_map_.find(entry->main_frame_id());
200
201 // Check whether the frame is tracked in the main render frame map, and if it
202 // is, check if |entry| is currently tracked by that frame.
203 bool frame_is_tracked = frame_iter != main_render_frame_data_use_map_.end() &&
204 frame_iter->second == entry;
205
206 // For non-main frame requests, the page load can only be tracked in the frame
207 // map.
208 bool page_load_is_tracked = frame_is_tracked;
209
199 const content::ResourceRequestInfo* request_info = 210 const content::ResourceRequestInfo* request_info =
200 content::ResourceRequestInfo::ForRequest(request); 211 content::ResourceRequestInfo::ForRequest(request);
201 212
202 if (request_info && 213 // If the frame is not tracked, but this is a main frame request, it might be
214 // the case that the navigation has not commit yet.
215 if (!frame_is_tracked && request_info &&
203 request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { 216 request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) {
204 will_datause_complete = 217 page_load_is_tracked =
205 pending_navigation_data_use_map_.find(entry->main_frame_request_id()) == 218 pending_navigation_data_use_map_.find(entry->main_frame_request_id()) !=
206 pending_navigation_data_use_map_.end(); 219 pending_navigation_data_use_map_.end();
207 } else {
208 // Non-mainframe, Services, and other requests.
209 const auto frame_iter =
210 main_render_frame_data_use_map_.find(entry->main_frame_id());
211 will_datause_complete =
212 frame_iter == main_render_frame_data_use_map_.end() ||
213 !frame_iter->second->HasPendingURLRequest(request);
214 } 220 }
215 221
216 DataUseAscriber::OnUrlRequestDestroyed(request); 222 DataUseAscriber::OnUrlRequestDestroyed(request);
217 request->RemoveUserData(DataUseRecorderEntryAsUserData::kUserDataKey);
218 223
219 if (entry->IsDataUseComplete() && will_datause_complete) { 224 // If all requests are done for |entry| and no more requests can be attributed
225 // to it, it is safe to delete.
226 if (entry->IsDataUseComplete() && !page_load_is_tracked) {
220 NotifyDataUseCompleted(entry); 227 NotifyDataUseCompleted(entry);
221 main_render_frame_data_use_map_.erase(entry->main_frame_id());
222 data_use_recorders_.erase(entry); 228 data_use_recorders_.erase(entry);
223 } 229 }
224 } 230 }
225 231
226 void ChromeDataUseAscriber::RenderFrameCreated(int render_process_id, 232 void ChromeDataUseAscriber::RenderFrameCreated(int render_process_id,
227 int render_frame_id, 233 int render_frame_id,
228 int main_render_process_id, 234 int main_render_process_id,
229 int main_render_frame_id) { 235 int main_render_frame_id) {
230 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 236 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
231 237
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 pending_navigation_global_request_id_.find(old_frame); 474 pending_navigation_global_request_id_.find(old_frame);
469 if (pending_navigation_iter != pending_navigation_global_request_id_.end()) { 475 if (pending_navigation_iter != pending_navigation_global_request_id_.end()) {
470 pending_navigation_global_request_id_.insert(std::make_pair( 476 pending_navigation_global_request_id_.insert(std::make_pair(
471 RenderFrameHostID(new_render_process_id, new_render_frame_id), 477 RenderFrameHostID(new_render_process_id, new_render_frame_id),
472 pending_navigation_iter->second)); 478 pending_navigation_iter->second));
473 pending_navigation_global_request_id_.erase(pending_navigation_iter); 479 pending_navigation_global_request_id_.erase(pending_navigation_iter);
474 } 480 }
475 } 481 }
476 482
477 } // namespace data_use_measurement 483 } // namespace data_use_measurement
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/data_use_measurement/chrome_data_use_ascriber_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698