Chromium Code Reviews| Index: content/browser/download/download_worker.cc |
| diff --git a/content/browser/download/download_worker.cc b/content/browser/download/download_worker.cc |
| index d537b1d9951e818909a3ebf3d8957f794142ba1e..2992a4dc3fa7a2d8ad16e4d48d869d29b1295f4c 100644 |
| --- a/content/browser/download/download_worker.cc |
| +++ b/content/browser/download/download_worker.cc |
| @@ -32,7 +32,15 @@ CreateUrlDownloader(std::unique_ptr<DownloadUrlParameters> params, |
| } // namespace |
| -DownloadWorker::DownloadWorker() : weak_factory_(this) {} |
| +DownloadWorker::DownloadWorker(DownloadWorker::Delegate* delegate, |
| + int64_t offset, |
| + int64_t length) |
| + : delegate_(delegate), |
| + offset_(offset), |
| + length_(length), |
| + weak_factory_(this) { |
| + DCHECK(delegate_); |
| +} |
| DownloadWorker::~DownloadWorker() = default; |
| @@ -48,15 +56,18 @@ void DownloadWorker::SendRequest( |
| } |
| void DownloadWorker::Pause() { |
| - request_handle_->PauseRequest(); |
| + if (request_handle_) |
| + request_handle_->PauseRequest(); |
| } |
| void DownloadWorker::Resume() { |
| - request_handle_->ResumeRequest(); |
| + if (request_handle_) |
| + request_handle_->ResumeRequest(); |
| } |
| void DownloadWorker::Cancel() { |
| - request_handle_->CancelRequest(); |
| + if (request_handle_) |
| + request_handle_->CancelRequest(); |
| } |
| void DownloadWorker::OnUrlDownloaderStarted( |
| @@ -66,13 +77,23 @@ void DownloadWorker::OnUrlDownloaderStarted( |
| // |callback| is not used in subsequent requests. |
| DCHECK(callback.is_null()); |
| - // TODO(xingliu): Pass the |stream_reader| to parallel job and handle failed |
| - // request. |
| + // If the server gave us a different part of the content, due to "If-Match" or |
| + // "If-Unmodified-Since" headers, reports an error, which results in the |
| + // download to be restarted. |
| + if (create_info->save_info->offset != offset() || |
| + create_info->save_info->length != length()) { |
|
asanka
2017/03/17 15:54:22
This condition will trip for any half-open slice.
xingliu
2017/03/17 21:14:36
Good point, It will be cleaner to let DownloadRequ
asanka
2017/03/20 20:50:20
Don't forget the part about explicitly indicating
xingliu
2017/03/21 17:32:15
Yeah, that's on my list.
|
| + // TODO(xingliu): Add the interrupt reason and metric data for precondition |
| + // failure. |
| + VLOG(kVerboseLevel) << "Server response does not match the offset or " |
| + "length in the request."; |
| + create_info->result = DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE; |
| + } |
| + |
| if (create_info->result != |
| DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE) { |
| - VLOG(kVerboseLevel) << "Parallel download sub request failed. reason = " |
| + VLOG(kVerboseLevel) << "Parallel download sub-request failed. reason = " |
| << create_info->result; |
| - NOTIMPLEMENTED(); |
| + delegate_->OnServerResponseError(this, create_info->result); |
| return; |
| } |