OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/download_file_impl.h" | 5 #include "content/browser/download/download_file_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 download_item_net_log.source().ToEventParametersCallback()); | 122 download_item_net_log.source().ToEventParametersCallback()); |
123 } | 123 } |
124 | 124 |
125 DownloadFileImpl::~DownloadFileImpl() { | 125 DownloadFileImpl::~DownloadFileImpl() { |
126 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 126 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
127 net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE); | 127 net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE); |
128 } | 128 } |
129 | 129 |
130 void DownloadFileImpl::Initialize( | 130 void DownloadFileImpl::Initialize( |
131 const InitializeCallback& callback, | 131 const InitializeCallback& callback, |
132 const DownloadItem::ReceivedSlices& received_slices) { | 132 const DownloadItem::ReceivedSlices& received_slices, |
133 bool is_parallelizable) { | |
133 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 134 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
134 | 135 |
135 update_timer_.reset(new base::RepeatingTimer()); | 136 update_timer_.reset(new base::RepeatingTimer()); |
136 int64_t bytes_so_far = 0; | 137 int64_t bytes_so_far = 0; |
137 received_slices_ = received_slices; | 138 received_slices_ = received_slices; |
138 if (IsSparseFile()) { | 139 if (IsSparseFile()) { |
139 for (const auto& received_slice : received_slices_) { | 140 for (const auto& received_slice : received_slices_) { |
140 bytes_so_far += received_slice.received_bytes; | 141 bytes_so_far += received_slice.received_bytes; |
141 } | 142 } |
142 } else { | 143 } else { |
143 bytes_so_far = save_info_->offset; | 144 bytes_so_far = save_info_->offset; |
144 } | 145 } |
145 DownloadInterruptReason result = file_.Initialize( | 146 DownloadInterruptReason result = file_.Initialize( |
146 save_info_->file_path, default_download_directory_, | 147 save_info_->file_path, default_download_directory_, |
147 std::move(save_info_->file), bytes_so_far, | 148 std::move(save_info_->file), bytes_so_far, |
148 save_info_->hash_of_partial_file, std::move(save_info_->hash_state), | 149 save_info_->hash_of_partial_file, std::move(save_info_->hash_state), |
149 IsSparseFile()); | 150 IsSparseFile()); |
150 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { | 151 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { |
151 BrowserThread::PostTask( | 152 BrowserThread::PostTask( |
152 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); | 153 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); |
153 return; | 154 return; |
154 } | 155 } |
155 | 156 |
156 download_start_ = base::TimeTicks::Now(); | 157 download_start_ = base::TimeTicks::Now(); |
157 last_update_time_ = download_start_; | 158 last_update_time_ = download_start_; |
159 record_stream_bandwidth_ = is_parallelizable; | |
xingliu
2017/04/19 02:18:11
Can we initialize this to false in the constructor
qinmin
2017/04/19 22:42:33
Done.
| |
158 | 160 |
159 // Primarily to make reset to zero in restart visible to owner. | 161 // Primarily to make reset to zero in restart visible to owner. |
160 SendUpdate(); | 162 SendUpdate(); |
161 | 163 |
162 BrowserThread::PostTask( | 164 BrowserThread::PostTask( |
163 BrowserThread::UI, FROM_HERE, base::Bind( | 165 BrowserThread::UI, FROM_HERE, base::Bind( |
164 callback, DOWNLOAD_INTERRUPT_REASON_NONE)); | 166 callback, DOWNLOAD_INTERRUPT_REASON_NONE)); |
165 | 167 |
166 // Initial pull from the straw from all source streams. | 168 // Initial pull from the straw from all source streams. |
167 for (auto& source_stream : source_streams_) | 169 for (auto& source_stream : source_streams_) |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 } | 477 } |
476 num_active_streams_--; | 478 num_active_streams_--; |
477 | 479 |
478 // Inform observers. | 480 // Inform observers. |
479 SendUpdate(); | 481 SendUpdate(); |
480 | 482 |
481 // All the stream reader are completed, shut down file IO processing. | 483 // All the stream reader are completed, shut down file IO processing. |
482 if (IsDownloadCompleted()) { | 484 if (IsDownloadCompleted()) { |
483 RecordFileBandwidth(bytes_seen_, disk_writes_time_, | 485 RecordFileBandwidth(bytes_seen_, disk_writes_time_, |
484 base::TimeTicks::Now() - download_start_); | 486 base::TimeTicks::Now() - download_start_); |
485 if (IsSparseFile() && record_stream_bandwidth_) { | 487 if (record_stream_bandwidth_) { |
486 RecordParallelDownloadStats(bytes_seen_with_parallel_streams_, | 488 RecordParallelizableDownloadStats( |
487 download_time_with_parallel_streams_, | 489 bytes_seen_with_parallel_streams_, |
488 bytes_seen_without_parallel_streams_, | 490 download_time_with_parallel_streams_, |
489 download_time_without_parallel_streams_); | 491 bytes_seen_without_parallel_streams_, |
492 download_time_without_parallel_streams_, IsSparseFile()); | |
490 } | 493 } |
491 weak_factory_.InvalidateWeakPtrs(); | 494 weak_factory_.InvalidateWeakPtrs(); |
492 std::unique_ptr<crypto::SecureHash> hash_state = file_.Finish(); | 495 std::unique_ptr<crypto::SecureHash> hash_state = file_.Finish(); |
493 update_timer_.reset(); | 496 update_timer_.reset(); |
494 BrowserThread::PostTask( | 497 BrowserThread::PostTask( |
495 BrowserThread::UI, FROM_HERE, | 498 BrowserThread::UI, FROM_HERE, |
496 base::Bind(&DownloadDestinationObserver::DestinationCompleted, | 499 base::Bind(&DownloadDestinationObserver::DestinationCompleted, |
497 observer_, TotalBytesReceived(), | 500 observer_, TotalBytesReceived(), |
498 base::Passed(&hash_state))); | 501 base::Passed(&hash_state))); |
499 } | 502 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 const base::FilePath& new_path, | 701 const base::FilePath& new_path, |
699 const RenameCompletionCallback& completion_callback) | 702 const RenameCompletionCallback& completion_callback) |
700 : option(option), | 703 : option(option), |
701 new_path(new_path), | 704 new_path(new_path), |
702 retries_left(kMaxRenameRetries), | 705 retries_left(kMaxRenameRetries), |
703 completion_callback(completion_callback) {} | 706 completion_callback(completion_callback) {} |
704 | 707 |
705 DownloadFileImpl::RenameParameters::~RenameParameters() {} | 708 DownloadFileImpl::RenameParameters::~RenameParameters() {} |
706 | 709 |
707 } // namespace content | 710 } // namespace content |
OLD | NEW |