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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 } | 90 } |
| 91 | 91 |
| 92 int ParallelDownloadJob::GetMinRemainingTimeInSeconds() const { | 92 int ParallelDownloadJob::GetMinRemainingTimeInSeconds() const { |
| 93 return GetParallelRequestRemainingTimeConfig().InSeconds(); | 93 return GetParallelRequestRemainingTimeConfig().InSeconds(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool ParallelDownloadJob::UsesParallelRequests() const { | 96 bool ParallelDownloadJob::UsesParallelRequests() const { |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void ParallelDownloadJob::CancelRequestWithOffset(int64_t offset) { | |
| 101 if (initial_request_offset_ == offset) { | |
| 102 DownloadJobImpl::Cancel(false); | |
|
asanka
2017/04/21 15:09:28
I guess the expectation is that this will go throu
xingliu
2017/04/21 18:07:00
ParallelDownloadComplete browser test covers this
xingliu
2017/04/22 00:07:24
The flow is DownloadFileImpl ==> DownloadItemImpl
| |
| 103 return; | |
| 104 } | |
| 105 | |
| 106 auto it = workers_.find(offset); | |
| 107 if (it != workers_.end()) | |
| 108 it->second->Cancel(); | |
|
asanka
2017/04/21 15:09:28
Is there a reason to consider the |it == workers_.
xingliu
2017/04/22 00:07:24
Done, added a DCHECK.
In the long term, after the
| |
| 109 } | |
| 110 | |
| 100 void ParallelDownloadJob::BuildParallelRequestAfterDelay() { | 111 void ParallelDownloadJob::BuildParallelRequestAfterDelay() { |
| 101 DCHECK(workers_.empty()); | 112 DCHECK(workers_.empty()); |
| 102 DCHECK(!requests_sent_); | 113 DCHECK(!requests_sent_); |
| 103 DCHECK(!timer_.IsRunning()); | 114 DCHECK(!timer_.IsRunning()); |
| 104 | 115 |
| 105 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this, | 116 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this, |
| 106 &ParallelDownloadJob::BuildParallelRequests); | 117 &ParallelDownloadJob::BuildParallelRequests); |
| 107 } | 118 } |
| 108 | 119 |
| 109 void ParallelDownloadJob::OnByteStreamReady( | 120 void ParallelDownloadJob::OnByteStreamReady( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 // download request. | 247 // download request. |
| 237 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), | 248 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), |
| 238 blink::kWebReferrerPolicyAlways)); | 249 blink::kWebReferrerPolicyAlways)); |
| 239 // Send the request. | 250 // Send the request. |
| 240 worker->SendRequest(std::move(download_params)); | 251 worker->SendRequest(std::move(download_params)); |
| 241 DCHECK(workers_.find(offset) == workers_.end()); | 252 DCHECK(workers_.find(offset) == workers_.end()); |
| 242 workers_[offset] = std::move(worker); | 253 workers_[offset] = std::move(worker); |
| 243 } | 254 } |
| 244 | 255 |
| 245 } // namespace content | 256 } // namespace content |
| OLD | NEW |