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

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: Moving error checking statement. 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 | « chrome/browser/predictors/resource_prefetcher.h ('k') | 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..c9814e12fa20a3eaa1f04469303a0765512bd602 100644
--- a/chrome/browser/predictors/resource_prefetcher.cc
+++ b/chrome/browser/predictors/resource_prefetcher.cc
@@ -170,20 +170,27 @@ void ResourcePrefetcher::ReadFullResponse(net::URLRequest* request) {
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;
- }
+ status = ShouldContinueReadingRequest(request, bytes_read);
+ } else if (request->status().error()) {
+ FinishRequest(request, Request::PREFETCH_STATUS_FAILED);
+ return;
}
}
}
+bool ResourcePrefetcher::ShouldContinueReadingRequest(net::URLRequest* request,
+ int bytes_read) {
+ if (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 false;
+ }
+
+ return true;
+}
+
void ResourcePrefetcher::OnReceivedRedirect(net::URLRequest* request,
const GURL& new_url,
bool* defer_redirect) {
@@ -213,6 +220,7 @@ void ResourcePrefetcher::OnResponseStarted(net::URLRequest* request) {
return;
}
+ // TODO(shishir): Do not read cached entries, or ones that are not cacheable.
ReadFullResponse(request);
}
@@ -223,7 +231,8 @@ void ResourcePrefetcher::OnReadCompleted(net::URLRequest* request,
return;
}
- ReadFullResponse(request);
+ if (ShouldContinueReadingRequest(request, bytes_read))
+ ReadFullResponse(request);
}
} // namespace predictors
« no previous file with comments | « chrome/browser/predictors/resource_prefetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698