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

Unified Diff: content/browser/download/download_resource_handler.cc

Issue 10831302: Download resumption - Preliminary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed signed/unsigned compare issue. Created 8 years, 1 month 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: content/browser/download/download_resource_handler.cc
diff --git a/content/browser/download/download_resource_handler.cc b/content/browser/download/download_resource_handler.cc
index 29f7e8e194fcca59bb94c18c8a81f493ca7e0588..fa4fb84a761a66a923bc7e080795e729500b7d74 100644
--- a/content/browser/download/download_resource_handler.cc
+++ b/content/browser/download/download_resource_handler.cc
@@ -172,6 +172,14 @@ bool DownloadResourceHandler::OnResponseStarted(
info->last_modified = last_modified_hdr;
if (headers->EnumerateHeader(NULL, "ETag", &etag))
info->etag = etag;
+
+ int status = headers->response_code();
+ if (status == 200) { // Continue with download:
+ // Downloading the full file, even if we asked for a range.
+ // If there is a temporary file and |received_bytes == 0|, delete it.
+ save_info_->offset = 0;
+ save_info_->hash_state = "";
+ }
}
std::string content_type_header;
@@ -322,19 +330,32 @@ bool DownloadResourceHandler::OnResponseCompleted(
reason = DOWNLOAD_INTERRUPT_REASON_USER_CANCELED;
}
- if (status.is_success()) {
- if (response_code >= 400) {
+ if (status.is_success() &&
+ (reason == DOWNLOAD_INTERRUPT_REASON_NONE) &&
+ request_->response_headers()) {
+ // Handle server's response codes.
+ if ((response_code >= 0) && ((response_code % 100) != 2)) {
switch(response_code) {
- case 404: // File Not Found.
+ // Continue with download:
+ case 200: // Downloading the full file, even if we asked for a
+ // range.
+ case 206: // Partial content. Leave alone.
+ break;
+ case 204: // No content. File not present.
+ case 404: // File Not Found.
reason = DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT;
break;
+ case 412: // Precondition failed. Fails 'If-Unmodified-Since' or
+ // 'If-Match'.
+ reason = DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION;
+ break;
case 416: // Range Not Satisfiable.
+ // Retry by downloading from the start automatically:
+ // If we haven't received data when we get this error, we won't.
reason = DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE;
- break;
- case 412: // Precondition Failed.
reason = DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION;
break;
- default:
+ default: // All other errors.
reason = DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED;
break;
}
« no previous file with comments | « content/browser/download/download_request_handle.cc ('k') | content/browser/hyphenator/hyphenator_message_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698