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

Unified Diff: chrome/browser/data_use_measurement/chrome_data_use_ascriber.cc

Issue 2868733002: Move failed URLRequest checking to OnUrlRequestCompleted (Closed)
Patch Set: Addressed comment 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/data_use_measurement/chrome_data_use_ascriber.cc
diff --git a/chrome/browser/data_use_measurement/chrome_data_use_ascriber.cc b/chrome/browser/data_use_measurement/chrome_data_use_ascriber.cc
index f7da400c932756f0b3f1683ebdc6e30cfee248a9..eac26e8f599bd531a7d6b031846350efa641156d 100644
--- a/chrome/browser/data_use_measurement/chrome_data_use_ascriber.cc
+++ b/chrome/browser/data_use_measurement/chrome_data_use_ascriber.cc
@@ -151,6 +151,26 @@ ChromeDataUseAscriber::GetOrCreateDataUseRecorderEntry(
return entry;
}
+void ChromeDataUseAscriber::OnUrlRequestCompleted(
+ const net::URLRequest& request,
+ bool started) {
+ ChromeDataUseRecorder* recorder = GetDataUseRecorder(request);
tbansal1 2017/05/11 20:55:41 Add DCHECK_CURRENTLY_ON(content::BrowserThread::IO
rajendrant 2017/05/16 01:04:14 Done.
+
+ if (!recorder)
+ return;
+
+ const content::ResourceRequestInfo* request_info =
+ content::ResourceRequestInfo::ForRequest(&request);
+ if (!request_info ||
+ request_info->GetResourceType() != content::RESOURCE_TYPE_MAIN_FRAME)
+ return;
tbansal1 2017/05/11 20:55:41 parens are needed here since the if-conditional sp
rajendrant 2017/05/16 01:04:14 Done.
+
+ // If request was not successful, then NavigationHandle in
tbansal1 2017/05/11 20:55:41 Do you have to check somewhere that |request| was
rajendrant 2017/05/16 01:04:14 Yes. This was missed.
+ // DidFinishMainFrameNavigation will not have GlobalRequestID. So we erase the
+ // DataUseRecorderEntry here.
+ pending_navigation_data_use_map_.erase(recorder->main_frame_request_id());
+}
+
void ChromeDataUseAscriber::OnUrlRequestDestroyed(net::URLRequest* request) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
@@ -159,8 +179,6 @@ void ChromeDataUseAscriber::OnUrlRequestDestroyed(net::URLRequest* request) {
if (entry == data_use_recorders_.end())
return;
- DataUseRecorder* recorder = &(*entry);
-
RenderFrameHostID frame_key = entry->main_frame_id();
auto frame_iter = main_render_frame_data_use_map_.find(frame_key);
bool is_in_render_frame_map =
@@ -169,30 +187,16 @@ void ChromeDataUseAscriber::OnUrlRequestDestroyed(net::URLRequest* request) {
const content::ResourceRequestInfo* request_info =
content::ResourceRequestInfo::ForRequest(request);
- content::ResourceType resource_type = request_info
- ? request_info->GetResourceType()
- : content::RESOURCE_TYPE_LAST_TYPE;
-
- bool is_in_pending_navigation_map = false;
- if (request_info && resource_type == content::RESOURCE_TYPE_MAIN_FRAME) {
- auto navigation_iter = pending_navigation_data_use_map_.find(
- entry->main_frame_request_id());
- is_in_pending_navigation_map =
- navigation_iter != pending_navigation_data_use_map_.end();
-
- // If request was not successful, then NavigationHandle in
- // DidFinishMainFrameNavigation will not have GlobalRequestID. So we erase
- // the DataUseRecorderEntry here.
- if (is_in_pending_navigation_map && !request->status().is_success()) {
- pending_navigation_data_use_map_.erase(navigation_iter);
- is_in_pending_navigation_map = false;
- }
- }
+ bool is_in_pending_navigation_map =
+ request_info &&
+ request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME &&
+ pending_navigation_data_use_map_.find(entry->main_frame_request_id()) !=
+ pending_navigation_data_use_map_.end();
DataUseAscriber::OnUrlRequestDestroyed(request);
request->RemoveUserData(DataUseRecorderEntryAsUserData::kUserDataKey);
- if (recorder->IsDataUseComplete() && !is_in_render_frame_map &&
+ if (entry->IsDataUseComplete() && !is_in_render_frame_map &&
!is_in_pending_navigation_map) {
OnDataUseCompleted(entry);
data_use_recorders_.erase(entry);

Powered by Google App Engine
This is Rietveld 408576698