Commit 8df9eb05 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Use base::GetContinuationTaskRunner() instead of base::SequencedTaskRunnerHandle::Get()

The latter is deprecated, and doesn't seem to support thread pool
environment. So switching to the former.

BUG=1009839

Change-Id: Ieef5e65b6220d46cd262f1550324f8636dbeb68d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1918221
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715802}
parent 9949a0be
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/task/post_task.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "base/values.h" #include "base/values.h"
...@@ -194,6 +193,8 @@ void DownloadFileImpl::Initialize( ...@@ -194,6 +193,8 @@ void DownloadFileImpl::Initialize(
int64_t bytes_so_far = 0; int64_t bytes_so_far = 0;
cancel_request_callback_ = cancel_request_callback; cancel_request_callback_ = cancel_request_callback;
received_slices_ = received_slices; received_slices_ = received_slices;
if (!task_runner_)
task_runner_ = base::GetContinuationTaskRunner();
// If the last slice is finished, then we know the actual content size. // If the last slice is finished, then we know the actual content size.
if (!received_slices_.empty() && received_slices_.back().finished) { if (!received_slices_.empty() && received_slices_.back().finished) {
...@@ -451,7 +452,7 @@ void DownloadFileImpl::RenameWithRetryInternal( ...@@ -451,7 +452,7 @@ void DownloadFileImpl::RenameWithRetryInternal(
--parameters->retries_left; --parameters->retries_left;
if (parameters->time_of_first_failure.is_null()) if (parameters->time_of_first_failure.is_null())
parameters->time_of_first_failure = base::TimeTicks::Now(); parameters->time_of_first_failure = base::TimeTicks::Now();
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask( task_runner_->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&DownloadFileImpl::RenameWithRetryInternal, base::BindOnce(&DownloadFileImpl::RenameWithRetryInternal,
weak_factory_.GetWeakPtr(), std::move(parameters)), weak_factory_.GetWeakPtr(), std::move(parameters)),
...@@ -631,7 +632,7 @@ void DownloadFileImpl::StreamActive(SourceStream* source_stream, ...@@ -631,7 +632,7 @@ void DownloadFileImpl::StreamActive(SourceStream* source_stream,
// If we're stopping to yield the thread, post a task so we come back. // If we're stopping to yield the thread, post a task so we come back.
if (state == InputStream::HAS_DATA && now - start > delta && if (state == InputStream::HAS_DATA && now - start > delta &&
!should_terminate) { !should_terminate) {
base::SequencedTaskRunnerHandle::Get()->PostTask( task_runner_->PostTask(
FROM_HERE, base::BindOnce(&DownloadFileImpl::StreamActive, FROM_HERE, base::BindOnce(&DownloadFileImpl::StreamActive,
weak_factory_.GetWeakPtr(), source_stream, weak_factory_.GetWeakPtr(), source_stream,
MOJO_RESULT_OK)); MOJO_RESULT_OK));
...@@ -911,6 +912,11 @@ void DownloadFileImpl::DebugStates() const { ...@@ -911,6 +912,11 @@ void DownloadFileImpl::DebugStates() const {
DebugSlicesInfo(received_slices_); DebugSlicesInfo(received_slices_);
} }
void DownloadFileImpl::SetTaskRunnerForTesting(
scoped_refptr<base::SequencedTaskRunner> task_runner) {
task_runner_ = std::move(task_runner);
}
DownloadFileImpl::RenameParameters::RenameParameters( DownloadFileImpl::RenameParameters::RenameParameters(
RenameOption option, RenameOption option,
const base::FilePath& new_path, const base::FilePath& new_path,
......
...@@ -258,6 +258,8 @@ class DownloadFileTest : public testing::Test { ...@@ -258,6 +258,8 @@ class DownloadFileTest : public testing::Test {
base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this); base::WeakPtrFactory<DownloadFileTest> weak_ptr_factory(this);
DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE; DownloadInterruptReason result = DOWNLOAD_INTERRUPT_REASON_NONE;
base::RunLoop loop_runner; base::RunLoop loop_runner;
download_file_->SetTaskRunnerForTesting(
base::SequencedTaskRunnerHandle::Get());
download_file_->Initialize( download_file_->Initialize(
base::BindRepeating(&DownloadFileTest::SetInterruptReasonCallback, base::BindRepeating(&DownloadFileTest::SetInterruptReasonCallback,
weak_ptr_factory.GetWeakPtr(), weak_ptr_factory.GetWeakPtr(),
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/download/public/common/stream_handle_input_stream.h" #include "components/download/public/common/stream_handle_input_stream.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/task/post_task.h"
#include "components/download/public/common/download_interrupt_reasons_utils.h" #include "components/download/public/common/download_interrupt_reasons_utils.h"
#include "mojo/public/c/system/types.h" #include "mojo/public/c/system/types.h"
...@@ -34,7 +35,7 @@ void StreamHandleInputStream::Initialize() { ...@@ -34,7 +35,7 @@ void StreamHandleInputStream::Initialize() {
mojom::NetworkRequestStatus::USER_CANCELED)); mojom::NetworkRequestStatus::USER_CANCELED));
handle_watcher_ = std::make_unique<mojo::SimpleWatcher>( handle_watcher_ = std::make_unique<mojo::SimpleWatcher>(
FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::AUTOMATIC, FROM_HERE, mojo::SimpleWatcher::ArmingPolicy::AUTOMATIC,
base::SequencedTaskRunnerHandle::Get()); base::GetContinuationTaskRunner());
} }
bool StreamHandleInputStream::IsEmpty() { bool StreamHandleInputStream::IsEmpty() {
......
...@@ -190,6 +190,11 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadFileImpl : public DownloadFile { ...@@ -190,6 +190,11 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadFileImpl : public DownloadFile {
DISALLOW_COPY_AND_ASSIGN(SourceStream); DISALLOW_COPY_AND_ASSIGN(SourceStream);
}; };
// Sets the task runner for testing purpose, must be called before
// Initialize().
void SetTaskRunnerForTesting(
scoped_refptr<base::SequencedTaskRunner> task_runner);
protected: protected:
// For test class overrides. // For test class overrides.
// Validate the first |bytes_to_validate| bytes and write the next // Validate the first |bytes_to_validate| bytes and write the next
...@@ -374,6 +379,9 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadFileImpl : public DownloadFile { ...@@ -374,6 +379,9 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadFileImpl : public DownloadFile {
// TaskRunner to post updates to the |observer_|. // TaskRunner to post updates to the |observer_|.
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
// TaskRunner this object lives on after initialization.
scoped_refptr<base::SequencedTaskRunner> task_runner_;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
base::FilePath display_name_; base::FilePath display_name_;
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment