Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Unified Diff: content/browser/download/download_file_impl.cc

Issue 2738063002: Verify that all slice are downloaded when a stream complete (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/download/download_file_impl.h ('k') | content/browser/download/download_file_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6fb0e9308dcfc63628d4494ae01c132899b380f7..eb1ef9bfd59e107735c6b49daf8f34df324f1191 100644
--- a/content/browser/download/download_file_impl.cc
+++ b/content/browser/download/download_file_impl.cc
@@ -393,18 +393,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();
@@ -483,6 +473,48 @@ void DownloadFileImpl::AddNewSlice(int64_t offset, int64_t length) {
}
}
+bool DownloadFileImpl::IsDownloadCompleted() {
+ SourceStream* stream_for_last_slice = nullptr;
+ int64_t last_slice_offset = 0;
+ 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;
+ last_slice_offset = source_stream->offset();
+ }
+ 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;
+ }
+ 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,
« no previous file with comments | « content/browser/download/download_file_impl.h ('k') | content/browser/download/download_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698