Commit ce1a5449 authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

Move ProfileSyncService::background_task_runner_ to SyncEngineImpl

ProfileSyncService mostly creates the task runner and passes it to the
engine, so this CL moves the creation to the engine. The one use of
the runner by ProfileSyncService is replaced with posting a task to the
thread pool.

Bug: 1123881
Change-Id: Ifef2806b527424b30e2a0d6ef07cfca026ee07b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2461325Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Commit-Queue: Victor Vianna <victorvianna@google.com>
Cr-Commit-Position: refs/heads/master@{#816106}
parent ef2223e9
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/location.h" #include "base/location.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/task_runner_util.h" #include "base/task_runner_util.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/invalidation/impl/invalidation_switches.h" #include "components/invalidation/impl/invalidation_switches.h"
...@@ -42,7 +44,10 @@ SyncEngineImpl::SyncEngineImpl( ...@@ -42,7 +44,10 @@ SyncEngineImpl::SyncEngineImpl(
SyncInvalidationsService* sync_invalidations_service, SyncInvalidationsService* sync_invalidations_service,
const base::WeakPtr<SyncPrefs>& sync_prefs, const base::WeakPtr<SyncPrefs>& sync_prefs,
const base::FilePath& sync_data_folder) const base::FilePath& sync_data_folder)
: name_(name), : sync_task_runner_(base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN})),
name_(name),
sync_prefs_(sync_prefs), sync_prefs_(sync_prefs),
invalidator_(invalidator), invalidator_(invalidator),
sync_invalidations_service_(sync_invalidations_service), sync_invalidations_service_(sync_invalidations_service),
...@@ -61,11 +66,9 @@ SyncEngineImpl::~SyncEngineImpl() { ...@@ -61,11 +66,9 @@ SyncEngineImpl::~SyncEngineImpl() {
} }
void SyncEngineImpl::Initialize(InitParams params) { void SyncEngineImpl::Initialize(InitParams params) {
DCHECK(params.sync_task_runner);
DCHECK(params.host); DCHECK(params.host);
DCHECK(params.registrar); DCHECK(params.registrar);
sync_task_runner_ = params.sync_task_runner;
host_ = params.host; host_ = params.host;
registrar_ = params.registrar.get(); registrar_ = params.registrar.get();
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h"
#include "components/invalidation/public/invalidation_handler.h" #include "components/invalidation/public/invalidation_handler.h"
#include "components/sync/base/extensions_activity.h" #include "components/sync/base/extensions_activity.h"
#include "components/sync/base/model_type.h" #include "components/sync/base/model_type.h"
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/invalidation/impl/invalidation_logger.h" #include "components/invalidation/impl/invalidation_logger.h"
...@@ -183,8 +182,7 @@ std::unique_ptr<HttpPostProviderFactory> CreateHttpBridgeFactory() { ...@@ -183,8 +182,7 @@ std::unique_ptr<HttpPostProviderFactory> CreateHttpBridgeFactory() {
class SyncEngineImplTest : public testing::Test { class SyncEngineImplTest : public testing::Test {
protected: protected:
SyncEngineImplTest() SyncEngineImplTest()
: sync_thread_("SyncThreadForTest"), : host_(base::BindOnce(&SyncEngineImplTest::SetEngineTypes,
host_(base::BindOnce(&SyncEngineImplTest::SetEngineTypes,
base::Unretained(this))), base::Unretained(this))),
fake_manager_(nullptr) {} fake_manager_(nullptr) {}
...@@ -196,7 +194,6 @@ class SyncEngineImplTest : public testing::Test { ...@@ -196,7 +194,6 @@ class SyncEngineImplTest : public testing::Test {
SyncPrefs::RegisterProfilePrefs(pref_service_.registry()); SyncPrefs::RegisterProfilePrefs(pref_service_.registry());
sync_prefs_ = std::make_unique<SyncPrefs>(&pref_service_); sync_prefs_ = std::make_unique<SyncPrefs>(&pref_service_);
sync_thread_.StartAndWaitForTesting();
ON_CALL(invalidator_, UpdateInterestedTopics(_, _)) ON_CALL(invalidator_, UpdateInterestedTopics(_, _))
.WillByDefault(testing::Return(true)); .WillByDefault(testing::Return(true));
backend_ = std::make_unique<SyncEngineImpl>( backend_ = std::make_unique<SyncEngineImpl>(
...@@ -235,7 +232,6 @@ class SyncEngineImplTest : public testing::Test { ...@@ -235,7 +232,6 @@ class SyncEngineImplTest : public testing::Test {
host_.SetExpectSuccess(expect_success); host_.SetExpectSuccess(expect_success);
SyncEngine::InitParams params; SyncEngine::InitParams params;
params.sync_task_runner = sync_thread_.task_runner();
params.host = &host_; params.host = &host_;
params.registrar = std::make_unique<SyncBackendRegistrar>( params.registrar = std::make_unique<SyncBackendRegistrar>(
std::string(), base::BindRepeating(&CreateModelWorkerForGroup)); std::string(), base::BindRepeating(&CreateModelWorkerForGroup));
...@@ -311,7 +307,6 @@ class SyncEngineImplTest : public testing::Test { ...@@ -311,7 +307,6 @@ class SyncEngineImplTest : public testing::Test {
base::test::TaskEnvironment task_environment_; base::test::TaskEnvironment task_environment_;
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
sync_preferences::TestingPrefServiceSyncable pref_service_; sync_preferences::TestingPrefServiceSyncable pref_service_;
base::Thread sync_thread_;
TestSyncEngineHost host_; TestSyncEngineHost host_;
std::unique_ptr<SyncPrefs> sync_prefs_; std::unique_ptr<SyncPrefs> sync_prefs_;
std::unique_ptr<SyncEngineImpl> backend_; std::unique_ptr<SyncEngineImpl> backend_;
......
...@@ -237,9 +237,6 @@ ProfileSyncService::ProfileSyncService(InitParams init_params) ...@@ -237,9 +237,6 @@ ProfileSyncService::ProfileSyncService(InitParams init_params)
base::Unretained(this)), base::Unretained(this)),
&sync_prefs_, &sync_prefs_,
sync_client_->GetTrustedVaultClient()), sync_client_->GetTrustedVaultClient()),
backend_task_runner_(base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN})),
network_time_update_callback_( network_time_update_callback_(
std::move(init_params.network_time_update_callback)), std::move(init_params.network_time_update_callback)),
url_loader_factory_(std::move(init_params.url_loader_factory)), url_loader_factory_(std::move(init_params.url_loader_factory)),
...@@ -580,7 +577,6 @@ void ProfileSyncService::StartUpSlowEngineComponents() { ...@@ -580,7 +577,6 @@ void ProfileSyncService::StartUpSlowEngineComponents() {
} }
SyncEngine::InitParams params; SyncEngine::InitParams params;
params.sync_task_runner = backend_task_runner_;
params.host = this; params.host = this;
params.registrar = std::make_unique<SyncBackendRegistrar>( params.registrar = std::make_unique<SyncBackendRegistrar>(
debug_identifier_, debug_identifier_,
...@@ -663,8 +659,10 @@ void ProfileSyncService::ShutdownImpl(ShutdownReason reason) { ...@@ -663,8 +659,10 @@ void ProfileSyncService::ShutdownImpl(ShutdownReason reason) {
// certain codepaths such as the user being signed out). To avoid that, // certain codepaths such as the user being signed out). To avoid that,
// SyncPrefs is used to determine whether it's worth it. // SyncPrefs is used to determine whether it's worth it.
if (!sync_prefs_.GetCacheGuid().empty()) { if (!sync_prefs_.GetCacheGuid().empty()) {
backend_task_runner_->PostTask( base::ThreadPool::PostTask(
FROM_HERE, FROM_HERE,
{base::TaskPriority::USER_VISIBLE, base::MayBlock(),
base::TaskShutdownBehavior::BLOCK_SHUTDOWN},
base::BindOnce(&DeleteLegacyDirectoryFilesAndNigoriStorage, base::BindOnce(&DeleteLegacyDirectoryFilesAndNigoriStorage,
sync_client_->GetSyncDataPath())); sync_client_->GetSyncDataPath()));
} }
......
...@@ -411,9 +411,6 @@ class ProfileSyncService : public SyncService, ...@@ -411,9 +411,6 @@ class ProfileSyncService : public SyncService,
// A utility object containing logic and state relating to encryption. // A utility object containing logic and state relating to encryption.
SyncServiceCrypto crypto_; SyncServiceCrypto crypto_;
// TODO(crbug.com/923287): Move out of this class. Possibly to SyncEngineImpl.
scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
// Our asynchronous engine to communicate with sync components living on // Our asynchronous engine to communicate with sync components living on
// other threads. // other threads.
std::unique_ptr<SyncEngine> engine_; std::unique_ptr<SyncEngine> engine_;
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/sequenced_task_runner.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/sync/base/extensions_activity.h" #include "components/sync/base/extensions_activity.h"
#include "components/sync/base/model_type.h" #include "components/sync/base/model_type.h"
...@@ -51,7 +50,6 @@ class SyncEngine : public ModelTypeConfigurer { ...@@ -51,7 +50,6 @@ class SyncEngine : public ModelTypeConfigurer {
InitParams(InitParams&& other); InitParams(InitParams&& other);
~InitParams(); ~InitParams();
scoped_refptr<base::SequencedTaskRunner> sync_task_runner;
SyncEngineHost* host = nullptr; SyncEngineHost* host = nullptr;
std::unique_ptr<SyncBackendRegistrar> registrar; std::unique_ptr<SyncBackendRegistrar> registrar;
std::unique_ptr<SyncEncryptionHandler::Observer> encryption_observer_proxy; std::unique_ptr<SyncEncryptionHandler::Observer> encryption_observer_proxy;
......
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