Chromium Code Reviews| 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" |
| 11 #include "content/public/browser/storage_partition.h" | 11 #include "content/public/browser/storage_partition.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 namespace { | |
| 15 | |
| 16 const int kVerboseLevel = 1; | |
| 17 | |
| 18 } // namespace | |
| 14 | 19 |
| 15 ParallelDownloadJob::ParallelDownloadJob( | 20 ParallelDownloadJob::ParallelDownloadJob( |
| 16 DownloadItemImpl* download_item, | 21 DownloadItemImpl* download_item, |
| 17 std::unique_ptr<DownloadRequestHandleInterface> request_handle, | 22 std::unique_ptr<DownloadRequestHandleInterface> request_handle, |
| 18 const DownloadCreateInfo& create_info) | 23 const DownloadCreateInfo& create_info) |
| 19 : DownloadJobImpl(download_item, std::move(request_handle)), | 24 : DownloadJobImpl(download_item, std::move(request_handle)), |
| 20 initial_request_offset_(create_info.offset), | 25 initial_request_offset_(create_info.offset), |
| 21 content_length_(create_info.total_bytes), | 26 content_length_(create_info.total_bytes), |
| 22 requests_sent_(false) {} | 27 requests_sent_(false) {} |
| 23 | 28 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 DCHECK(!requests_sent_); | 83 DCHECK(!requests_sent_); |
| 79 DCHECK(!timer_.IsRunning()); | 84 DCHECK(!timer_.IsRunning()); |
| 80 | 85 |
| 81 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this, | 86 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this, |
| 82 &ParallelDownloadJob::BuildParallelRequests); | 87 &ParallelDownloadJob::BuildParallelRequests); |
| 83 } | 88 } |
| 84 | 89 |
| 85 void ParallelDownloadJob::OnByteStreamReady( | 90 void ParallelDownloadJob::OnByteStreamReady( |
| 86 DownloadWorker* worker, | 91 DownloadWorker* worker, |
| 87 std::unique_ptr<ByteStreamReader> stream_reader) { | 92 std::unique_ptr<ByteStreamReader> stream_reader) { |
| 88 DownloadJob::AddByteStream(std::move(stream_reader), worker->offset(), | 93 // Destroy the request if user canceled. |
| 89 worker->length()); | 94 if (DownloadJob::is_canceled()) { |
| 95 VLOG(kVerboseLevel) << "Byte stream arrived after user cancel the request."; | |
| 96 worker->Cancel(); | |
|
qinmin
2017/03/21 22:53:55
do you need to do this? If cancel is called before
xingliu
2017/03/21 23:19:14
At that time the request handle is not set into th
xingliu
2017/03/21 23:27:59
I'm also fine with let worker defer the cancel cal
qinmin
2017/03/21 23:48:33
Yes, it should be worker's responsibility to handl
xingliu
2017/03/22 01:25:59
Make sense, done.
| |
| 97 return; | |
| 98 } | |
| 99 | |
| 100 // Pause the stream if user paused, still push the stream reader to the sink. | |
| 101 if (DownloadJob::is_paused()) { | |
| 102 VLOG(kVerboseLevel) << "Byte stream arrived after user pause the request."; | |
| 103 worker->Pause(); | |
|
qinmin
2017/03/21 22:53:55
same here.
xingliu
2017/03/21 23:19:14
We still need to add the stream to DownloadFileImp
qinmin
2017/03/21 23:48:33
Yes. what i mean is that you don't need to call Pa
xingliu
2017/03/22 01:25:59
Done. Moved to worker.
| |
| 104 } | |
| 105 | |
| 106 bool success = DownloadJob::AddByteStream(std::move(stream_reader), | |
| 107 worker->offset(), worker->length()); | |
| 108 | |
| 109 // Destroy the request if the sink is gone. | |
| 110 if (!success) { | |
| 111 VLOG(kVerboseLevel) | |
| 112 << "Byte stream arrived after download file is released."; | |
| 113 worker->Cancel(); | |
| 114 } | |
| 90 } | 115 } |
| 91 | 116 |
| 92 void ParallelDownloadJob::OnServerResponseError( | 117 void ParallelDownloadJob::OnServerResponseError( |
| 93 DownloadWorker* worker, | 118 DownloadWorker* worker, |
| 94 DownloadInterruptReason reason) { | 119 DownloadInterruptReason reason) { |
| 95 // TODO(xingliu): Consider to let the original request to cover the full | 120 // 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 | 121 // content if the sub-requests get invalid response. Consider retry on certain |
| 97 // error. | 122 // error. |
| 98 DownloadJob::Interrupt(reason); | 123 DownloadJob::Interrupt(reason); |
| 99 } | 124 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 // download request. | 195 // download request. |
| 171 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), | 196 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), |
| 172 blink::WebReferrerPolicyAlways)); | 197 blink::WebReferrerPolicyAlways)); |
| 173 // Send the request. | 198 // Send the request. |
| 174 worker->SendRequest(std::move(download_params)); | 199 worker->SendRequest(std::move(download_params)); |
| 175 DCHECK(workers_.find(offset) == workers_.end()); | 200 DCHECK(workers_.find(offset) == workers_.end()); |
| 176 workers_[offset] = std::move(worker); | 201 workers_[offset] = std::move(worker); |
| 177 } | 202 } |
| 178 | 203 |
| 179 } // namespace content | 204 } // namespace content |
| OLD | NEW |