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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 base::WeakPtr<DownloadDestinationObserver> observer) | 99 base::WeakPtr<DownloadDestinationObserver> observer) |
100 : net_log_( | 100 : net_log_( |
101 net::NetLogWithSource::Make(download_item_net_log.net_log(), | 101 net::NetLogWithSource::Make(download_item_net_log.net_log(), |
102 net::NetLogSourceType::DOWNLOAD_FILE)), | 102 net::NetLogSourceType::DOWNLOAD_FILE)), |
103 file_(net_log_), | 103 file_(net_log_), |
104 save_info_(std::move(save_info)), | 104 save_info_(std::move(save_info)), |
105 default_download_directory_(default_download_directory), | 105 default_download_directory_(default_download_directory), |
106 potential_file_length_(kUnknownContentLength), | 106 potential_file_length_(kUnknownContentLength), |
107 bytes_seen_(0), | 107 bytes_seen_(0), |
108 num_active_streams_(0), | 108 num_active_streams_(0), |
109 record_stream_bandwidth_(true), | 109 record_stream_bandwidth_(false), |
110 bytes_seen_with_parallel_streams_(0), | 110 bytes_seen_with_parallel_streams_(0), |
111 bytes_seen_without_parallel_streams_(0), | 111 bytes_seen_without_parallel_streams_(0), |
112 observer_(observer), | 112 observer_(observer), |
113 weak_factory_(this) { | 113 weak_factory_(this) { |
114 source_streams_[save_info_->offset] = base::MakeUnique<SourceStream>( | 114 source_streams_[save_info_->offset] = base::MakeUnique<SourceStream>( |
115 save_info_->offset, save_info_->length, std::move(stream_reader)); | 115 save_info_->offset, save_info_->length, std::move(stream_reader)); |
116 | 116 |
117 download_item_net_log.AddEvent( | 117 download_item_net_log.AddEvent( |
118 net::NetLogEventType::DOWNLOAD_FILE_CREATED, | 118 net::NetLogEventType::DOWNLOAD_FILE_CREATED, |
119 net_log_.source().ToEventParametersCallback()); | 119 net_log_.source().ToEventParametersCallback()); |
120 net_log_.BeginEvent( | 120 net_log_.BeginEvent( |
121 net::NetLogEventType::DOWNLOAD_FILE_ACTIVE, | 121 net::NetLogEventType::DOWNLOAD_FILE_ACTIVE, |
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& initialize_callback, | 131 const InitializeCallback& initialize_callback, |
132 const CancelRequestCallback& cancel_request_callback, | 132 const CancelRequestCallback& cancel_request_callback, |
133 const DownloadItem::ReceivedSlices& received_slices) { | 133 const DownloadItem::ReceivedSlices& received_slices, |
| 134 bool is_parallelizable) { |
134 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 135 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
135 | 136 |
136 update_timer_.reset(new base::RepeatingTimer()); | 137 update_timer_.reset(new base::RepeatingTimer()); |
137 int64_t bytes_so_far = 0; | 138 int64_t bytes_so_far = 0; |
138 cancel_request_callback_ = cancel_request_callback; | 139 cancel_request_callback_ = cancel_request_callback; |
139 received_slices_ = received_slices; | 140 received_slices_ = received_slices; |
140 if (IsSparseFile()) { | 141 if (IsSparseFile()) { |
141 for (const auto& received_slice : received_slices_) { | 142 for (const auto& received_slice : received_slices_) { |
142 bytes_so_far += received_slice.received_bytes; | 143 bytes_so_far += received_slice.received_bytes; |
143 } | 144 } |
144 } else { | 145 } else { |
145 bytes_so_far = save_info_->offset; | 146 bytes_so_far = save_info_->offset; |
146 } | 147 } |
147 DownloadInterruptReason result = file_.Initialize( | 148 DownloadInterruptReason result = file_.Initialize( |
148 save_info_->file_path, default_download_directory_, | 149 save_info_->file_path, default_download_directory_, |
149 std::move(save_info_->file), bytes_so_far, | 150 std::move(save_info_->file), bytes_so_far, |
150 save_info_->hash_of_partial_file, std::move(save_info_->hash_state), | 151 save_info_->hash_of_partial_file, std::move(save_info_->hash_state), |
151 IsSparseFile()); | 152 IsSparseFile()); |
152 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { | 153 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { |
153 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 154 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
154 base::Bind(initialize_callback, result)); | 155 base::Bind(initialize_callback, result)); |
155 return; | 156 return; |
156 } | 157 } |
157 | 158 |
158 download_start_ = base::TimeTicks::Now(); | 159 download_start_ = base::TimeTicks::Now(); |
159 last_update_time_ = download_start_; | 160 last_update_time_ = download_start_; |
| 161 record_stream_bandwidth_ = is_parallelizable; |
160 | 162 |
161 // Primarily to make reset to zero in restart visible to owner. | 163 // Primarily to make reset to zero in restart visible to owner. |
162 SendUpdate(); | 164 SendUpdate(); |
163 | 165 |
164 BrowserThread::PostTask( | 166 BrowserThread::PostTask( |
165 BrowserThread::UI, FROM_HERE, | 167 BrowserThread::UI, FROM_HERE, |
166 base::Bind(initialize_callback, DOWNLOAD_INTERRUPT_REASON_NONE)); | 168 base::Bind(initialize_callback, DOWNLOAD_INTERRUPT_REASON_NONE)); |
167 | 169 |
168 // Initial pull from the straw from all source streams. | 170 // Initial pull from the straw from all source streams. |
169 for (auto& source_stream : source_streams_) | 171 for (auto& source_stream : source_streams_) |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 } | 483 } |
482 num_active_streams_--; | 484 num_active_streams_--; |
483 | 485 |
484 // Inform observers. | 486 // Inform observers. |
485 SendUpdate(); | 487 SendUpdate(); |
486 | 488 |
487 // All the stream reader are completed, shut down file IO processing. | 489 // All the stream reader are completed, shut down file IO processing. |
488 if (IsDownloadCompleted()) { | 490 if (IsDownloadCompleted()) { |
489 RecordFileBandwidth(bytes_seen_, disk_writes_time_, | 491 RecordFileBandwidth(bytes_seen_, disk_writes_time_, |
490 base::TimeTicks::Now() - download_start_); | 492 base::TimeTicks::Now() - download_start_); |
491 if (IsSparseFile() && record_stream_bandwidth_) { | 493 if (record_stream_bandwidth_) { |
492 RecordParallelDownloadStats(bytes_seen_with_parallel_streams_, | 494 RecordParallelizableDownloadStats( |
493 download_time_with_parallel_streams_, | 495 bytes_seen_with_parallel_streams_, |
494 bytes_seen_without_parallel_streams_, | 496 download_time_with_parallel_streams_, |
495 download_time_without_parallel_streams_); | 497 bytes_seen_without_parallel_streams_, |
| 498 download_time_without_parallel_streams_, IsSparseFile()); |
496 } | 499 } |
497 weak_factory_.InvalidateWeakPtrs(); | 500 weak_factory_.InvalidateWeakPtrs(); |
498 std::unique_ptr<crypto::SecureHash> hash_state = file_.Finish(); | 501 std::unique_ptr<crypto::SecureHash> hash_state = file_.Finish(); |
499 update_timer_.reset(); | 502 update_timer_.reset(); |
500 BrowserThread::PostTask( | 503 BrowserThread::PostTask( |
501 BrowserThread::UI, FROM_HERE, | 504 BrowserThread::UI, FROM_HERE, |
502 base::Bind(&DownloadDestinationObserver::DestinationCompleted, | 505 base::Bind(&DownloadDestinationObserver::DestinationCompleted, |
503 observer_, TotalBytesReceived(), | 506 observer_, TotalBytesReceived(), |
504 base::Passed(&hash_state))); | 507 base::Passed(&hash_state))); |
505 } | 508 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 const base::FilePath& new_path, | 715 const base::FilePath& new_path, |
713 const RenameCompletionCallback& completion_callback) | 716 const RenameCompletionCallback& completion_callback) |
714 : option(option), | 717 : option(option), |
715 new_path(new_path), | 718 new_path(new_path), |
716 retries_left(kMaxRenameRetries), | 719 retries_left(kMaxRenameRetries), |
717 completion_callback(completion_callback) {} | 720 completion_callback(completion_callback) {} |
718 | 721 |
719 DownloadFileImpl::RenameParameters::~RenameParameters() {} | 722 DownloadFileImpl::RenameParameters::~RenameParameters() {} |
720 | 723 |
721 } // namespace content | 724 } // namespace content |
OLD | NEW |