| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/download/download_worker.h" | 5 #include "content/browser/download/download_worker.h" |
| 6 | 6 |
| 7 #include "content/browser/download/download_create_info.h" | 7 #include "content/browser/download/download_create_info.h" |
| 8 #include "content/public/browser/download_interrupt_reasons.h" | 8 #include "content/public/browser/download_interrupt_reasons.h" |
| 9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 | 10 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // |callback| is not used in subsequent requests. | 82 // |callback| is not used in subsequent requests. |
| 83 DCHECK(callback.is_null()); | 83 DCHECK(callback.is_null()); |
| 84 | 84 |
| 85 // Destroy the request if user canceled. | 85 // Destroy the request if user canceled. |
| 86 if (is_canceled_) { | 86 if (is_canceled_) { |
| 87 VLOG(kVerboseLevel) << "Byte stream arrived after user cancel the request."; | 87 VLOG(kVerboseLevel) << "Byte stream arrived after user cancel the request."; |
| 88 create_info->request_handle->CancelRequest(); | 88 create_info->request_handle->CancelRequest(); |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 | 91 |
| 92 // TODO(xingliu): Add the interrupt reason and metric data for precondition | 92 // TODO(xingliu): Add metric for error handling. |
| 93 // failure. Make DownloadRequestCore know if it should return error if the | |
| 94 // the server gives a different part of the content, e.g. "If-Match" return | |
| 95 // http 200. | |
| 96 if (create_info->result != | 93 if (create_info->result != |
| 97 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE) { | 94 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 98 VLOG(kVerboseLevel) << "Parallel download sub-request failed. reason = " | 95 VLOG(kVerboseLevel) << "Parallel download sub-request failed. reason = " |
| 99 << create_info->result; | 96 << create_info->result; |
| 97 |
| 98 // Ignore HTTP 416 for the workers. |
| 99 if (create_info->result == |
| 100 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE) { |
| 101 return; |
| 102 } |
| 103 |
| 100 delegate_->OnServerResponseError(this, create_info->result); | 104 delegate_->OnServerResponseError(this, create_info->result); |
| 101 return; | 105 return; |
| 102 } | 106 } |
| 103 | 107 |
| 104 request_handle_ = std::move(create_info->request_handle); | 108 request_handle_ = std::move(create_info->request_handle); |
| 105 | 109 |
| 106 // Pause the stream if user paused, still push the stream reader to the sink. | 110 // Pause the stream if user paused, still push the stream reader to the sink. |
| 107 if (is_paused_) { | 111 if (is_paused_) { |
| 108 VLOG(kVerboseLevel) << "Byte stream arrived after user pause the request."; | 112 VLOG(kVerboseLevel) << "Byte stream arrived after user pause the request."; |
| 109 Pause(); | 113 Pause(); |
| 110 } | 114 } |
| 111 | 115 |
| 112 delegate_->OnByteStreamReady(this, std::move(stream_reader)); | 116 delegate_->OnByteStreamReady(this, std::move(stream_reader)); |
| 113 } | 117 } |
| 114 | 118 |
| 115 void DownloadWorker::OnUrlDownloaderStopped(UrlDownloader* downloader) { | 119 void DownloadWorker::OnUrlDownloaderStopped(UrlDownloader* downloader) { |
| 116 // Release the |url_downloader_|, the object will be deleted on IO thread. | 120 // Release the |url_downloader_|, the object will be deleted on IO thread. |
| 117 url_downloader_.reset(); | 121 url_downloader_.reset(); |
| 118 } | 122 } |
| 119 | 123 |
| 120 void DownloadWorker::AddUrlDownloader( | 124 void DownloadWorker::AddUrlDownloader( |
| 121 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> | 125 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> |
| 122 downloader) { | 126 downloader) { |
| 123 url_downloader_ = std::move(downloader); | 127 url_downloader_ = std::move(downloader); |
| 124 } | 128 } |
| 125 | 129 |
| 126 } // namespace content | 130 } // namespace content |
| OLD | NEW |