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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 return GetParallelRequestRemainingTimeConfig().InSeconds(); | 93 return GetParallelRequestRemainingTimeConfig().InSeconds(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void ParallelDownloadJob::CancelRequestWithOffset(int64_t offset) { | 96 void ParallelDownloadJob::CancelRequestWithOffset(int64_t offset) { |
| 97 if (initial_request_offset_ == offset) { | 97 if (initial_request_offset_ == offset) { |
| 98 DownloadJobImpl::Cancel(false); | 98 DownloadJobImpl::Cancel(false); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 | 101 |
| 102 auto it = workers_.find(offset); | 102 auto it = workers_.find(offset); |
| 103 DCHECK(it != workers_.end()); | |
| 103 if (it != workers_.end()) | 104 if (it != workers_.end()) |
|
qinmin
2017/04/24 21:27:31
nit: you can remove this if statement.
xingliu
2017/04/24 22:07:11
Done.
| |
| 104 it->second->Cancel(); | 105 it->second->Cancel(); |
| 105 } | 106 } |
| 106 | 107 |
| 107 void ParallelDownloadJob::BuildParallelRequestAfterDelay() { | 108 void ParallelDownloadJob::BuildParallelRequestAfterDelay() { |
| 108 DCHECK(workers_.empty()); | 109 DCHECK(workers_.empty()); |
| 109 DCHECK(!requests_sent_); | 110 DCHECK(!requests_sent_); |
| 110 DCHECK(!timer_.IsRunning()); | 111 DCHECK(!timer_.IsRunning()); |
| 111 | 112 |
| 112 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this, | 113 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this, |
| 113 &ParallelDownloadJob::BuildParallelRequests); | 114 &ParallelDownloadJob::BuildParallelRequests); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 // download request. | 244 // download request. |
| 244 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), | 245 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), |
| 245 blink::kWebReferrerPolicyAlways)); | 246 blink::kWebReferrerPolicyAlways)); |
| 246 // Send the request. | 247 // Send the request. |
| 247 worker->SendRequest(std::move(download_params)); | 248 worker->SendRequest(std::move(download_params)); |
| 248 DCHECK(workers_.find(offset) == workers_.end()); | 249 DCHECK(workers_.find(offset) == workers_.end()); |
| 249 workers_[offset] = std::move(worker); | 250 workers_[offset] = std::move(worker); |
| 250 } | 251 } |
| 251 | 252 |
| 252 } // namespace content | 253 } // namespace content |
| OLD | NEW |