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 4498c986e89f9cce154abc88b864fb6e5728a0eb..59196d388b6fad70fd20630bce5b845049b82740 100644 |
--- a/content/browser/download/download_resource_handler.cc |
+++ b/content/browser/download/download_resource_handler.cc |
@@ -73,10 +73,12 @@ static void StartOnUIThread( |
} // namespace |
DownloadResourceHandler::DownloadResourceHandler( |
+ DownloadId id, |
net::URLRequest* request, |
const DownloadResourceHandler::OnStartedCallback& started_cb, |
scoped_ptr<DownloadSaveInfo> save_info) |
- : render_view_id_(0), // Actually initialized below. |
+ : download_id_(id), |
+ render_view_id_(0), // Actually initialized below. |
content_length_(0), |
request_(request), |
started_cb_(started_cb), |
@@ -149,6 +151,7 @@ bool DownloadResourceHandler::OnResponseStarted( |
stream_writer_->RegisterCallback( |
base::Bind(&DownloadResourceHandler::ResumeRequest, AsWeakPtr())); |
+ info->download_id = download_id_; |
info->url_chain = request_->url_chain(); |
info->referrer_url = GURL(request_->referrer()); |
info->start_time = base::Time::Now(); |
@@ -173,6 +176,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. If we asked for a range, we didn't |
+ // get it--reset the file pointers to reflect that. |
+ save_info_->offset = 0; |
+ save_info_->hash_state = ""; |
+ } |
} |
std::string content_type_header; |
@@ -323,19 +334,31 @@ 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; |
} |