| 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/parallel_download_job.h" | 5 #include "content/browser/download/parallel_download_job.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "content/browser/download/download_create_info.h" | 8 #include "content/browser/download/download_create_info.h" |
| 9 #include "content/browser/download/parallel_download_utils.h" | 9 #include "content/browser/download/parallel_download_utils.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 &ParallelDownloadJob::BuildParallelRequests); | 82 &ParallelDownloadJob::BuildParallelRequests); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void ParallelDownloadJob::OnByteStreamReady( | 85 void ParallelDownloadJob::OnByteStreamReady( |
| 86 DownloadWorker* worker, | 86 DownloadWorker* worker, |
| 87 std::unique_ptr<ByteStreamReader> stream_reader) { | 87 std::unique_ptr<ByteStreamReader> stream_reader) { |
| 88 DownloadJob::AddByteStream(std::move(stream_reader), worker->offset(), | 88 DownloadJob::AddByteStream(std::move(stream_reader), worker->offset(), |
| 89 worker->length()); | 89 worker->length()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void ParallelDownloadJob::OnServerResponseError( |
| 93 DownloadWorker* worker, |
| 94 DownloadInterruptReason reason) { |
| 95 // TODO(xingliu): Consider to let the original request to cover the full |
| 96 // content if the sub-requests get invalid response. Consider retry on certain |
| 97 // error. |
| 98 DownloadJob::Interrupt(reason); |
| 99 } |
| 100 |
| 92 void ParallelDownloadJob::BuildParallelRequests() { | 101 void ParallelDownloadJob::BuildParallelRequests() { |
| 93 DCHECK(!requests_sent_); | 102 DCHECK(!requests_sent_); |
| 94 // TODO(qinmin): The size of |slices_to_download| should be no larger than | 103 // TODO(qinmin): The size of |slices_to_download| should be no larger than |
| 95 // |kParallelRequestCount| unless |kParallelRequestCount| is changed after | 104 // |kParallelRequestCount| unless |kParallelRequestCount| is changed after |
| 96 // a download is interrupted. This could happen if we use finch to config | 105 // a download is interrupted. This could happen if we use finch to config |
| 97 // the number of parallel requests. | 106 // the number of parallel requests. |
| 98 // Get the next |kParallelRequestCount - 1| slices and fork | 107 // Get the next |kParallelRequestCount - 1| slices and fork |
| 99 // new requests. For the remaining slices, they will be handled once some | 108 // new requests. For the remaining slices, they will be handled once some |
| 100 // of the workers finish their job. | 109 // of the workers finish their job. |
| 101 DownloadItem::ReceivedSlices slices_to_download; | 110 DownloadItem::ReceivedSlices slices_to_download; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // download request. | 170 // download request. |
| 162 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), | 171 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), |
| 163 blink::WebReferrerPolicyAlways)); | 172 blink::WebReferrerPolicyAlways)); |
| 164 // Send the request. | 173 // Send the request. |
| 165 worker->SendRequest(std::move(download_params)); | 174 worker->SendRequest(std::move(download_params)); |
| 166 DCHECK(workers_.find(offset) == workers_.end()); | 175 DCHECK(workers_.find(offset) == workers_.end()); |
| 167 workers_[offset] = std::move(worker); | 176 workers_[offset] = std::move(worker); |
| 168 } | 177 } |
| 169 | 178 |
| 170 } // namespace content | 179 } // namespace content |
| OLD | NEW |