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 edde01e1bc0c42f0cf088cbc103c3a17e36cd7fd..0de3594f401dbed057df86d004ac51178ee0de79 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/download_task_runner.h" |
|
gab
2017/06/22 16:03:59
rm (see below)
Sigurður Ásgeirsson
2017/06/22 18:47:28
Done.
|
| #include "content/browser/download/parallel_download_utils.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "crypto/secure_hash.h" |
| @@ -120,10 +121,13 @@ DownloadFileImpl::DownloadFileImpl( |
| net_log_.BeginEvent( |
| net::NetLogEventType::DOWNLOAD_FILE_ACTIVE, |
| download_item_net_log.source().ToEventParametersCallback()); |
| + |
| + DETACH_FROM_SEQUENCE(sequence_checker_); |
| } |
| DownloadFileImpl::~DownloadFileImpl() { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| + |
| net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE); |
| } |
| @@ -132,7 +136,7 @@ void DownloadFileImpl::Initialize( |
| const CancelRequestCallback& cancel_request_callback, |
| const DownloadItem::ReceivedSlices& received_slices, |
| bool is_parallelizable) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| update_timer_.reset(new base::RepeatingTimer()); |
| int64_t bytes_so_far = 0; |
| @@ -176,7 +180,7 @@ void DownloadFileImpl::AddByteStream( |
| std::unique_ptr<ByteStreamReader> stream_reader, |
| int64_t offset, |
| int64_t length) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| source_streams_[offset] = |
| base::MakeUnique<SourceStream>(offset, length, std::move(stream_reader)); |
| @@ -196,7 +200,8 @@ void DownloadFileImpl::AddByteStream( |
| DownloadInterruptReason DownloadFileImpl::WriteDataToFile(int64_t offset, |
| const char* data, |
| size_t data_len) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| + |
| WillWriteToDisk(data_len); |
| return file_.WriteDataToFile(offset, data, data_len); |
| } |
| @@ -274,7 +279,7 @@ bool DownloadFileImpl::ShouldRetryFailedRename(DownloadInterruptReason reason) { |
| void DownloadFileImpl::RenameWithRetryInternal( |
| std::unique_ptr<RenameParameters> parameters) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| base::FilePath new_path = parameters->new_path; |
| @@ -299,8 +304,7 @@ void DownloadFileImpl::RenameWithRetryInternal( |
| --parameters->retries_left; |
| if (parameters->time_of_first_failure.is_null()) |
| parameters->time_of_first_failure = base::TimeTicks::Now(); |
| - BrowserThread::PostDelayedTask( |
| - BrowserThread::FILE, |
| + GetDownloadTaskRunner()->PostDelayedTask( |
| FROM_HERE, |
| base::Bind(&DownloadFileImpl::RenameWithRetryInternal, |
| weak_factory_.GetWeakPtr(), |
| @@ -468,10 +472,9 @@ void DownloadFileImpl::StreamActive(SourceStream* source_stream) { |
| // If we're stopping to yield the thread, post a task so we come back. |
| if (state == ByteStreamReader::STREAM_HAS_DATA && now - start > delta && |
| !should_terminate) { |
| - BrowserThread::PostTask( |
| - BrowserThread::FILE, FROM_HERE, |
| - base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr(), |
| - source_stream)); |
| + GetDownloadTaskRunner()->PostTask( |
|
gab
2017/06/22 16:03:59
Use SequencedTaskRunnerHandle::Get() here instead
Sigurður Ásgeirsson
2017/06/22 18:47:28
Nice, this also cuts down on the sequence hopping
|
| + FROM_HERE, base::Bind(&DownloadFileImpl::StreamActive, |
| + weak_factory_.GetWeakPtr(), source_stream)); |
| } |
| if (total_incoming_data_size) |
| @@ -526,7 +529,8 @@ void DownloadFileImpl::StreamActive(SourceStream* source_stream) { |
| } |
| void DownloadFileImpl::RegisterAndActivateStream(SourceStream* source_stream) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| + |
| ByteStreamReader* stream_reader = source_stream->stream_reader(); |
| if (stream_reader) { |
| stream_reader->RegisterCallback(base::Bind(&DownloadFileImpl::StreamActive, |
| @@ -616,7 +620,8 @@ bool DownloadFileImpl::IsDownloadCompleted() { |
| void DownloadFileImpl::HandleStreamError(SourceStream* source_stream, |
| DownloadInterruptReason reason) { |
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| + |
| source_stream->stream_reader()->RegisterCallback(base::Closure()); |
| source_stream->set_finished(true); |
| num_active_streams_--; |