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 e4ec806f7718c8b4de357eb9977f329a852834a7..c47621b8b103bbf8ccf570e0bad1f9860228aceb 100644 |
| --- a/content/browser/download/download_file_impl.cc |
| +++ b/content/browser/download/download_file_impl.cc |
| @@ -41,16 +41,18 @@ const int kInitialRenameRetryDelayMs = 200; |
| // Number of times a failing rename is retried before giving up. |
| const int kMaxRenameRetries = 3; |
| -DownloadFileImpl::SourceStream::SourceStream(int64_t offset, int64_t length) |
| - : offset_(offset), length_(length), bytes_written_(0), finished_(false) {} |
| +DownloadFileImpl::SourceStream::SourceStream( |
| + int64_t offset, |
| + int64_t length, |
| + std::unique_ptr<ByteStreamReader> stream_reader) |
| + : offset_(offset), |
| + length_(length), |
| + bytes_written_(0), |
| + finished_(false), |
| + stream_reader_(std::move(stream_reader)) {} |
| DownloadFileImpl::SourceStream::~SourceStream() = default; |
| -void DownloadFileImpl::SourceStream::SetByteStream( |
| - std::unique_ptr<ByteStreamReader> stream_reader) { |
| - stream_reader_ = std::move(stream_reader); |
| -} |
| - |
| void DownloadFileImpl::SourceStream::OnWriteBytesToDisk(int64_t bytes_write) { |
| bytes_written_ += bytes_write; |
| } |
| @@ -75,9 +77,8 @@ DownloadFileImpl::DownloadFileImpl( |
| observer_(observer), |
| weak_factory_(this) { |
| source_streams_[save_info_->offset] = base::MakeUnique<SourceStream>( |
| - save_info_->offset, DownloadSaveInfo::kLengthFullContent); |
| - DCHECK(source_streams_.size() == static_cast<size_t>(1)); |
| - source_streams_[save_info_->offset]->SetByteStream(std::move(stream_reader)); |
| + save_info_->offset, DownloadSaveInfo::kLengthFullContent, |
|
qinmin
2017/03/17 07:54:36
actually, this is no longer true. For resumption,
xingliu
2017/03/17 19:08:25
Good point, done.
|
| + std::move(stream_reader)); |
| download_item_net_log.AddEvent( |
| net::NetLogEventType::DOWNLOAD_FILE_CREATED, |
| @@ -120,7 +121,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 +132,17 @@ 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(); |
| - stream->SetByteStream(std::move(stream_reader)); |
| + source_streams_[offset] = |
| + base::MakeUnique<SourceStream>(offset, length, std::move(stream_reader)); |
| - RegisterAndActivateStream(stream); |
| + // If the file is initialized, start to write data, or wait until file opened. |
| + if (file_.in_progress()) |
| + RegisterAndActivateStream(source_streams_[offset].get()); |
| } |
| DownloadInterruptReason DownloadFileImpl::WriteDataToFile(int64_t offset, |