Chromium Code Reviews| Index: content/browser/download/download_file_impl.cc |
| diff --git a/content/browser/download/download_file_impl.cc b/content/browser/download/download_file_impl.cc |
| index 8b2a9e8e81585fb36be77bd083558ba356fc8ffa..90f59448e6369337feb9a2be525587a778d3a3e2 100644 |
| --- a/content/browser/download/download_file_impl.cc |
| +++ b/content/browser/download/download_file_impl.cc |
| @@ -19,6 +19,7 @@ |
| #include "content/browser/download/download_interrupt_reasons_impl.h" |
| #include "content/browser/download/download_net_log_parameters.h" |
| #include "content/browser/download/download_stats.h" |
| +#include "content/browser/download/parallel_download_utils.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "crypto/secure_hash.h" |
| #include "crypto/sha2.h" |
| @@ -367,18 +368,8 @@ void DownloadFileImpl::StreamActive(SourceStream* source_stream) { |
| // Inform observers. |
| SendUpdate(); |
| - // TODO(xingliu): Use slice info to determine if the file is fully |
| - // downloaded. |
| - bool all_stream_complete = true; |
| - for (auto& stream : source_streams_) { |
| - if (!stream.second->is_finished()) { |
| - all_stream_complete = false; |
| - break; |
| - } |
| - } |
| - |
| // All the stream reader are completed, shut down file IO processing. |
| - if (all_stream_complete) { |
| + if (IsDownloadCompleted()) { |
| RecordFileBandwidth(bytes_seen_, disk_writes_time_, |
| base::TimeTicks::Now() - download_start_); |
| weak_factory_.InvalidateWeakPtrs(); |
| @@ -433,6 +424,46 @@ void DownloadFileImpl::WillWriteToDisk(size_t data_len) { |
| rate_estimator_.Increment(data_len); |
| } |
| +bool DownloadFileImpl::IsDownloadCompleted() { |
| + SourceStream* stream_for_last_slice = nullptr; |
| + int64_t last_slice_offset = 0; |
|
David Trainor- moved to gerrit
2017/03/09 17:23:10
You need to set this inside the if block below rig
qinmin
2017/03/09 17:42:25
Good catch. I was using
steam_for_last_slice = sou
|
| + for (auto& stream : source_streams_) { |
| + SourceStream* source_stream = stream.second.get(); |
| + if (source_stream->offset() >= last_slice_offset && |
| + source_stream->bytes_written() > 0) { |
| + stream_for_last_slice = source_stream; |
| + } |
| + if (!source_stream->is_finished()) |
| + return false; |
| + } |
| + |
| + if (!is_sparse_file_) |
| + return true; |
| + |
| + // Verify that all the file slices have been downloaded. |
| + std::vector<DownloadItem::ReceivedSlice> slices_to_download = |
| + FindSlicesToDownload(received_slices_); |
| + if (slices_to_download.size() > 1) { |
| + // If there are 1 or more holes in the file, download is not finished. |
| + // Some streams might not have been added to |source_streams_| yet. |
| + return false; |
| + } else if (stream_for_last_slice) { |
| + DCHECK_EQ(slices_to_download[0].received_bytes, |
| + DownloadSaveInfo::kLengthFullContent); |
| + // The last stream should not have a length limit. If it has, it might |
| + // not reach the end of the file. |
| + if (stream_for_last_slice->length() != |
| + DownloadSaveInfo::kLengthFullContent) { |
| + return false; |
| + } |
| + DCHECK_EQ(slices_to_download[0].offset, |
| + stream_for_last_slice->offset() + |
| + stream_for_last_slice->bytes_written()); |
| + } |
| + |
| + return true; |
| +} |
| + |
| DownloadFileImpl::RenameParameters::RenameParameters( |
| RenameOption option, |
| const base::FilePath& new_path, |