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); | |
|
qinmin
2017/04/17 21:39:59
early return?
xingliu
2017/04/17 23:41:51
Done, make sense.
| |
| 103 | |
| 104 auto it = workers_.find(offset); | |
| 105 if (it != workers_.end()) | |
| 106 it->second->Cancel(); | |
| 107 } | |
| 108 | |
| 100 void ParallelDownloadJob::BuildParallelRequestAfterDelay() { | 109 void ParallelDownloadJob::BuildParallelRequestAfterDelay() { |
| 101 DCHECK(workers_.empty()); | 110 DCHECK(workers_.empty()); |
| 102 DCHECK(!requests_sent_); | 111 DCHECK(!requests_sent_); |
| 103 DCHECK(!timer_.IsRunning()); | 112 DCHECK(!timer_.IsRunning()); |
| 104 | 113 |
| 105 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this, | 114 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this, |
| 106 &ParallelDownloadJob::BuildParallelRequests); | 115 &ParallelDownloadJob::BuildParallelRequests); |
| 107 } | 116 } |
| 108 | 117 |
| 109 void ParallelDownloadJob::OnByteStreamReady( | 118 void ParallelDownloadJob::OnByteStreamReady( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 // download request. | 245 // download request. |
| 237 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), | 246 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), |
| 238 blink::kWebReferrerPolicyAlways)); | 247 blink::kWebReferrerPolicyAlways)); |
| 239 // Send the request. | 248 // Send the request. |
| 240 worker->SendRequest(std::move(download_params)); | 249 worker->SendRequest(std::move(download_params)); |
| 241 DCHECK(workers_.find(offset) == workers_.end()); | 250 DCHECK(workers_.find(offset) == workers_.end()); |
| 242 workers_[offset] = std::move(worker); | 251 workers_[offset] = std::move(worker); |
| 243 } | 252 } |
| 244 | 253 |
| 245 } // namespace content | 254 } // namespace content |
| OLD | NEW |