| 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..2187fe7a88c544179d32a2e5c80d40695ab165fa 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"
|
| #include "content/browser/download/parallel_download_utils.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "crypto/secure_hash.h"
|
| @@ -123,7 +124,8 @@ DownloadFileImpl::DownloadFileImpl(
|
| }
|
|
|
| DownloadFileImpl::~DownloadFileImpl() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
| +
|
| net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE);
|
| }
|
|
|
| @@ -132,7 +134,7 @@ void DownloadFileImpl::Initialize(
|
| const CancelRequestCallback& cancel_request_callback,
|
| const DownloadItem::ReceivedSlices& received_slices,
|
| bool is_parallelizable) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
|
|
| update_timer_.reset(new base::RepeatingTimer());
|
| int64_t bytes_so_far = 0;
|
| @@ -176,7 +178,7 @@ void DownloadFileImpl::AddByteStream(
|
| std::unique_ptr<ByteStreamReader> stream_reader,
|
| int64_t offset,
|
| int64_t length) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
|
|
| source_streams_[offset] =
|
| base::MakeUnique<SourceStream>(offset, length, std::move(stream_reader));
|
| @@ -196,7 +198,8 @@ void DownloadFileImpl::AddByteStream(
|
| DownloadInterruptReason DownloadFileImpl::WriteDataToFile(int64_t offset,
|
| const char* data,
|
| size_t data_len) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
| +
|
| WillWriteToDisk(data_len);
|
| return file_.WriteDataToFile(offset, data, data_len);
|
| }
|
| @@ -274,7 +277,7 @@ bool DownloadFileImpl::ShouldRetryFailedRename(DownloadInterruptReason reason) {
|
|
|
| void DownloadFileImpl::RenameWithRetryInternal(
|
| std::unique_ptr<RenameParameters> parameters) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
|
|
| base::FilePath new_path = parameters->new_path;
|
|
|
| @@ -299,8 +302,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 +470,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(
|
| + FROM_HERE, base::Bind(&DownloadFileImpl::StreamActive,
|
| + weak_factory_.GetWeakPtr(), source_stream));
|
| }
|
|
|
| if (total_incoming_data_size)
|
| @@ -526,7 +527,8 @@ void DownloadFileImpl::StreamActive(SourceStream* source_stream) {
|
| }
|
|
|
| void DownloadFileImpl::RegisterAndActivateStream(SourceStream* source_stream) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
| +
|
| ByteStreamReader* stream_reader = source_stream->stream_reader();
|
| if (stream_reader) {
|
| stream_reader->RegisterCallback(base::Bind(&DownloadFileImpl::StreamActive,
|
| @@ -616,7 +618,8 @@ bool DownloadFileImpl::IsDownloadCompleted() {
|
|
|
| void DownloadFileImpl::HandleStreamError(SourceStream* source_stream,
|
| DownloadInterruptReason reason) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::FILE);
|
| + DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
|
| +
|
| source_stream->stream_reader()->RegisterCallback(base::Closure());
|
| source_stream->set_finished(true);
|
| num_active_streams_--;
|
|
|