From 0218c961e600748049cde69571472b400ea771ea Mon Sep 17 00:00:00 2001 From: Sherry Zhou Date: Wed, 1 May 2024 05:02:50 +0800 Subject: [PATCH] Fix evergreen updateClient crash (#3079) b/335726353 (cherry picked from commit 7fa46d039544b5cefdf8fe8bc9ba3a7fc0b4a9ed) --- cobalt/loader/BUILD.gn | 4 +- cobalt/loader/fetcher_cache_test.cc | 50 +++---- components/update_client/BUILD.gn | 1 - components/update_client/action_runner.cc | 6 +- components/update_client/action_runner.h | 6 +- components/update_client/component.cc | 127 +++++++++--------- components/update_client/component.h | 6 +- .../component_unpacker_unittest.cc | 4 +- components/update_client/crx_downloader.cc | 12 +- components/update_client/crx_downloader.h | 10 +- .../update_client/crx_downloader_unittest.cc | 19 +-- .../update_client/net/network_impl_cobalt.cc | 20 +-- .../net/url_loader_post_interceptor.cc | 5 +- components/update_client/persisted_data.cc | 18 +-- components/update_client/persisted_data.h | 4 +- components/update_client/ping_manager.cc | 18 +-- components/update_client/ping_manager.h | 4 +- .../update_client/ping_manager_unittest.cc | 6 +- components/update_client/request_sender.cc | 22 +-- components/update_client/request_sender.h | 4 +- .../update_client/request_sender_unittest.cc | 4 +- .../update_client/task_send_uninstall_ping.cc | 12 +- .../update_client/task_send_uninstall_ping.h | 4 +- components/update_client/task_update.cc | 12 +- components/update_client/task_update.h | 4 +- components/update_client/update_checker.cc | 22 +-- .../update_client/update_checker_unittest.cc | 6 +- components/update_client/update_client.cc | 30 ++--- .../update_client/update_client_internal.h | 4 +- .../update_client/update_client_unittest.cc | 72 +++++----- components/update_client/update_engine.cc | 50 +++---- components/update_client/update_engine.h | 4 +- 32 files changed, 286 insertions(+), 284 deletions(-) diff --git a/cobalt/loader/BUILD.gn b/cobalt/loader/BUILD.gn index 5532cbe3b244..8eb9a84f7423 100644 --- a/cobalt/loader/BUILD.gn +++ b/cobalt/loader/BUILD.gn @@ -175,9 +175,7 @@ target(gtest_target_type, "loader_test") { sources = [ "blob_fetcher_test.cc", - - # TODO: b/335330660 - Re-enable FetcherCacheTests once crash is fixed for evergreen. - # "fetcher_cache_test.cc", + "fetcher_cache_test.cc", "fetcher_factory_test.cc", "fetcher_test.h", "file_fetcher_test.cc", diff --git a/cobalt/loader/fetcher_cache_test.cc b/cobalt/loader/fetcher_cache_test.cc index 4b43db559233..5199c9cac9b6 100644 --- a/cobalt/loader/fetcher_cache_test.cc +++ b/cobalt/loader/fetcher_cache_test.cc @@ -22,8 +22,8 @@ #include "base/memory/ref_counted.h" #include "base/run_loop.h" #include "base/strings/string_number_conversions.h" +#include "base/task/sequenced_task_runner.h" #include "base/test/task_environment.h" -#include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" #include "cobalt/loader/fetcher.h" #include "net/http/http_response_headers.h" @@ -150,15 +150,15 @@ TEST_F(FetcherCacheTest, SunnyDay) { scoped_refptr headers = base::MakeRefCounted("HTTP/1.1 200 OK\n"); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireResponseStarted, base::Unretained(stub_fetcher_factory.fetcher), headers)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireReceived, base::Unretained(stub_fetcher_factory.fetcher), data_.c_str(), data_.size())); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireDone, base::Unretained(stub_fetcher_factory.fetcher))); @@ -187,7 +187,7 @@ TEST_F(FetcherCacheTest, DuplicateFetcherCache) { stub_fetcher_factorys.push_back(stub_fetcher_factory); fetcher_creators.push_back(fetcher_creator); fetchers.push_back(std::move(fetcher)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireFetcherProcess, base::Unretained(stub_fetcher_factorys[i].fetcher), @@ -219,7 +219,7 @@ TEST_F(FetcherCacheTest, MultipleFetcherCache) { stub_fetcher_factorys.push_back(stub_fetcher_factory); fetcher_creators.push_back(fetcher_creator); fetchers.push_back(std::move(fetcher)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireFetcherProcess, base::Unretained(stub_fetcher_factorys[i].fetcher), @@ -255,7 +255,7 @@ TEST_F(FetcherCacheTest, MaxFetcherCache) { stub_fetcher_factorys.push_back(stub_fetcher_factory); fetcher_creators.push_back(fetcher_creator); fetchers.push_back(std::move(fetcher)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireFetcherProcess, base::Unretained(stub_fetcher_factorys[i].fetcher), @@ -284,30 +284,30 @@ TEST_F(FetcherCacheTest, DisorderedSameFetcherCache) { std::unique_ptr fetcher2 = fetcher_creator2.Run(&handler); // Task 1: start and receive - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireResponseStarted, base::Unretained(stub_fetcher_factory1.fetcher), headers)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireReceived, base::Unretained(stub_fetcher_factory1.fetcher), data_.c_str(), data_.size())); // Task 2: start and receive - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireResponseStarted, base::Unretained(stub_fetcher_factory2.fetcher), headers)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireReceived, base::Unretained(stub_fetcher_factory2.fetcher), data_.c_str(), data_.size())); // Task 1: done - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireDone, base::Unretained(stub_fetcher_factory1.fetcher))); // Task 2: done - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireDone, base::Unretained(stub_fetcher_factory2.fetcher))); @@ -334,30 +334,30 @@ TEST_F(FetcherCacheTest, DisorderedDiffFetcherCache) { std::unique_ptr fetcher2 = fetcher_creator2.Run(&handler); // Task 1: start and receive - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireResponseStarted, base::Unretained(stub_fetcher_factory1.fetcher), headers)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireReceived, base::Unretained(stub_fetcher_factory1.fetcher), data_.c_str(), data_.size())); // Task 2: start and receive - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireResponseStarted, base::Unretained(stub_fetcher_factory2.fetcher), headers)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireReceived, base::Unretained(stub_fetcher_factory2.fetcher), data_.c_str(), data_.size())); // Task 1: done - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireDone, base::Unretained(stub_fetcher_factory1.fetcher))); // Task 2: done - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireDone, base::Unretained(stub_fetcher_factory2.fetcher))); @@ -384,29 +384,29 @@ TEST_F(FetcherCacheTest, DisorderedSlowFetcherCache) { std::unique_ptr fetcher2 = fetcher_creator2.Run(&handler); // Task 1: start and receive - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireResponseStarted, base::Unretained(stub_fetcher_factory1.fetcher), headers)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireReceived, base::Unretained(stub_fetcher_factory1.fetcher), data_.c_str(), data_.size())); // Task 2: start, receive, and done - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireResponseStarted, base::Unretained(stub_fetcher_factory2.fetcher), headers)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireReceived, base::Unretained(stub_fetcher_factory2.fetcher), data_.c_str(), data_.size())); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireDone, base::Unretained(stub_fetcher_factory2.fetcher))); // Task 1: done - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&StubFetcher::FireDone, base::Unretained(stub_fetcher_factory1.fetcher))); diff --git a/components/update_client/BUILD.gn b/components/update_client/BUILD.gn index f560fd24b067..31f6679f717e 100644 --- a/components/update_client/BUILD.gn +++ b/components/update_client/BUILD.gn @@ -123,7 +123,6 @@ static_library("test_support") { if (cobalt_pending_clean_up) { sources -= [ - "net/network_impl_cobalt.cc", "net/url_request_post_interceptor.cc", ] } diff --git a/components/update_client/action_runner.cc b/components/update_client/action_runner.cc index abcd47ba967b..b456f138e6ce 100644 --- a/components/update_client/action_runner.cc +++ b/components/update_client/action_runner.cc @@ -59,14 +59,14 @@ namespace update_client { ActionRunner::ActionRunner(const Component& component) : is_per_user_install_(component.config()->IsPerUserInstall()), component_(component), - main_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} + main_task_runner_(base::SequencedTaskRunner::GetCurrentDefault()) {} ActionRunner::~ActionRunner() { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void ActionRunner::Run(Callback run_complete) { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); run_complete_ = std::move(run_complete); diff --git a/components/update_client/action_runner.h b/components/update_client/action_runner.h index ee41890021f0..83835533e7c5 100644 --- a/components/update_client/action_runner.h +++ b/components/update_client/action_runner.h @@ -15,7 +15,7 @@ #include "base/files/file_path.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" #include "build/build_config.h" #include "components/update_client/component_unpacker.h" @@ -59,14 +59,14 @@ class ActionRunner { const Component& component_; // Used to post callbacks to the main thread. - scoped_refptr main_task_runner_; + scoped_refptr main_task_runner_; // Contains the unpack path for the component associated with the run action. base::FilePath unpack_path_; Callback run_complete_; - THREAD_CHECKER(thread_checker_); + SEQUENCE_CHECKER(sequence_checker_); DISALLOW_COPY_AND_ASSIGN(ActionRunner); }; diff --git a/components/update_client/component.cc b/components/update_client/component.cc index 2560392c7eb9..f88f384a8ef5 100644 --- a/components/update_client/component.cc +++ b/components/update_client/component.cc @@ -12,8 +12,9 @@ #include "base/files/scoped_temp_dir.h" #include "base/location.h" #include "base/logging.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_number_conversions.h" +#include "base/task/bind_post_task.h" +#include "base/task/sequenced_task_runner.h" #include "base/task/thread_pool.h" #include "base/threading/thread_task_runner_handle.h" #include "base/values.h" @@ -77,7 +78,7 @@ using InstallOnBlockingTaskRunnerCompleteCallback = base::OnceCallback< void(ErrorCategory error_category, int error_code, int extra_code1)>; void InstallComplete( - scoped_refptr main_task_runner, + scoped_refptr main_task_runner, InstallOnBlockingTaskRunnerCompleteCallback callback, const base::FilePath& unpack_path, const CrxInstaller::Result& result) { @@ -87,7 +88,7 @@ void InstallComplete( base::ThreadPool::PostTask( FROM_HERE, {base::TaskPriority::BEST_EFFORT, base::MayBlock()}, base::BindOnce( - [](scoped_refptr main_task_runner, + [](scoped_refptr main_task_runner, InstallOnBlockingTaskRunnerCompleteCallback callback, const base::FilePath& unpack_path, const CrxInstaller::Result& result) { @@ -111,7 +112,7 @@ void InstallComplete( } void InstallOnBlockingTaskRunner( - scoped_refptr main_task_runner, + scoped_refptr main_task_runner, const base::FilePath& unpack_path, const std::string& public_key, #if defined(STARBOARD) @@ -195,7 +196,7 @@ void InstallOnBlockingTaskRunner( } void UnpackCompleteOnBlockingTaskRunner( - scoped_refptr main_task_runner, + scoped_refptr main_task_runner, #if defined(IN_MEMORY_UPDATES) const base::FilePath& installation_dir, #else @@ -261,7 +262,7 @@ void UnpackCompleteOnBlockingTaskRunner( } void StartInstallOnBlockingTaskRunner( - scoped_refptr main_task_runner, + scoped_refptr main_task_runner, const std::vector& pk_hash, #if defined(IN_MEMORY_UPDATES) const base::FilePath& installation_dir, @@ -350,7 +351,7 @@ bool Component::is_foreground() const { } void Component::Handle(CallbackHandleComplete callback_handle_complete) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(state_); #if defined(STARBOARD) LOG(INFO) << "Component::Handle"; @@ -363,14 +364,14 @@ void Component::Handle(CallbackHandleComplete callback_handle_complete) { #if defined(STARBOARD) void Component::Cancel() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); is_cancelled_ = true; state_->Cancel(); } #endif void Component::ChangeState(std::unique_ptr next_state) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "Component::ChangeState next_state=" << ((next_state)? next_state->state_name(): "nullptr"); @@ -382,12 +383,12 @@ void Component::ChangeState(std::unique_ptr next_state) { else is_handled_ = true; - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, std::move(callback_handle_complete_)); } CrxUpdateItem Component::GetCrxUpdateItem() const { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); CrxUpdateItem crx_update_item; crx_update_item.state = state_->state(); @@ -405,7 +406,7 @@ CrxUpdateItem Component::GetCrxUpdateItem() const { } void Component::SetParseResult(const ProtocolParser::Result& result) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_EQ(0, update_check_error_); @@ -436,7 +437,7 @@ void Component::SetParseResult(const ProtocolParser::Result& result) { } void Component::Uninstall(const base::Version& version, int reason) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_EQ(ComponentState::kNew, state()); @@ -454,7 +455,7 @@ void Component::SetUpdateCheckResult( const base::Optional& result, ErrorCategory error_category, int error) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_EQ(ComponentState::kChecking, state()); error_category_ = error_category; @@ -462,7 +463,7 @@ void Component::SetUpdateCheckResult( if (result) SetParseResult(result.value()); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, std::move(update_check_complete_)); } @@ -478,7 +479,7 @@ void Component::AppendEvent(base::Value::Dict event) { } void Component::NotifyObservers(UpdateClient::Observer::Events event) const { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) if (!is_cancelled_) { @@ -492,7 +493,7 @@ void Component::NotifyObservers(UpdateClient::Observer::Events event) const { } base::TimeDelta Component::GetUpdateDuration() const { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (update_begin_.is_null()) return base::TimeDelta(); @@ -607,7 +608,7 @@ Component::State::State(Component* component, ComponentState state) Component::State::~State() {} void Component::State::Handle(CallbackNextState callback_next_state) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "Component::State::Handle"; #endif @@ -619,29 +620,29 @@ void Component::State::Handle(CallbackNextState callback_next_state) { #if defined(STARBOARD) void Component::State::Cancel() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); // Further work may be needed to ensure cancellation during any state results // in a clear result and no memory leaks. } #endif void Component::State::TransitionState(std::unique_ptr next_state) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(next_state); #if defined(STARBOARD) LOG(INFO) << "Component::State::TransitionState next_state=" << ((next_state)? next_state->state_name(): "nullptr"); #endif - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(callback_next_state_), std::move(next_state))); } void Component::State::EndState() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(callback_next_state_), nullptr)); } @@ -649,11 +650,11 @@ Component::StateNew::StateNew(Component* component) : State(component, ComponentState::kNew) {} Component::StateNew::~StateNew() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void Component::StateNew::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = State::component(); @@ -675,7 +676,7 @@ Component::StateChecking::StateChecking(Component* component) : State(component, ComponentState::kChecking) {} Component::StateChecking::~StateChecking() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } // Unlike how other states are handled, this function does not change the @@ -685,7 +686,7 @@ Component::StateChecking::~StateChecking() { // together but the state machine defines the transitions for one component // at a time. void Component::StateChecking::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = State::component(); DCHECK(component.crx_component()); @@ -698,18 +699,18 @@ void Component::StateChecking::DoHandle() { } void Component::StateChecking::UpdateCheckComplete() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = State::component(); #if defined(STARBOARD) auto& config = component.update_context_.config; auto metadata = component.update_context_.update_checker->GetPersistedData(); if (metadata != nullptr) { - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&PersistedData::SetUpdaterChannel, base::Unretained(metadata), component.id_, config->GetChannel())); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&PersistedData::SetLatestChannel, base::Unretained(metadata), config->GetChannel())); @@ -741,11 +742,11 @@ Component::StateUpdateError::StateUpdateError(Component* component) : State(component, ComponentState::kUpdateError) {} Component::StateUpdateError::~StateUpdateError() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void Component::StateUpdateError::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = State::component(); @@ -771,11 +772,11 @@ Component::StateCanUpdate::StateCanUpdate(Component* component) : State(component, ComponentState::kCanUpdate) {} Component::StateCanUpdate::~StateCanUpdate() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void Component::StateCanUpdate::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = State::component(); DCHECK(component.crx_component()); @@ -814,11 +815,11 @@ Component::StateUpToDate::StateUpToDate(Component* component) : State(component, ComponentState::kUpToDate) {} Component::StateUpToDate::~StateUpToDate() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void Component::StateUpToDate::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = State::component(); DCHECK(component.crx_component()); @@ -831,18 +832,18 @@ Component::StateDownloadingDiff::StateDownloadingDiff(Component* component) : State(component, ComponentState::kDownloadingDiff) {} Component::StateDownloadingDiff::~StateDownloadingDiff() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } #if defined(STARBOARD) void Component::StateDownloadingDiff::Cancel() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); crx_downloader_->CancelDownload(); } #endif void Component::StateDownloadingDiff::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(IN_MEMORY_UPDATES) auto& component = Component::State::component(); @@ -881,7 +882,7 @@ void Component::StateDownloadingDiff::DoHandle() { // times due to how the CRX downloader switches between different downloaders // and fallback urls. void Component::StateDownloadingDiff::DownloadProgress(const std::string& id) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); component().NotifyObservers(Events::COMPONENT_UPDATE_DOWNLOADING); } @@ -889,7 +890,7 @@ void Component::StateDownloadingDiff::DownloadProgress(const std::string& id) { void Component::StateDownloadingDiff::DownloadComplete( const std::string& id, const CrxDownloader::Result& download_result) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = Component::State::component(); for (const auto& download_metrics : crx_downloader_->download_metrics()) @@ -925,18 +926,18 @@ Component::StateDownloading::StateDownloading(Component* component) : State(component, ComponentState::kDownloading) {} Component::StateDownloading::~StateDownloading() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } #if defined(STARBOARD) void Component::StateDownloading::Cancel() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); crx_downloader_->CancelDownload(); } #endif void Component::StateDownloading::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(IN_MEMORY_UPDATES) auto& component = Component::State::component(); @@ -975,7 +976,7 @@ void Component::StateDownloading::DoHandle() { // times due to how the CRX downloader switches between different downloaders // and fallback urls. void Component::StateDownloading::DownloadProgress(const std::string& id) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); component().NotifyObservers(Events::COMPONENT_UPDATE_DOWNLOADING); } @@ -983,7 +984,7 @@ void Component::StateDownloading::DownloadProgress(const std::string& id) { void Component::StateDownloading::DownloadComplete( const std::string& id, const CrxDownloader::Result& download_result) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = Component::State::component(); @@ -1020,11 +1021,11 @@ Component::StateUpdatingDiff::StateUpdatingDiff(Component* component) : State(component, ComponentState::kUpdatingDiff) {} Component::StateUpdatingDiff::~StateUpdatingDiff() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void Component::StateUpdatingDiff::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(IN_MEMORY_UPDATES) auto& component = Component::State::component(); @@ -1042,7 +1043,7 @@ void Component::StateUpdatingDiff::DoHandle() { FROM_HERE, base::BindOnce( &update_client::StartInstallOnBlockingTaskRunner, - base::ThreadTaskRunnerHandle::Get(), + base::SequencedTaskRunner::GetCurrentDefault(), component.crx_component()->pk_hash, #if defined(IN_MEMORY_UPDATES) component.installation_dir_, @@ -1066,7 +1067,7 @@ void Component::StateUpdatingDiff::DoHandle() { void Component::StateUpdatingDiff::InstallComplete(ErrorCategory error_category, int error_code, int extra_code1) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = Component::State::component(); @@ -1097,14 +1098,14 @@ Component::StateUpdating::StateUpdating(Component* component) : State(component, ComponentState::kUpdating) {} Component::StateUpdating::~StateUpdating() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void Component::StateUpdating::DoHandle() { #if defined(STARBOARD) LOG(INFO) << "Component::StateUpdating::DoHandle()"; #endif - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(IN_MEMORY_UPDATES) auto& component = Component::State::component(); @@ -1121,7 +1122,7 @@ void Component::StateUpdating::DoHandle() { ->PostTask(FROM_HERE, base::BindOnce( &update_client::StartInstallOnBlockingTaskRunner, - base::ThreadTaskRunnerHandle::Get(), + base::SequencedTaskRunner::GetCurrentDefault(), component.crx_component()->pk_hash, #if defined(IN_MEMORY_UPDATES) component.installation_dir_, @@ -1145,7 +1146,7 @@ void Component::StateUpdating::DoHandle() { void Component::StateUpdating::InstallComplete(ErrorCategory error_category, int error_code, int extra_code1) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = Component::State::component(); @@ -1170,15 +1171,15 @@ void Component::StateUpdating::InstallComplete(ErrorCategory error_category, Component::StateUpdated::StateUpdated(Component* component) : State(component, ComponentState::kUpdated) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } Component::StateUpdated::~StateUpdated() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void Component::StateUpdated::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = State::component(); DCHECK(component.crx_component()); @@ -1194,15 +1195,15 @@ void Component::StateUpdated::DoHandle() { Component::StateUninstalled::StateUninstalled(Component* component) : State(component, ComponentState::kUninstalled) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } Component::StateUninstalled::~StateUninstalled() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void Component::StateUninstalled::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = State::component(); DCHECK(component.crx_component()); @@ -1216,11 +1217,11 @@ Component::StateRun::StateRun(Component* component) : State(component, ComponentState::kRun) {} Component::StateRun::~StateRun() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void Component::StateRun::DoHandle() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); const auto& component = State::component(); DCHECK(component.crx_component()); @@ -1233,7 +1234,7 @@ void Component::StateRun::DoHandle() { void Component::StateRun::ActionRunComplete(bool succeeded, int error_code, int extra_code1) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto& component = State::component(); diff --git a/components/update_client/component.h b/components/update_client/component.h index d1c756a57c7d..b763f7ddcbe3 100644 --- a/components/update_client/component.h +++ b/components/update_client/component.h @@ -18,7 +18,7 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/optional.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" #include "base/time/time.h" #include "base/version.h" #include "components/update_client/crx_downloader.h" @@ -219,7 +219,7 @@ class Component { Component& component() { return component_; } const Component& component() const { return component_; } - base::ThreadChecker thread_checker_; + SEQUENCE_CHECKER(sequence_checker_); const ComponentState state_; @@ -444,7 +444,7 @@ class Component { int error_code, int extra_code1) const; - base::ThreadChecker thread_checker_; + SEQUENCE_CHECKER(sequence_checker_); const std::string id_; base::Optional crx_component_; diff --git a/components/update_client/component_unpacker_unittest.cc b/components/update_client/component_unpacker_unittest.cc index ae93621134c9..9a4f28032ba6 100644 --- a/components/update_client/component_unpacker_unittest.cc +++ b/components/update_client/component_unpacker_unittest.cc @@ -78,8 +78,8 @@ class ComponentUnpackerTest : public testing::Test { void RunThreads(); base::test::TaskEnvironment scoped_task_environment_; - const scoped_refptr main_thread_task_runner_ = - base::ThreadTaskRunnerHandle::Get(); + const scoped_refptr main_thread_task_runner_ = + base::SequencedTaskRunner::GetCurrentDefault(); base::RunLoop runloop_; base::OnceClosure quit_closure_ = runloop_.QuitClosure(); diff --git a/components/update_client/crx_downloader.cc b/components/update_client/crx_downloader.cc index c55cb2691f53..b40925ec16a3 100644 --- a/components/update_client/crx_downloader.cc +++ b/components/update_client/crx_downloader.cc @@ -10,9 +10,9 @@ #include "base/files/file_util.h" #include "base/location.h" #include "base/logging.h" +#include "base/task/sequenced_task_runner.h" #include "base/task/task_traits.h" #include "base/task/thread_pool.h" -#include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" #if defined(OS_WIN) #include "components/update_client/background_downloader_win.h" @@ -60,7 +60,7 @@ std::unique_ptr CrxDownloader::Create( } CrxDownloader::CrxDownloader(std::unique_ptr successor) - : main_task_runner_(base::ThreadTaskRunnerHandle::Get()), + : main_task_runner_(base::SequencedTaskRunner::GetCurrentDefault()), successor_(std::move(successor)) { #if defined(STARBOARD) LOG(INFO) << "CrxDownloader::CrxDownloader"; @@ -119,7 +119,7 @@ void CrxDownloader::StartDownload(const std::vector& urls, std::string* dst, #endif DownloadCallback download_callback) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(IN_MEMORY_UPDATES) CHECK(dst != nullptr); #endif @@ -166,7 +166,7 @@ void CrxDownloader::OnDownloadComplete( bool is_handled, const Result& result, const DownloadMetrics& download_metrics) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "CrxDownloader::OnDownloadComplete"; #endif @@ -183,7 +183,7 @@ void CrxDownloader::OnDownloadComplete( } void CrxDownloader::OnDownloadProgress() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (progress_callback_.is_null()) return; @@ -241,7 +241,7 @@ void CrxDownloader::HandleDownloadError( bool is_handled, const Result& result, const DownloadMetrics& download_metrics) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_NE(0, result.error); #if !defined(IN_MEMORY_UPDATES) DCHECK(result.response.empty()); diff --git a/components/update_client/crx_downloader.h b/components/update_client/crx_downloader.h index 6263a4109cb7..9d311b9f0060 100644 --- a/components/update_client/crx_downloader.h +++ b/components/update_client/crx_downloader.h @@ -15,8 +15,8 @@ #include "base/files/file_path.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/single_thread_task_runner.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" +#include "base/task/sequenced_task_runner.h" #include "url/gurl.h" #if defined(STARBOARD) @@ -170,7 +170,7 @@ class CrxDownloader { // Returns the url which is currently being downloaded from. GURL url() const; - scoped_refptr main_task_runner() const { + scoped_refptr main_task_runner() const { return main_task_runner_; } @@ -192,10 +192,10 @@ class CrxDownloader { const Result& result, const DownloadMetrics& download_metrics); - base::ThreadChecker thread_checker_; + SEQUENCE_CHECKER(sequence_checker_); // Used to post callbacks to the main thread. - scoped_refptr main_task_runner_; + scoped_refptr main_task_runner_; std::vector urls_; diff --git a/components/update_client/crx_downloader_unittest.cc b/components/update_client/crx_downloader_unittest.cc index 5b4809384493..e5dccb762cec 100644 --- a/components/update_client/crx_downloader_unittest.cc +++ b/components/update_client/crx_downloader_unittest.cc @@ -13,9 +13,9 @@ #include "base/memory/ref_counted.h" #include "base/path_service.h" #include "base/run_loop.h" -#include "base/test/bind_test_util.h" -#include "base/test/scoped_task_environment.h" -#include "base/threading/thread_task_runner_handle.h" +#include "base/task/sequenced_task_runner.h" +#include "base/test/bind.h" +#include "base/test/task_environment.h" #include "build/build_config.h" #include "components/update_client/net/network_chromium.h" #include "components/update_client/update_client_errors.h" @@ -107,7 +107,7 @@ class CrxDownloaderTest : public testing::Test { static const int kExpectedContext = 0xaabb; private: - base::test::ScopedTaskEnvironment scoped_task_environment_; + base::test::TaskEnvironment task_environment_; #if defined(STARBOARD) scoped_refptr context_; #else @@ -129,11 +129,11 @@ CrxDownloaderTest::CrxDownloaderTest() crx_context_(0), num_download_complete_calls_(0), num_progress_calls_(0), - scoped_task_environment_( - base::test::ScopedTaskEnvironment::MainThreadType::IO), + task_environment_( + base::test::TaskEnvironment::MainThreadType::IO), #if defined(STARBOARD) context_(base::MakeRefCounted( - base::ThreadTaskRunnerHandle::Get())) { + base::SequencedTaskRunner::GetCurrentDefault())) { } CrxDownloaderTest::~CrxDownloaderTest() { @@ -162,7 +162,8 @@ void CrxDownloaderTest::SetUp() { crx_downloader_->set_progress_callback(progress_callback_); get_interceptor_ = std::make_unique( - base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get()); + base::SequencedTaskRunner::GetCurrentDefault(), + base::SequencedTaskRunner::GetCurrentDefault()); #else crx_downloader_ = CrxDownloader::Create( false, base::MakeRefCounted( @@ -228,7 +229,7 @@ void CrxDownloaderTest::RunThreads() { } void CrxDownloaderTest::RunThreadsUntilIdle() { - scoped_task_environment_.RunUntilIdle(); + task_environment_.RunUntilIdle(); base::RunLoop().RunUntilIdle(); } diff --git a/components/update_client/net/network_impl_cobalt.cc b/components/update_client/net/network_impl_cobalt.cc index 45002059f21d..a64a61d4aafd 100644 --- a/components/update_client/net/network_impl_cobalt.cc +++ b/components/update_client/net/network_impl_cobalt.cc @@ -20,6 +20,7 @@ #include "base/bind.h" #include "base/callback.h" #include "base/functional/callback_helpers.h" +#include "base/strings/stringprintf.h" #include "base/threading/thread_task_runner_handle.h" #include "cobalt/base/polymorphic_downcast.h" #include "cobalt/loader/url_fetcher_string_writer.h" @@ -184,25 +185,26 @@ void NetworkFetcherCobaltImpl::OnURLFetchResponseStarted( void NetworkFetcherCobaltImpl::OnURLFetchComplete( const net::URLFetcher* source) { DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + LOG(INFO) << "cobalt::updater::NetworkFetcher::OnURLFetchComplete"; const net::Error status = source->GetStatus(); const int response_code = source->GetResponseCode(); if (url_fetcher_type_ == kUrlFetcherTypePostRequest) { - OnPostRequestComplete(source, status.error()); + OnPostRequestComplete(source, status); #if defined(IN_MEMORY_UPDATES) } else if (url_fetcher_type_ == kUrlFetcherTypeDownloadToString) { - OnDownloadToStringComplete(source, status.error()); + OnDownloadToStringComplete(source, status); } #else } else if (url_fetcher_type_ == kUrlFetcherTypeDownloadToFile) { - OnDownloadToFileComplete(source, status.error()); + OnDownloadToFileComplete(source, status); } #endif - if (!status.is_success() || !IsResponseCodeSuccess(response_code)) { - std::string msg(base::StringPrintf( - "NetworkFetcher error on %s : %s, response code %d", - source->GetURL().spec().c_str(), - net::ErrorToString(status.error()).c_str(), response_code)); + if (status != net::OK || !IsResponseCodeSuccess(response_code)) { + std::string msg( + base::StringPrintf("NetworkFetcher error on %s : %s, response code %d", + source->GetURL().spec().c_str(), + net::ErrorToString(status).c_str(), response_code)); return HandleError(msg).InvalidateThis(); } url_fetcher_.reset(); @@ -231,9 +233,9 @@ void NetworkFetcherCobaltImpl::CreateUrlFetcher( // Request mode is kCORSModeOmitCredentials. const uint32 kDisableCookiesAndCacheLoadFlags = net::LOAD_NORMAL | net::LOAD_DO_NOT_SAVE_COOKIES | - net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SEND_AUTH_DATA | net::LOAD_DISABLE_CACHE; url_fetcher_->SetLoadFlags(kDisableCookiesAndCacheLoadFlags); + url_fetcher_->SetAllowCredentials(false); url_fetcher_->SetAutomaticallyRetryOnNetworkChanges( kMaxRetriesOnNetworkChange); diff --git a/components/update_client/net/url_loader_post_interceptor.cc b/components/update_client/net/url_loader_post_interceptor.cc index 11a2af87933a..6ddd2c51454b 100644 --- a/components/update_client/net/url_loader_post_interceptor.cc +++ b/components/update_client/net/url_loader_post_interceptor.cc @@ -9,6 +9,7 @@ #include "base/macros.h" #include "base/run_loop.h" #include "base/strings/stringprintf.h" +#include "base/task/sequenced_task_runner.h" #include "base/test/bind_test_util.h" #include "components/update_client/test_configurator.h" #include "net/test/embedded_test_server/embedded_test_server.h" @@ -120,7 +121,7 @@ void URLLoaderPostInterceptor::Pause() { void URLLoaderPostInterceptor::Resume() { is_paused_ = false; - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindLambdaForTesting([&]() { if (!pending_expectations_.size()) return; @@ -182,7 +183,7 @@ void URLLoaderPostInterceptor::InitializeWithInterceptor() { const std::string response_body(expectation.second.response_body); if (url_job_request_ready_callback_) { - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, std::move(url_job_request_ready_callback_)); } diff --git a/components/update_client/persisted_data.cc b/components/update_client/persisted_data.cc index 5b51294cff4a..bf6838896077 100644 --- a/components/update_client/persisted_data.cc +++ b/components/update_client/persisted_data.cc @@ -27,13 +27,13 @@ PersistedData::PersistedData(PrefService* pref_service, activity_data_service_(activity_data_service) {} PersistedData::~PersistedData() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } int PersistedData::GetInt(const std::string& id, const std::string& key, int fallback) const { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); // We assume ids do not contain '.' characters. DCHECK_EQ(std::string::npos, id.find('.')); if (!pref_service_) @@ -49,7 +49,7 @@ int PersistedData::GetInt(const std::string& id, std::string PersistedData::GetString(const std::string& id, const std::string& key) const { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); // We assume ids do not contain '.' characters. DCHECK_EQ(std::string::npos, id.find('.')); if (!pref_service_) @@ -107,7 +107,7 @@ std::string PersistedData::GetCohortHint(const std::string& id) const { void PersistedData::SetDateLastRollCall(const std::vector& ids, int datenum) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (!pref_service_ || datenum < 0) return; ScopedDictPrefUpdate update(pref_service_, kPersistedDataPreference); @@ -122,7 +122,7 @@ void PersistedData::SetDateLastRollCall(const std::vector& ids, void PersistedData::SetDateLastActive(const std::vector& ids, int datenum) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (!pref_service_ || datenum < 0) return; ScopedDictPrefUpdate update(pref_service_, kPersistedDataPreference); @@ -140,7 +140,7 @@ void PersistedData::SetDateLastActive(const std::vector& ids, void PersistedData::SetString(const std::string& id, const std::string& key, const std::string& value) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (!pref_service_) return; ScopedDictPrefUpdate update(pref_service_, kPersistedDataPreference); @@ -158,7 +158,7 @@ void PersistedData::SetUpdaterChannel(const std::string& id, SetString(id, "updaterchannel", channel); } void PersistedData::SetLatestChannel(const std::string& channel) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (!pref_service_) return; ScopedDictPrefUpdate update(pref_service_, kPersistedDataPreference); @@ -186,14 +186,14 @@ bool PersistedData::GetActiveBit(const std::string& id) const { } int PersistedData::GetDaysSinceLastRollCall(const std::string& id) const { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); return activity_data_service_ ? activity_data_service_->GetDaysSinceLastRollCall(id) : kDaysUnknown; } int PersistedData::GetDaysSinceLastActive(const std::string& id) const { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); return activity_data_service_ ? activity_data_service_->GetDaysSinceLastActive(id) : kDaysUnknown; diff --git a/components/update_client/persisted_data.h b/components/update_client/persisted_data.h index 6a355949fff6..715cb2b36c35 100644 --- a/components/update_client/persisted_data.h +++ b/components/update_client/persisted_data.h @@ -9,7 +9,7 @@ #include #include "base/macros.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" #include "base/values.h" class PrefRegistrySimple; @@ -133,7 +133,7 @@ class PersistedData { const std::string& key, const std::string& value); - base::ThreadChecker thread_checker_; + SEQUENCE_CHECKER(sequence_checker_); PrefService* pref_service_; ActivityDataService* activity_data_service_; diff --git a/components/update_client/ping_manager.cc b/components/update_client/ping_manager.cc index a2486ef98b47..811b3ac9630c 100644 --- a/components/update_client/ping_manager.cc +++ b/components/update_client/ping_manager.cc @@ -15,7 +15,7 @@ #include "base/location.h" #include "base/logging.h" #include "base/macros.h" -#include "base/threading/thread_task_runner_handle.h" +#include "base/task/sequenced_task_runner.h" #include "components/update_client/component.h" #include "components/update_client/configurator.h" #include "components/update_client/protocol_definition.h" @@ -58,7 +58,7 @@ class PingSender : public base::RefCountedThreadSafe { const std::string& response, int retry_after_sec); - THREAD_CHECKER(thread_checker_); + SEQUENCE_CHECKER(sequence_checker_); const scoped_refptr config_; Callback callback_; @@ -70,18 +70,18 @@ class PingSender : public base::RefCountedThreadSafe { PingSender::PingSender(scoped_refptr config) : config_(config) {} PingSender::~PingSender() { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void PingSender::SendPing(const Component& component, Callback callback) { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "PingSender::SendPing"; #endif if (component.events().empty()) { - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(callback), kErrorNoEvents, "")); return; } @@ -93,7 +93,7 @@ void PingSender::SendPing(const Component& component, Callback callback) { RemoveUnsecureUrls(&urls); if (urls.empty()) { - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(callback), kErrorNoUrl, "")); return; } @@ -129,7 +129,7 @@ void PingSender::Cancel() { void PingSender::SendPingComplete(int error, const std::string& response, int retry_after_sec) { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); std::move(callback_).Run(error, response); } @@ -154,14 +154,14 @@ void PingManager::Cancel() { #endif PingManager::~PingManager() { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "PingManager::~PingManager"; #endif } void PingManager::SendPing(const Component& component, Callback callback) { - DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "PingManager::SendPing"; diff --git a/components/update_client/ping_manager.h b/components/update_client/ping_manager.h index 799221ddfd14..822a0ae7da5c 100644 --- a/components/update_client/ping_manager.h +++ b/components/update_client/ping_manager.h @@ -10,7 +10,7 @@ #include "base/functional/callback_forward.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" namespace update_client { @@ -44,7 +44,7 @@ class PingManager : public base::RefCountedThreadSafe { private: friend class base::RefCountedThreadSafe; - THREAD_CHECKER(thread_checker_); + SEQUENCE_CHECKER(sequence_checker_); const scoped_refptr config_; #if defined(STARBOARD) diff --git a/components/update_client/ping_manager_unittest.cc b/components/update_client/ping_manager_unittest.cc index fe349f9e1fd9..7dc3ec049c76 100644 --- a/components/update_client/ping_manager_unittest.cc +++ b/components/update_client/ping_manager_unittest.cc @@ -16,8 +16,8 @@ #include "base/json/json_reader.h" #include "base/memory/ref_counted.h" #include "base/run_loop.h" +#include "base/task/sequenced_task_runner.h" #include "base/test/scoped_task_environment.h" -#include "base/threading/thread_task_runner_handle.h" #include "base/version.h" #include "components/update_client/component.h" #include "components/update_client/protocol_definition.h" @@ -118,8 +118,8 @@ INSTANTIATE_TEST_SUITE_P(Parameterized, PingManagerTest, testing::Bool()); TEST_P(PingManagerTest, SendPing) { #if defined(STARBOARD) - auto interceptor_factory = - std::make_unique(base::ThreadTaskRunnerHandle::Get()); + auto interceptor_factory = std::make_unique( + base::SequencedTaskRunner::GetCurrentDefault()); auto interceptor = interceptor_factory->CreateInterceptor(); #else auto interceptor = std::make_unique( diff --git a/components/update_client/request_sender.cc b/components/update_client/request_sender.cc index 2f3d878a39ac..e1f03ccd1d4f 100644 --- a/components/update_client/request_sender.cc +++ b/components/update_client/request_sender.cc @@ -12,7 +12,7 @@ #include "base/logging.h" #include "base/numerics/safe_conversions.h" #include "base/strings/stringprintf.h" -#include "base/threading/thread_task_runner_handle.h" +#include "base/task/sequenced_task_runner.h" #include "components/client_update_protocol/ecdsa.h" #include "components/update_client/configurator.h" #include "components/update_client/network.h" @@ -35,7 +35,7 @@ RequestSender::RequestSender(scoped_refptr config) : config_(config) {} RequestSender::~RequestSender() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void RequestSender::Send( @@ -44,7 +44,7 @@ void RequestSender::Send( const std::string& request_body, bool use_signing, RequestSenderCallback request_sender_callback) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "RequestSender::Send"; #endif @@ -74,7 +74,7 @@ void RequestSender::Send( void RequestSender::SendInternal() { DCHECK(cur_url_ != urls_.end()); DCHECK(cur_url_->is_valid()); - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); GURL url(*cur_url_); @@ -89,7 +89,7 @@ void RequestSender::SendInternal() { network_fetcher_ = config_->GetNetworkFetcherFactory()->Create(); if (!network_fetcher_) { - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&RequestSender::SendInternalComplete, base::Unretained(this), @@ -122,7 +122,7 @@ void RequestSender::SendInternalComplete(int error, #endif if (!error) { if (!use_signing_) { - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(request_sender_callback_), 0, response_body, retry_after_sec)); return; @@ -131,7 +131,7 @@ void RequestSender::SendInternalComplete(int error, DCHECK(use_signing_); DCHECK(signer_); if (signer_->ValidateResponse(response_body, response_etag)) { - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(request_sender_callback_), 0, response_body, retry_after_sec)); return; @@ -145,7 +145,7 @@ void RequestSender::SendInternalComplete(int error, // A positive |retry_after_sec| is a hint from the server that the client // should not send further request until the cooldown has expired. if (retry_after_sec <= 0 && ++cur_url_ != urls_.end() && - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&RequestSender::SendInternal, base::Unretained(this)))) { return; @@ -166,7 +166,7 @@ void RequestSender::OnNetworkFetcherComplete( int net_error, const std::string& header_etag, int64_t xheader_retry_after_sec) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "RequestSender::OnNetworkFetcherComplete"; #endif @@ -187,7 +187,7 @@ void RequestSender::OnNetworkFetcherComplete( if (original_url.SchemeIsCryptographic() && error > 0) retry_after_sec = base::saturated_cast(xheader_retry_after_sec); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&RequestSender::SendInternalComplete, base::Unretained(this), error, response_body ? *response_body : std::string(), @@ -195,7 +195,7 @@ void RequestSender::OnNetworkFetcherComplete( } void RequestSender::HandleSendError(int error, int retry_after_sec) { - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(request_sender_callback_), error, std::string(), retry_after_sec)); } diff --git a/components/update_client/request_sender.h b/components/update_client/request_sender.h index 19360478ca43..2d5e711c41f7 100644 --- a/components/update_client/request_sender.h +++ b/components/update_client/request_sender.h @@ -15,7 +15,7 @@ #include "base/containers/flat_map.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" #include "url/gurl.h" namespace client_update_protocol { @@ -92,7 +92,7 @@ class RequestSender { // Helper function to handle a non-continuable error in Send. void HandleSendError(int error, int retry_after_sec); - base::ThreadChecker thread_checker_; + SEQUENCE_CHECKER(sequence_checker_); const scoped_refptr config_; diff --git a/components/update_client/request_sender_unittest.cc b/components/update_client/request_sender_unittest.cc index cd6911b4bd10..de10f7897b51 100644 --- a/components/update_client/request_sender_unittest.cc +++ b/components/update_client/request_sender_unittest.cc @@ -103,8 +103,8 @@ void RequestSenderTest::SetUp() { request_sender_ = std::make_unique(config_); #if defined(STARBOARD) - interceptor_factory_ = - std::make_unique(base::ThreadTaskRunnerHandle::Get()); + interceptor_factory_ = std::make_unique( + base::SequencedTaskRunner::GetCurrentDefault()); post_interceptor_1_ = interceptor_factory_->CreateInterceptorForPath(kUrlPath1); post_interceptor_2_ = diff --git a/components/update_client/task_send_uninstall_ping.cc b/components/update_client/task_send_uninstall_ping.cc index 018bb1dfafeb..f9bc6290d016 100644 --- a/components/update_client/task_send_uninstall_ping.cc +++ b/components/update_client/task_send_uninstall_ping.cc @@ -7,7 +7,7 @@ #include "base/bind.h" #include "base/location.h" -#include "base/threading/thread_task_runner_handle.h" +#include "base/task/sequenced_task_runner.h" #include "base/version.h" #include "components/update_client/update_client.h" #include "components/update_client/update_engine.h" @@ -27,11 +27,11 @@ TaskSendUninstallPing::TaskSendUninstallPing( callback_(std::move(callback)) {} TaskSendUninstallPing::~TaskSendUninstallPing() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); } void TaskSendUninstallPing::Run() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (id_.empty()) { TaskComplete(Error::INVALID_ARGUMENT); @@ -44,7 +44,7 @@ void TaskSendUninstallPing::Run() { } void TaskSendUninstallPing::Cancel() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); TaskComplete(Error::UPDATE_CANCELED); } @@ -54,9 +54,9 @@ std::vector TaskSendUninstallPing::GetIds() const { } void TaskSendUninstallPing::TaskComplete(Error error) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(callback_), scoped_refptr(this), error)); } diff --git a/components/update_client/task_send_uninstall_ping.h b/components/update_client/task_send_uninstall_ping.h index 9367b3d4b4a6..83078cfa7a7b 100644 --- a/components/update_client/task_send_uninstall_ping.h +++ b/components/update_client/task_send_uninstall_ping.h @@ -11,7 +11,7 @@ #include "base/callback.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" #include "components/update_client/task.h" #include "components/update_client/update_client.h" @@ -53,7 +53,7 @@ class TaskSendUninstallPing : public Task { // it has been canceled. void TaskComplete(Error error); - base::ThreadChecker thread_checker_; + SEQUENCE_CHECKER(sequence_checker_); scoped_refptr update_engine_; const std::string id_; const base::Version version_; diff --git a/components/update_client/task_update.cc b/components/update_client/task_update.cc index a5cf4bd42d4e..ad4c706febf2 100644 --- a/components/update_client/task_update.cc +++ b/components/update_client/task_update.cc @@ -8,7 +8,7 @@ #include "base/bind.h" #include "base/location.h" #include "base/logging.h" -#include "base/threading/thread_task_runner_handle.h" +#include "base/task/sequenced_task_runner.h" #include "components/update_client/update_client.h" #include "components/update_client/update_engine.h" @@ -34,14 +34,14 @@ TaskUpdate::TaskUpdate(scoped_refptr update_engine, } TaskUpdate::~TaskUpdate() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "TaskUpdate::~TaskUpdate"; #endif } void TaskUpdate::Run() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "TaskUpdate::Run begin"; if(is_completed_) { @@ -68,7 +68,7 @@ void TaskUpdate::Run() { } void TaskUpdate::Cancel() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "TaskUpdate::Cancel"; @@ -85,7 +85,7 @@ std::vector TaskUpdate::GetIds() const { } void TaskUpdate::TaskComplete(Error error) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "TaskUpdate::TaskComplete"; @@ -99,7 +99,7 @@ void TaskUpdate::TaskComplete(Error error) { is_completed_ = true; #endif - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(callback_), scoped_refptr(this), error)); } diff --git a/components/update_client/task_update.h b/components/update_client/task_update.h index 2697c35001f0..2d4e45e88da0 100644 --- a/components/update_client/task_update.h +++ b/components/update_client/task_update.h @@ -11,7 +11,7 @@ #include "base/callback.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" #include "components/update_client/task.h" #include "components/update_client/update_client.h" @@ -51,7 +51,7 @@ class TaskUpdate : public Task { // it has been canceled. void TaskComplete(Error error); - base::ThreadChecker thread_checker_; + SEQUENCE_CHECKER(sequence_checker_); scoped_refptr update_engine_; const bool is_foreground_; const std::vector ids_; diff --git a/components/update_client/update_checker.cc b/components/update_client/update_checker.cc index 481a53e0ab79..a3cbe45bc2c2 100644 --- a/components/update_client/update_checker.cc +++ b/components/update_client/update_checker.cc @@ -17,9 +17,9 @@ #include "base/location.h" #include "base/logging.h" #include "base/macros.h" +#include "base/sequence_checker.h" #include "base/strings/stringprintf.h" -#include "base/threading/thread_checker.h" -#include "base/threading/thread_task_runner_handle.h" +#include "base/task/sequenced_task_runner.h" #include "base/task/thread_pool.h" #include "build/build_config.h" #if defined(STARBOARD) @@ -113,7 +113,7 @@ class UpdateCheckerImpl : public UpdateChecker { int error, int retry_after_sec); - base::ThreadChecker thread_checker_; + SEQUENCE_CHECKER(sequence_checker_); const scoped_refptr config_; PersistedData* metadata_ = nullptr; @@ -134,7 +134,7 @@ UpdateCheckerImpl::UpdateCheckerImpl(scoped_refptr config, } UpdateCheckerImpl::~UpdateCheckerImpl() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "UpdateCheckerImpl::~UpdateCheckerImpl"; #endif @@ -147,7 +147,7 @@ void UpdateCheckerImpl::CheckForUpdates( const base::flat_map& additional_attributes, bool enabled_component_updates, UpdateCheckCallback update_check_callback) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "UpdateCheckerImpl::CheckForUpdates"; #endif @@ -187,7 +187,7 @@ void UpdateCheckerImpl::CheckForUpdatesHelper( const IdToComponentPtrMap& components, const base::flat_map& additional_attributes, bool enabled_component_updates) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "UpdateCheckerImpl::CheckForUpdatesHelper"; #endif @@ -334,7 +334,7 @@ void UpdateCheckerImpl::OnRequestSenderComplete( int error, const std::string& response, int retry_after_sec) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (error) { VLOG(1) << "RequestSender failed " << error; @@ -358,7 +358,7 @@ void UpdateCheckerImpl::OnRequestSenderComplete( void UpdateCheckerImpl::UpdateCheckSucceeded( const ProtocolParser::Results& results, int retry_after_sec) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); const int daynum = results.daystart_elapsed_days; if (daynum != ProtocolParser::kNoDaystart) { @@ -377,7 +377,7 @@ void UpdateCheckerImpl::UpdateCheckSucceeded( metadata_->SetCohortHint(result.extension_id, entry->second); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback_), absl::make_optional(results), @@ -387,10 +387,10 @@ void UpdateCheckerImpl::UpdateCheckSucceeded( void UpdateCheckerImpl::UpdateCheckFailed(ErrorCategory error_category, int error, int retry_after_sec) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_NE(0, error); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback_), base::nullopt, error_category, error, retry_after_sec)); diff --git a/components/update_client/update_checker_unittest.cc b/components/update_client/update_checker_unittest.cc index b8e92fc75930..04f76eebf26f 100644 --- a/components/update_client/update_checker_unittest.cc +++ b/components/update_client/update_checker_unittest.cc @@ -21,9 +21,9 @@ #include "base/stl_util.h" #include "base/strings/stringprintf.h" #include "base/task/post_task.h" +#include "base/task/sequenced_task_runner.h" #include "base/test/bind_test_util.h" #include "base/test/scoped_task_environment.h" -#include "base/threading/thread_task_runner_handle.h" #include "base/version.h" #include "build/build_config.h" #include "components/prefs/testing_pref_service.h" @@ -188,8 +188,8 @@ void UpdateCheckerTest::SetUp() { activity_data_service_.get()); #if defined(STARBOARD) - interceptor_factory_ = - std::make_unique(base::ThreadTaskRunnerHandle::Get()); + interceptor_factory_ = std::make_unique( + base::SequencedTaskRunner::GetCurrentDefault()); post_interceptor_ = interceptor_factory_->CreateInterceptor(); #else post_interceptor_ = std::make_unique( diff --git a/components/update_client/update_client.cc b/components/update_client/update_client.cc index 14baeafefd4d..8e9e90e9fa72 100644 --- a/components/update_client/update_client.cc +++ b/components/update_client/update_client.cc @@ -18,8 +18,8 @@ #include "base/macros.h" #include "base/observer_list.h" #include "base/stl_util.h" -#include "base/threading/thread_checker.h" -#include "base/threading/thread_task_runner_handle.h" +#include "base/sequence_checker.h" +#include "base/task/sequenced_task_runner.h" #include "components/crx_file/crx_verifier.h" #include "components/prefs/pref_registry_simple.h" #include "components/update_client/configurator.h" @@ -74,7 +74,7 @@ UpdateClientImpl::UpdateClientImpl( base::Unretained(this)))) {} UpdateClientImpl::~UpdateClientImpl() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(task_queue_.empty()); DCHECK(tasks_.empty()); @@ -90,7 +90,7 @@ UpdateClientImpl::~UpdateClientImpl() { void UpdateClientImpl::Install(const std::string& id, CrxDataCallback crx_data_callback, Callback callback) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (IsUpdating(id)) { std::move(callback).Run(Error::UPDATE_IN_PROGRESS); @@ -112,7 +112,7 @@ void UpdateClientImpl::Update(const std::vector& ids, CrxDataCallback crx_data_callback, bool is_foreground, Callback callback) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); auto task = base::MakeRefCounted( update_engine_.get(), is_foreground, ids, std::move(crx_data_callback), @@ -129,8 +129,8 @@ void UpdateClientImpl::Update(const std::vector& ids, } void UpdateClientImpl::RunTask(scoped_refptr task) { - DCHECK(thread_checker_.CalledOnValidThread()); - base::ThreadTaskRunnerHandle::Get()->PostTask( + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&Task::Run, base::Unretained(task.get()))); tasks_.insert(task); } @@ -138,14 +138,14 @@ void UpdateClientImpl::RunTask(scoped_refptr task) { void UpdateClientImpl::OnTaskComplete(Callback callback, scoped_refptr task, Error error) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(task); #if defined(STARBOARD) LOG(INFO) << "UpdateClientImpl::OnTaskComplete"; #endif - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(callback), error)); // Remove the task from the set of the running tasks. Only tasks handled by @@ -165,18 +165,18 @@ void UpdateClientImpl::OnTaskComplete(Callback callback, } void UpdateClientImpl::AddObserver(Observer* observer) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); observer_list_.AddObserver(observer); } void UpdateClientImpl::RemoveObserver(Observer* observer) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); observer_list_.RemoveObserver(observer); } void UpdateClientImpl::NotifyObservers(Observer::Events event, const std::string& id) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) if (is_stopped_) { LOG(WARNING) << "UpdateClientImpl::NotifyObservers: already stopped"; @@ -193,7 +193,7 @@ bool UpdateClientImpl::GetCrxUpdateState(const std::string& id, } bool UpdateClientImpl::IsUpdating(const std::string& id) const { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); for (const auto task : tasks_) { const auto ids = task->GetIds(); @@ -213,7 +213,7 @@ bool UpdateClientImpl::IsUpdating(const std::string& id) const { } void UpdateClientImpl::Stop() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); is_stopped_ = true; @@ -252,7 +252,7 @@ void UpdateClientImpl::SendUninstallPing(const std::string& id, const base::Version& version, int reason, Callback callback) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); RunTask(base::MakeRefCounted( update_engine_.get(), id, version, reason, diff --git a/components/update_client/update_client_internal.h b/components/update_client/update_client_internal.h index 2b6158c1b2f9..b7691db9d542 100644 --- a/components/update_client/update_client_internal.h +++ b/components/update_client/update_client_internal.h @@ -14,7 +14,7 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/observer_list.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" #include "components/update_client/crx_downloader.h" #include "components/update_client/update_checker.h" #include "components/update_client/update_client.h" @@ -61,7 +61,7 @@ class UpdateClientImpl : public UpdateClient { void NotifyObservers(Observer::Events event, const std::string& id); - base::ThreadChecker thread_checker_; + SEQUENCE_CHECKER(sequence_checker_); // True if Stop method has been called. bool is_stopped_ = false; diff --git a/components/update_client/update_client_unittest.cc b/components/update_client/update_client_unittest.cc index 866927b66462..4d6c78eaa75a 100644 --- a/components/update_client/update_client_unittest.cc +++ b/components/update_client/update_client_unittest.cc @@ -280,7 +280,7 @@ TEST_F(UpdateClientTest, OneCrxNoUpdate) { ProtocolParser::Results results; results.list.push_back(result); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -451,7 +451,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { EXPECT_FALSE(components.at(id)->is_foreground()); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -485,11 +485,11 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoUpdate) { result.error = 0; result.response = path; - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, base::Unretained(this))); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, base::Unretained(this), true, result, download_metrics)); @@ -652,7 +652,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateFirstServerIgnoresSecond) { EXPECT_FALSE(components.at(id)->is_foreground()); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -686,11 +686,11 @@ TEST_F(UpdateClientTest, TwoCrxUpdateFirstServerIgnoresSecond) { result.error = 0; result.response = path; - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, base::Unretained(this))); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, base::Unretained(this), true, result, download_metrics)); @@ -860,7 +860,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoCrxComponentData) { EXPECT_FALSE(components.at(id)->is_foreground()); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -898,11 +898,11 @@ TEST_F(UpdateClientTest, TwoCrxUpdateNoCrxComponentData) { NOTREACHED(); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, base::Unretained(this))); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, base::Unretained(this), true, result, download_metrics)); @@ -1189,7 +1189,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { results.list.push_back(result); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -1238,11 +1238,11 @@ TEST_F(UpdateClientTest, TwoCrxUpdateDownloadTimeout) { NOTREACHED(); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, base::Unretained(this))); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, base::Unretained(this), true, result, download_metrics)); @@ -1480,7 +1480,7 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdate) { NOTREACHED(); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -1532,11 +1532,11 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdate) { NOTREACHED(); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, base::Unretained(this))); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, base::Unretained(this), true, result, download_metrics)); @@ -1754,7 +1754,7 @@ TEST_F(UpdateClientTest, OneCrxInstallError) { ProtocolParser::Results results; results.list.push_back(result); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -1788,11 +1788,11 @@ TEST_F(UpdateClientTest, OneCrxInstallError) { result.error = 0; result.response = path; - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, base::Unretained(this))); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, base::Unretained(this), true, result, download_metrics)); @@ -2003,7 +2003,7 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { NOTREACHED(); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -2065,11 +2065,11 @@ TEST_F(UpdateClientTest, OneCrxDiffUpdateFailsFullUpdateSucceeds) { result.response = path; } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, base::Unretained(this))); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, base::Unretained(this), true, result, download_metrics)); @@ -2222,7 +2222,7 @@ TEST_F(UpdateClientTest, OneCrxNoUpdateQueuedCall) { ProtocolParser::Results results; results.list.push_back(result); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -2369,7 +2369,7 @@ TEST_F(UpdateClientTest, OneCrxInstall) { // Verify that calling Install sets ondemand. EXPECT_TRUE(components.at(id)->is_foreground()); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -2407,11 +2407,11 @@ TEST_F(UpdateClientTest, OneCrxInstall) { NOTREACHED(); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, base::Unretained(this))); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, base::Unretained(this), true, result, download_metrics)); @@ -2632,7 +2632,7 @@ TEST_F(UpdateClientTest, ConcurrentInstallSameCRX) { // Verify that calling Install sets |is_foreground| for the component. EXPECT_TRUE(components.at(id)->is_foreground()); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -2917,7 +2917,7 @@ TEST_F(UpdateClientTest, RetryAfter) { ProtocolParser::Results results; results.list.push_back(result); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, retry_after_sec)); } @@ -3160,7 +3160,7 @@ TEST_F(UpdateClientTest, TwoCrxUpdateOneUpdateDisabled) { results.list.push_back(result); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -3198,11 +3198,11 @@ TEST_F(UpdateClientTest, TwoCrxUpdateOneUpdateDisabled) { NOTREACHED(); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadProgress, base::Unretained(this))); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, base::Unretained(this), true, result, download_metrics)); @@ -3328,7 +3328,7 @@ TEST_F(UpdateClientTest, OneCrxUpdateCheckFails) { const std::string id = "jebgalgnebhfojomionfpkfelancnnkf"; EXPECT_EQ(id, ids_to_check.front()); EXPECT_EQ(1u, components.count(id)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), base::nullopt, ErrorCategory::kUpdateCheck, -1, 0)); @@ -3485,7 +3485,7 @@ TEST_F(UpdateClientTest, OneCrxErrorUnknownApp) { const auto parser = ProtocolHandlerFactoryJSON().CreateParser(); EXPECT_TRUE(parser->Parse(update_response)); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), parser->results(), ErrorCategory::kNone, 0, 0)); @@ -3671,7 +3671,7 @@ TEST_F(UpdateClientTest, ActionRun_Install) { ProtocolParser::Results results; results.list.push_back(result); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } @@ -3709,7 +3709,7 @@ TEST_F(UpdateClientTest, ActionRun_Install) { NOTREACHED(); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&MockCrxDownloader::OnDownloadComplete, base::Unretained(this), true, result, download_metrics)); @@ -3833,7 +3833,7 @@ TEST_F(UpdateClientTest, ActionRun_NoUpdate) { ProtocolParser::Results results; results.list.push_back(result); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_check_callback), results, ErrorCategory::kNone, 0, 0)); } diff --git a/components/update_client/update_engine.cc b/components/update_client/update_engine.cc index ffef9b3449a0..57e6f9c3417f 100644 --- a/components/update_client/update_engine.cc +++ b/components/update_client/update_engine.cc @@ -15,7 +15,7 @@ #include "base/optional.h" #include "base/stl_util.h" #include "base/strings/strcat.h" -#include "base/threading/thread_task_runner_handle.h" +#include "base/task/sequenced_task_runner.h" #include "components/prefs/pref_service.h" #include "components/update_client/component.h" #include "components/update_client/configurator.h" @@ -77,7 +77,7 @@ UpdateEngine::UpdateEngine( } UpdateEngine::~UpdateEngine() { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "UpdateEngine::~UpdateEngine"; #endif @@ -96,14 +96,14 @@ void UpdateEngine::Update(bool is_foreground, base::OnceClosure& cancelation_closure) { #endif - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "UpdateEngine::Update"; #endif if (ids.empty()) { - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(callback), Error::INVALID_ARGUMENT)); return; @@ -115,7 +115,7 @@ void UpdateEngine::Update(bool is_foreground, for (const auto& id : ids) { VLOG(1) << "id:" << id; } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(callback), Error::RETRY_LATER)); return; } @@ -163,7 +163,7 @@ void UpdateEngine::Update(bool is_foreground, } if (update_context->components_to_check_for_updates.empty()) { - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&UpdateEngine::HandleComponent, base::Unretained(this), update_context)); return; @@ -178,7 +178,7 @@ void UpdateEngine::Update(bool is_foreground, void UpdateEngine::ComponentCheckingForUpdatesStart( scoped_refptr update_context, const std::string& id) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(update_context); DCHECK_EQ(1u, update_context->components.count(id)); @@ -207,13 +207,13 @@ void UpdateEngine::ComponentCheckingForUpdatesStart( } #endif - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&UpdateEngine::DoUpdateCheck, base::Unretained(this), update_context)); } void UpdateEngine::DoUpdateCheck(scoped_refptr update_context) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(update_context); #if defined(STARBOARD) @@ -238,7 +238,7 @@ void UpdateEngine::UpdateCheckResultsAvailable( ErrorCategory error_category, int error, int retry_after_sec) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(update_context); #if defined(STARBOARD) @@ -314,7 +314,7 @@ void UpdateEngine::UpdateCheckResultsAvailable( void UpdateEngine::ComponentCheckingForUpdatesComplete( scoped_refptr update_context) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(update_context); #if defined(STARBOARD) @@ -327,14 +327,14 @@ void UpdateEngine::ComponentCheckingForUpdatesComplete( return; } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&UpdateEngine::UpdateCheckComplete, base::Unretained(this), update_context)); } void UpdateEngine::UpdateCheckComplete( scoped_refptr update_context) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(update_context); #if defined(STARBOARD) @@ -344,14 +344,14 @@ void UpdateEngine::UpdateCheckComplete( for (const auto& id : update_context->components_to_check_for_updates) update_context->component_queue.push(id); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&UpdateEngine::HandleComponent, base::Unretained(this), update_context)); } void UpdateEngine::HandleComponent( scoped_refptr update_context) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(update_context); #if defined(STARBOARD) @@ -365,7 +365,7 @@ void UpdateEngine::HandleComponent( ? Error::UPDATE_CHECK_ERROR : Error::NONE; - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&UpdateEngine::UpdateComplete, base::Unretained(this), update_context, error)); @@ -379,7 +379,7 @@ void UpdateEngine::HandleComponent( auto& next_update_delay = update_context->next_update_delay; if (!next_update_delay.is_zero() && component->IsUpdateAvailable()) { - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask( FROM_HERE, base::BindOnce(&UpdateEngine::HandleComponent, base::Unretained(this), update_context), @@ -405,7 +405,7 @@ void UpdateEngine::HandleComponent( void UpdateEngine::HandleComponentComplete( scoped_refptr update_context) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(update_context); #if defined(STARBOARD) @@ -441,7 +441,7 @@ void UpdateEngine::HandleComponentComplete( queue.pop(); } - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&UpdateEngine::HandleComponent, base::Unretained(this), update_context)); } @@ -452,19 +452,19 @@ void UpdateEngine::UpdateComplete(scoped_refptr update_context, LOG(INFO) << "UpdateEngine::UpdateComplete"; #endif - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(update_context); const auto num_erased = update_contexts_.erase(update_context->session_id); DCHECK_EQ(1u, num_erased); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(std::move(update_context->callback), error)); } bool UpdateEngine::GetUpdateState(const std::string& id, CrxUpdateItem* update_item) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "UpdateEngine::GetUpdateState"; #endif @@ -480,7 +480,7 @@ bool UpdateEngine::GetUpdateState(const std::string& id, } bool UpdateEngine::IsThrottled(bool is_foreground) const { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "UpdateEngine::IsThrottled"; #endif @@ -520,7 +520,7 @@ void UpdateEngine::SendUninstallPing(const std::string& id, const base::Version& version, int reason, Callback callback) { - DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); #if defined(STARBOARD) LOG(INFO) << "UpdateEngine::SendUninstallPing"; @@ -545,7 +545,7 @@ void UpdateEngine::SendUninstallPing(const std::string& id, update_context->component_queue.push(id); - base::ThreadTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&UpdateEngine::HandleComponent, base::Unretained(this), update_context)); } diff --git a/components/update_client/update_engine.h b/components/update_client/update_engine.h index 1bf1cd7709ac..a536fe63c52d 100644 --- a/components/update_client/update_engine.h +++ b/components/update_client/update_engine.h @@ -16,7 +16,7 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/optional.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" #include "base/time/time.h" #include "components/update_client/component.h" #include "components/update_client/crx_downloader.h" @@ -115,7 +115,7 @@ class UpdateEngine : public base::RefCounted { const std::vector& crx_component_ids); #endif - base::ThreadChecker thread_checker_; + SEQUENCE_CHECKER(sequence_checker_); scoped_refptr config_; UpdateChecker::Factory update_checker_factory_; CrxDownloader::Factory crx_downloader_factory_;