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

Unified Diff: chrome/browser/predictors/resource_prefetcher.cc

Issue 11761022: Fixing possible read on URLRequest when there is no more data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing rvargas's comments. Created 7 years, 12 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/predictors/resource_prefetcher.cc
diff --git a/chrome/browser/predictors/resource_prefetcher.cc b/chrome/browser/predictors/resource_prefetcher.cc
index 44b1057c4165839429cda432b446087e27efc25b..1419ffc9561a29026a34d59765d7aaa2a24b11a1 100644
--- a/chrome/browser/predictors/resource_prefetcher.cc
+++ b/chrome/browser/predictors/resource_prefetcher.cc
@@ -169,17 +169,17 @@ void ResourcePrefetcher::ReadFullResponse(net::URLRequest* request) {
kResourceBufferSizeBytes));
status = request->Read(buffer, kResourceBufferSizeBytes, &bytes_read);
- if (status) {
- if (request->status().error()) {
- FinishRequest(request, Request::PREFETCH_STATUS_FAILED);
- return;
- } else if (bytes_read == 0) {
- if (request->was_cached())
- FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE);
- else
- FinishRequest(request, Request::PREFETCH_STATUS_FROM_NETWORK);
- return;
- }
+ if (request->status().error()) {
rvargas (doing something else) 2013/01/04 02:02:40 The contract is not to inspect status() regardless
Shishir 2013/01/04 02:21:14 From the comment on the Read function: // If a rea
+ FinishRequest(request, Request::PREFETCH_STATUS_FAILED);
+ return;
+ }
+
+ if (status && bytes_read == 0) { // When bytes_read == 0, no more data.
+ if (request->was_cached())
+ FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE);
+ else
+ FinishRequest(request, Request::PREFETCH_STATUS_FROM_NETWORK);
+ return;
}
}
}
@@ -223,6 +223,15 @@ void ResourcePrefetcher::OnReadCompleted(net::URLRequest* request,
return;
}
+ // If the bytes_read is == 0, there is no more data to read.
+ if (bytes_read == 0) {
+ if (request->was_cached())
+ FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE);
+ else
+ FinishRequest(request, Request::PREFETCH_STATUS_FROM_NETWORK);
+ return;
+ }
+
ReadFullResponse(request);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698