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

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

Issue 2742093002: Glue parallel download job and download file together. (Closed)
Patch Set: Work on feedback. 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
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 e4ec806f7718c8b4de357eb9977f329a852834a7..88eb1f5ab3e8b68cdc345626197bab6c6a58d7e7 100644
--- a/content/browser/download/download_file_impl.cc
+++ b/content/browser/download/download_file_impl.cc
@@ -120,7 +120,7 @@ void DownloadFileImpl::Initialize(const InitializeCallback& callback) {
// Primarily to make reset to zero in restart visible to owner.
SendUpdate();
- // Initial pull from the straw.
+ // Initial pull from the straw from all source streams.
for (auto& source_stream : source_streams_)
RegisterAndActivateStream(source_stream.second.get());
@@ -131,16 +131,18 @@ void DownloadFileImpl::Initialize(const InitializeCallback& callback) {
void DownloadFileImpl::AddByteStream(
std::unique_ptr<ByteStreamReader> stream_reader,
- int64_t offset) {
+ int64_t offset,
+ int64_t length) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ DCHECK(source_streams_.find(offset) == source_streams_.end());
- // The |source_streams_| must have an existing entry for the stream reader.
- auto current_source_stream = source_streams_.find(offset);
- DCHECK(current_source_stream != source_streams_.end());
- SourceStream* stream = current_source_stream->second.get();
+ source_streams_[offset] = base::MakeUnique<SourceStream>(offset, length);
+ SourceStream* stream = source_streams_[offset].get();
stream->SetByteStream(std::move(stream_reader));
asanka 2017/03/14 19:44:01 Are all SourceStream constructions immediately fol
xingliu 2017/03/14 22:48:29 Done, Thanks for this suggestion, yeah, this make
- RegisterAndActivateStream(stream);
+ // If the file is initialized, start to write data, or wait until file opened.
+ if (file_.in_progress())
+ RegisterAndActivateStream(stream);
}
DownloadInterruptReason DownloadFileImpl::WriteDataToFile(int64_t offset,

Powered by Google App Engine
This is Rietveld 408576698