summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvabr <vabr@chromium.org>2016-02-19 08:45:01 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-19 16:46:28 +0000
commit6b1e9715eed76b95f079c82663d7d5c8dee9ef74 (patch)
tree1fd7c077d3c08e147e4ac6d73d419ebfce152775
parentd167c6997b7cf811efb526c17ff3c803da729867 (diff)
downloadchromium_src-6b1e9715eed76b95f079c82663d7d5c8dee9ef74.zip
chromium_src-6b1e9715eed76b95f079c82663d7d5c8dee9ef74.tar.gz
chromium_src-6b1e9715eed76b95f079c82663d7d5c8dee9ef74.tar.bz2
Avoid BrowserThread in profile_sync_service_autofill_unittest.cc
This CL gets rid of the content-provided threads in profile_sync_service_autofill_unittest, in favour of base::Thread. This is in preparation to componentising this unit test. BUG=581640 Review URL: https://codereview.chromium.org/1684643002 Cr-Commit-Position: refs/heads/master@{#376457}
-rw-r--r--chrome/browser/sync/abstract_profile_sync_service_test.cc16
-rw-r--r--chrome/browser/sync/abstract_profile_sync_service_test.h6
-rw-r--r--chrome/browser/sync/profile_sync_service_autofill_unittest.cc143
-rw-r--r--chrome/browser/sync/profile_sync_service_typed_url_unittest.cc23
-rw-r--r--chrome/browser/sync/test_profile_sync_service.h2
-rw-r--r--components/browser_sync/browser/profile_sync_test_util.cc80
-rw-r--r--components/browser_sync/browser/profile_sync_test_util.h28
7 files changed, 120 insertions, 178 deletions
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.cc b/chrome/browser/sync/abstract_profile_sync_service_test.cc
index 28d6396..c555080 100644
--- a/chrome/browser/sync/abstract_profile_sync_service_test.cc
+++ b/chrome/browser/sync/abstract_profile_sync_service_test.cc
@@ -15,14 +15,12 @@
#include "chrome/browser/sync/test_profile_sync_service.h"
#include "components/sync_driver/glue/sync_backend_host_core.h"
#include "components/sync_driver/sync_api_component_factory_mock.h"
-#include "content/public/test/test_utils.h"
#include "google_apis/gaia/gaia_constants.h"
#include "sync/internal_api/public/test/sync_manager_factory_for_profile_sync_test.h"
#include "sync/internal_api/public/test/test_internal_components_factory.h"
#include "sync/internal_api/public/test/test_user_share.h"
#include "sync/protocol/sync.pb.h"
-using content::BrowserThread;
using syncer::ModelType;
using testing::_;
using testing::Return;
@@ -163,22 +161,12 @@ ProfileSyncServiceTestHelper::MakeSingletonDeletionChangeRecordList(
}
AbstractProfileSyncServiceTest::AbstractProfileSyncServiceTest()
- // Purposefully do not use a real FILE thread, see crbug/550013.
- : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD |
- content::TestBrowserThreadBundle::REAL_IO_THREAD),
- profile_sync_service_bundle_(
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
- BrowserThread::GetBlockingPool()) {
+ : data_type_thread_("Extra thread") {
CHECK(temp_dir_.CreateUniqueTempDir());
}
AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() {
- // Pump messages posted by the sync core thread (which may end up
- // posting on the IO thread).
- base::RunLoop().RunUntilIdle();
- content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
- base::RunLoop().RunUntilIdle();
+ sync_service_->Shutdown();
}
bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) {
diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.h b/chrome/browser/sync/abstract_profile_sync_service_test.h
index b539e98..39cb4cc 100644
--- a/chrome/browser/sync/abstract_profile_sync_service_test.h
+++ b/chrome/browser/sync/abstract_profile_sync_service_test.h
@@ -14,7 +14,6 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "components/browser_sync/browser/profile_sync_test_util.h"
-#include "content/public/test/test_browser_thread_bundle.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/change_record.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -58,7 +57,10 @@ class AbstractProfileSyncServiceTest : public testing::Test {
scoped_ptr<sync_driver::SyncClient> sync_client,
const base::Closure& initialization_success_callback);
- content::TestBrowserThreadBundle thread_bundle_;
+ // Use |data_type_thread_| for code disallowed on the UI thread.
+ base::Thread data_type_thread_;
+
+ base::MessageLoop message_loop_;
browser_sync::ProfileSyncServiceBundle profile_sync_service_bundle_;
scoped_ptr<TestProfileSyncService> sync_service_;
diff --git a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
index 889a745..b32d162 100644
--- a/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_autofill_unittest.cc
@@ -24,6 +24,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
#include "base/thread_task_runner_handle.h"
+#include "base/threading/thread.h"
#include "base/time/time.h"
#include "chrome/browser/sync/abstract_profile_sync_service_test.h"
#include "chrome/browser/sync/test_profile_sync_service.h"
@@ -46,7 +47,6 @@
#include "components/syncable_prefs/pref_service_syncable.h"
#include "components/webdata/common/web_database.h"
#include "components/webdata_services/web_data_service_test_util.h"
-#include "content/public/test/test_browser_thread.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/internal_api/public/data_type_debug_info_listener.h"
#include "sync/internal_api/public/read_node.h"
@@ -74,7 +74,6 @@ using base::TimeDelta;
using base::WaitableEvent;
using browser_sync::AutofillDataTypeController;
using browser_sync::AutofillProfileDataTypeController;
-using content::BrowserThread;
using syncer::AUTOFILL;
using syncer::AUTOFILL_PROFILE;
using syncer::BaseNode;
@@ -144,12 +143,12 @@ class WebDatabaseFake : public WebDatabase {
class MockAutofillBackend : public autofill::AutofillWebDataBackend {
public:
- MockAutofillBackend(
- WebDatabase* web_database,
- const base::Closure& on_changed)
+ MockAutofillBackend(WebDatabase* web_database,
+ const base::Closure& on_changed,
+ const scoped_refptr<base::SequencedTaskRunner>& ui_thread)
: web_database_(web_database),
- on_changed_(on_changed) {
- }
+ on_changed_(on_changed),
+ ui_thread_(ui_thread) {}
~MockAutofillBackend() override {}
WebDatabase* GetDatabase() override { return web_database_; }
@@ -159,13 +158,14 @@ class MockAutofillBackend : public autofill::AutofillWebDataBackend {
autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {}
void RemoveExpiredFormElements() override {}
void NotifyOfMultipleAutofillChanges() override {
- DCHECK_CURRENTLY_ON(BrowserThread::DB);
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, on_changed_);
+ DCHECK(!ui_thread_->RunsTasksOnCurrentThread());
+ ui_thread_->PostTask(FROM_HERE, on_changed_);
}
private:
WebDatabase* web_database_;
base::Closure on_changed_;
+ const scoped_refptr<base::SequencedTaskRunner> ui_thread_;
};
class ProfileSyncServiceAutofillTest;
@@ -187,11 +187,10 @@ syncer::ModelType GetModelType<AutofillProfile>() {
class TokenWebDataServiceFake : public TokenWebData {
public:
- TokenWebDataServiceFake()
- : TokenWebData(
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)) {
- }
+ TokenWebDataServiceFake(
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& db_thread)
+ : TokenWebData(ui_thread, db_thread) {}
bool IsDatabaseLoaded() override { return true; }
@@ -215,15 +214,16 @@ class TokenWebDataServiceFake : public TokenWebData {
class WebDataServiceFake : public AutofillWebDataService {
public:
- WebDataServiceFake()
- : AutofillWebDataService(
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB)),
+ WebDataServiceFake(
+ const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
+ const scoped_refptr<base::SingleThreadTaskRunner>& db_thread)
+ : AutofillWebDataService(ui_thread, db_thread),
web_database_(NULL),
autocomplete_syncable_service_(NULL),
autofill_profile_syncable_service_(NULL),
- syncable_service_created_or_destroyed_(false, false) {
- }
+ syncable_service_created_or_destroyed_(false, false),
+ db_thread_(db_thread),
+ ui_thread_(ui_thread) {}
void SetDatabase(WebDatabase* web_database) {
web_database_ = web_database;
@@ -236,19 +236,18 @@ class WebDataServiceFake : public AutofillWebDataService {
&WebDataServiceFake::NotifyAutofillMultipleChangedOnUIThread,
AsWeakPtr());
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&WebDataServiceFake::CreateSyncableService,
- base::Unretained(this),
- on_changed_callback));
+ db_thread_->PostTask(
+ FROM_HERE, base::Bind(&WebDataServiceFake::CreateSyncableService,
+ base::Unretained(this), on_changed_callback));
syncable_service_created_or_destroyed_.Wait();
}
void ShutdownSyncableService() {
// The |autofill_profile_syncable_service_| must be destructed on the DB
// thread.
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
- base::Bind(&WebDataServiceFake::DestroySyncableService,
- base::Unretained(this)));
+ db_thread_->PostTask(FROM_HERE,
+ base::Bind(&WebDataServiceFake::DestroySyncableService,
+ base::Unretained(this)));
syncable_service_created_or_destroyed_.Wait();
}
@@ -263,10 +262,8 @@ class WebDataServiceFake : public AutofillWebDataService {
base::Bind(&AutocompleteSyncableService::AutofillEntriesChanged,
base::Unretained(autocomplete_syncable_service_),
changes);
- BrowserThread::PostTask(
- BrowserThread::DB,
- FROM_HERE,
- base::Bind(&RunAndSignal, notify_cb, &event));
+ db_thread_->PostTask(FROM_HERE,
+ base::Bind(&RunAndSignal, notify_cb, &event));
event.Wait();
}
@@ -277,10 +274,8 @@ class WebDataServiceFake : public AutofillWebDataService {
base::Bind(&AutocompleteSyncableService::AutofillProfileChanged,
base::Unretained(autofill_profile_syncable_service_),
changes);
- BrowserThread::PostTask(
- BrowserThread::DB,
- FROM_HERE,
- base::Bind(&RunAndSignal, notify_cb, &event));
+ db_thread_->PostTask(FROM_HERE,
+ base::Bind(&RunAndSignal, notify_cb, &event));
event.Wait();
}
@@ -288,10 +283,10 @@ class WebDataServiceFake : public AutofillWebDataService {
~WebDataServiceFake() override {}
void CreateSyncableService(const base::Closure& on_changed_callback) {
- ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread());
// These services are deleted in DestroySyncableService().
- backend_.reset(new MockAutofillBackend(
- GetDatabase(), on_changed_callback));
+ backend_.reset(new MockAutofillBackend(GetDatabase(), on_changed_callback,
+ ui_thread_.get()));
AutocompleteSyncableService::CreateForWebDataServiceAndBackend(
this, backend_.get());
AutofillProfileSyncableService::CreateForWebDataServiceAndBackend(
@@ -306,7 +301,7 @@ class WebDataServiceFake : public AutofillWebDataService {
}
void DestroySyncableService() {
- ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread());
autocomplete_syncable_service_ = NULL;
autofill_profile_syncable_service_ = NULL;
backend_.reset();
@@ -320,16 +315,12 @@ class WebDataServiceFake : public AutofillWebDataService {
WaitableEvent syncable_service_created_or_destroyed_;
+ const scoped_refptr<base::SingleThreadTaskRunner> db_thread_;
+ const scoped_refptr<base::SingleThreadTaskRunner> ui_thread_;
+
DISALLOW_COPY_AND_ASSIGN(WebDataServiceFake);
};
-ACTION_P(MakeAutocompleteSyncComponents, wds) {
- EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
- if (!BrowserThread::CurrentlyOn(BrowserThread::DB))
- return base::WeakPtr<syncer::SyncableService>();
- return AutocompleteSyncableService::FromWebDataService(wds)->AsWeakPtr();
-}
-
ACTION_P(ReturnNewDataTypeManagerWithDebugListener, debug_listener) {
return new sync_driver::DataTypeManagerImpl(
debug_listener,
@@ -367,9 +358,15 @@ class ProfileSyncServiceAutofillTest
RegisterAutofillPrefs(
profile_sync_service_bundle_.pref_service()->registry());
+ data_type_thread_.Start();
+ profile_sync_service_bundle_.set_db_thread(data_type_thread_.task_runner());
+
web_database_.reset(new WebDatabaseFake(&autofill_table_));
web_data_wrapper_ = make_scoped_ptr(new MockWebDataServiceWrapper(
- new WebDataServiceFake(), new TokenWebDataServiceFake()));
+ new WebDataServiceFake(base::ThreadTaskRunnerHandle::Get(),
+ data_type_thread_.task_runner()),
+ new TokenWebDataServiceFake(base::ThreadTaskRunnerHandle::Get(),
+ data_type_thread_.task_runner())));
web_data_service_ = static_cast<WebDataServiceFake*>(
web_data_wrapper_->GetAutofillWebData().get());
web_data_service_->SetDatabase(web_database_.get());
@@ -407,10 +404,15 @@ class ProfileSyncServiceAutofillTest
}
~ProfileSyncServiceAutofillTest() override {
- // Note: The tear down order is important.
- sync_service_->Shutdown();
web_data_service_->ShutdownOnUIThread();
web_data_service_->ShutdownSyncableService();
+ web_data_wrapper_->Shutdown();
+ web_data_service_ = nullptr;
+ web_data_wrapper_.reset();
+ web_database_.reset();
+ // Shut down the service explicitly before some data members from this
+ // test it needs will be deleted.
+ sync_service_->Shutdown();
}
int GetSyncCount(syncer::ModelType type) {
@@ -590,13 +592,11 @@ class ProfileSyncServiceAutofillTest
DCHECK(type == AUTOFILL || type == AUTOFILL_PROFILE);
if (type == AUTOFILL) {
return new AutofillDataTypeController(
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
+ base::ThreadTaskRunnerHandle::Get(), data_type_thread_.task_runner(),
base::Bind(&base::DoNothing), sync_client_, web_data_service_);
} else {
return new AutofillProfileDataTypeController(
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
+ base::ThreadTaskRunnerHandle::Get(), data_type_thread_.task_runner(),
base::Bind(&base::DoNothing), sync_client_, web_data_service_);
}
}
@@ -674,20 +674,20 @@ class WriteTransactionTest: public WriteTransaction {
WriteTransactionTest(const tracked_objects::Location& from_here,
WriterTag writer,
syncer::syncable::Directory* directory,
- scoped_ptr<WaitableEvent>* wait_for_syncapi)
+ WaitableEvent* wait_for_syncapi)
: WriteTransaction(from_here, writer, directory),
- wait_for_syncapi_(wait_for_syncapi) { }
+ wait_for_syncapi_(wait_for_syncapi) {}
void NotifyTransactionComplete(syncer::ModelTypeSet types) override {
// This is where we differ. Force a thread change here, giving another
// thread a chance to create a WriteTransaction
- (*wait_for_syncapi_)->Wait();
+ wait_for_syncapi_->Wait();
WriteTransaction::NotifyTransactionComplete(types);
}
private:
- scoped_ptr<WaitableEvent>* wait_for_syncapi_;
+ WaitableEvent* const wait_for_syncapi_;
};
// Our fake server updater. Needs the RefCountedThreadSafe inheritance so we can
@@ -695,17 +695,19 @@ class WriteTransactionTest: public WriteTransaction {
class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> {
public:
FakeServerUpdater(TestProfileSyncService* service,
- scoped_ptr<WaitableEvent>* wait_for_start,
- scoped_ptr<WaitableEvent>* wait_for_syncapi)
+ WaitableEvent* wait_for_start,
+ WaitableEvent* wait_for_syncapi,
+ scoped_refptr<base::SequencedTaskRunner> db_thread)
: entry_(ProfileSyncServiceAutofillTest::MakeAutofillEntry("0", "0", 0)),
service_(service),
wait_for_start_(wait_for_start),
wait_for_syncapi_(wait_for_syncapi),
- is_finished_(false, false) { }
+ is_finished_(false, false),
+ db_thread_(db_thread) {}
void Update() {
// This gets called in a modelsafeworker thread.
- ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread());
syncer::UserShare* user_share = service_->GetUserShare();
syncer::syncable::Directory* directory = user_share->directory.get();
@@ -728,7 +730,7 @@ class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> {
{
// Tell main thread we've started
- (*wait_for_start_)->Signal();
+ wait_for_start_->Signal();
// Create write transaction.
WriteTransactionTest trans(FROM_HERE, UNITTEST, directory,
@@ -754,10 +756,9 @@ class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> {
void CreateNewEntry(const AutofillEntry& entry) {
entry_ = entry;
- ASSERT_FALSE(BrowserThread::CurrentlyOn(BrowserThread::DB));
- if (!BrowserThread::PostTask(
- BrowserThread::DB, FROM_HERE,
- base::Bind(&FakeServerUpdater::Update, this))) {
+ ASSERT_FALSE(db_thread_->RunsTasksOnCurrentThread());
+ if (!db_thread_->PostTask(FROM_HERE,
+ base::Bind(&FakeServerUpdater::Update, this))) {
NOTREACHED() << "Failed to post task to the db thread.";
return;
}
@@ -773,10 +774,13 @@ class FakeServerUpdater : public base::RefCountedThreadSafe<FakeServerUpdater> {
AutofillEntry entry_;
TestProfileSyncService* service_;
- scoped_ptr<WaitableEvent>* wait_for_start_;
- scoped_ptr<WaitableEvent>* wait_for_syncapi_;
+ WaitableEvent* const wait_for_start_;
+ WaitableEvent* const wait_for_syncapi_;
WaitableEvent is_finished_;
syncer::syncable::Id parent_id_;
+ scoped_refptr<base::SequencedTaskRunner> db_thread_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeServerUpdater);
};
// TODO(skrul): Test abort startup.
@@ -1216,7 +1220,8 @@ TEST_F(ProfileSyncServiceAutofillTest, ServerChangeRace) {
scoped_ptr<WaitableEvent> wait_for_start(new WaitableEvent(true, false));
scoped_ptr<WaitableEvent> wait_for_syncapi(new WaitableEvent(true, false));
scoped_refptr<FakeServerUpdater> updater(new FakeServerUpdater(
- sync_service_.get(), &wait_for_start, &wait_for_syncapi));
+ sync_service_.get(), wait_for_start.get(), wait_for_syncapi.get(),
+ data_type_thread_.task_runner()));
// This server side update will stall waiting for CommitWaiter.
updater->CreateNewEntry(MakeAutofillEntry("server", "entry", 1));
diff --git a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
index 9838574..9300403 100644
--- a/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_typed_url_unittest.cc
@@ -165,21 +165,21 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
}
protected:
- ProfileSyncServiceTypedUrlTest() : history_thread_("history") {
+ ProfileSyncServiceTypedUrlTest() {
profile_sync_service_bundle_.pref_service()
->registry()
->RegisterBooleanPref(kDummySavingBrowserHistoryDisabled, false);
- history_thread_.Start();
+ data_type_thread_.Start();
base::RunLoop run_loop;
- history_thread_.task_runner()->PostTaskAndReply(
+ data_type_thread_.task_runner()->PostTaskAndReply(
FROM_HERE,
base::Bind(&ProfileSyncServiceTypedUrlTest::CreateHistoryService,
base::Unretained(this)),
run_loop.QuitClosure());
run_loop.Run();
history_service_ = make_scoped_ptr(new HistoryServiceMock);
- history_service_->set_task_runner(history_thread_.task_runner());
+ history_service_->set_task_runner(data_type_thread_.task_runner());
history_service_->set_backend(history_backend_);
browser_sync::ProfileSyncServiceBundle::SyncClientBuilder builder(
@@ -201,7 +201,10 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
new TestTypedUrlSyncableService(history_backend_.get()));
}
- void DeleteSyncableService() { syncable_service_.reset(); }
+ void DeleteSyncableService() {
+ syncable_service_.reset();
+ history_backend_ = nullptr;
+ }
~ProfileSyncServiceTypedUrlTest() override {
history_service_->Shutdown();
@@ -220,11 +223,12 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
run_loop.Run();
}
- sync_service_->Shutdown();
+ // Spin the loop again for deletion tasks posted from the Sync thread.
+ base::RunLoop().RunUntilIdle();
{
base::RunLoop run_loop;
- history_thread_.task_runner()->PostTaskAndReply(
+ data_type_thread_.task_runner()->PostTaskAndReply(
FROM_HERE,
base::Bind(&ProfileSyncServiceTypedUrlTest::DeleteSyncableService,
base::Unretained(this)),
@@ -297,7 +301,7 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
}
void SendNotification(const base::Closure& task) {
- history_thread_.task_runner()->PostTaskAndReply(
+ data_type_thread_.task_runner()->PostTaskAndReply(
FROM_HERE, task,
base::Bind(&base::MessageLoop::QuitNow,
base::Unretained(base::MessageLoop::current())));
@@ -374,9 +378,6 @@ class ProfileSyncServiceTypedUrlTest : public AbstractProfileSyncServiceTest {
return syncable_service_->AsWeakPtr();
}
- // The separate thread is needed, because TypedUrlDataTypeController
- // requires to run on another thread than the UI thread.
- base::Thread history_thread_;
scoped_refptr<HistoryBackendMock> history_backend_;
scoped_ptr<HistoryServiceMock> history_service_;
sync_driver::DataTypeErrorHandlerMock error_handler_;
diff --git a/chrome/browser/sync/test_profile_sync_service.h b/chrome/browser/sync/test_profile_sync_service.h
index 9aefbb1..097b4b9 100644
--- a/chrome/browser/sync/test_profile_sync_service.h
+++ b/chrome/browser/sync/test_profile_sync_service.h
@@ -18,7 +18,7 @@ class SyncPrefs;
class TestProfileSyncService : public ProfileSyncService {
public:
- explicit TestProfileSyncService(ProfileSyncService::InitParams init_params);
+ explicit TestProfileSyncService(InitParams init_params);
~TestProfileSyncService() override;
diff --git a/components/browser_sync/browser/profile_sync_test_util.cc b/components/browser_sync/browser/profile_sync_test_util.cc
index fd6d916..cb6c543 100644
--- a/components/browser_sync/browser/profile_sync_test_util.cc
+++ b/components/browser_sync/browser/profile_sync_test_util.cc
@@ -217,43 +217,35 @@ ProfileSyncServiceBundle::SyncClientBuilder::Build() {
personal_data_manager_, get_syncable_service_callback_,
get_sync_service_callback_,
activate_model_creation_ ? bundle_->db_thread() : nullptr,
- activate_model_creation_ ? bundle_->file_thread() : nullptr,
+ activate_model_creation_ ? base::ThreadTaskRunnerHandle::Get() : nullptr,
history_service_));
}
-struct ProfileSyncServiceBundle::ThreadProvider {
- public:
- ThreadProvider() : worker_pool_owner_(2, "sync test worker pool") {
- DCHECK(base::MessageLoop::current())
- << "The test including the bundle also needs to include a MessageLoop";
- }
- ~ThreadProvider() = default;
-
- base::SequencedWorkerPoolOwner worker_pool_owner_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ThreadProvider);
-};
-
ProfileSyncServiceBundle::ProfileSyncServiceBundle()
- : ProfileSyncServiceBundle(make_scoped_ptr(new ThreadProvider),
- nullptr,
- nullptr,
- nullptr) {}
-
-ProfileSyncServiceBundle::ProfileSyncServiceBundle(
- const scoped_refptr<base::SingleThreadTaskRunner>& db_thread,
- const scoped_refptr<base::SingleThreadTaskRunner>& file_thread,
- base::SequencedWorkerPool* worker_pool)
- : ProfileSyncServiceBundle(nullptr, db_thread, file_thread, worker_pool) {}
+ : db_thread_(base::ThreadTaskRunnerHandle::Get()),
+ worker_pool_owner_(2, "sync test worker pool"),
+ signin_client_(&pref_service_),
+#if defined(OS_CHROMEOS)
+ signin_manager_(&signin_client_, &account_tracker_),
+#else
+ signin_manager_(&signin_client_,
+ &auth_service_,
+ &account_tracker_,
+ nullptr),
+#endif
+ url_request_context_(new net::TestURLRequestContextGetter(
+ base::ThreadTaskRunnerHandle::Get())) {
+ browser_sync::RegisterPrefsForProfileSyncService(pref_service_.registry());
+ auth_service_.set_auto_post_fetch_response_on_message_loop(true);
+ account_tracker_.Initialize(&signin_client_);
+ signin_manager_.Initialize(&pref_service_);
+}
ProfileSyncServiceBundle::~ProfileSyncServiceBundle() {}
ProfileSyncService::InitParams ProfileSyncServiceBundle::CreateBasicInitParams(
browser_sync::ProfileSyncServiceStartBehavior start_behavior,
scoped_ptr<sync_driver::SyncClient> sync_client) {
- DCHECK(worker_pool_);
-
ProfileSyncService::InitParams init_params;
init_params.start_behavior = start_behavior;
@@ -268,40 +260,10 @@ ProfileSyncService::InitParams ProfileSyncServiceBundle::CreateBasicInitParams(
init_params.debug_identifier = "dummyDebugName";
init_params.channel = version_info::Channel::UNKNOWN;
init_params.db_thread = db_thread_;
- init_params.file_thread = file_thread_;
- init_params.blocking_pool = worker_pool_;
+ init_params.file_thread = base::ThreadTaskRunnerHandle::Get();
+ init_params.blocking_pool = worker_pool_owner_.pool().get();
return init_params;
}
-ProfileSyncServiceBundle::ProfileSyncServiceBundle(
- scoped_ptr<ThreadProvider> thread_provider,
- scoped_refptr<base::SingleThreadTaskRunner> db_thread,
- scoped_refptr<base::SingleThreadTaskRunner> file_thread,
- base::SequencedWorkerPool* worker_pool)
- : thread_provider_(std::move(thread_provider)),
- db_thread_(thread_provider_ ? base::ThreadTaskRunnerHandle::Get()
- : db_thread),
- file_thread_(thread_provider_ ? base::ThreadTaskRunnerHandle::Get()
- : file_thread),
- worker_pool_(thread_provider_
- ? thread_provider_->worker_pool_owner_.pool().get()
- : worker_pool),
- signin_client_(&pref_service_),
-#if defined(OS_CHROMEOS)
- signin_manager_(&signin_client_, &account_tracker_),
-#else
- signin_manager_(&signin_client_,
- &auth_service_,
- &account_tracker_,
- nullptr),
-#endif
- url_request_context_(new net::TestURLRequestContextGetter(
- base::ThreadTaskRunnerHandle::Get())) {
- browser_sync::RegisterPrefsForProfileSyncService(pref_service_.registry());
- auth_service_.set_auto_post_fetch_response_on_message_loop(true);
- account_tracker_.Initialize(&signin_client_);
- signin_manager_.Initialize(&pref_service_);
-}
-
} // namespace browser_sync
diff --git a/components/browser_sync/browser/profile_sync_test_util.h b/components/browser_sync/browser/profile_sync_test_util.h
index 485e7dd..4a55caf 100644
--- a/components/browser_sync/browser/profile_sync_test_util.h
+++ b/components/browser_sync/browser/profile_sync_test_util.h
@@ -63,15 +63,8 @@ class ProfileSyncServiceBundle {
typedef FakeSigninManager FakeSigninManagerType;
#endif
- // Use this if you don't care about threads.
ProfileSyncServiceBundle();
- // Use this to inject threads directly.
- ProfileSyncServiceBundle(
- const scoped_refptr<base::SingleThreadTaskRunner>& db_thread,
- const scoped_refptr<base::SingleThreadTaskRunner>& file_thread,
- base::SequencedWorkerPool* worker_pool);
-
~ProfileSyncServiceBundle();
// Builders
@@ -165,23 +158,14 @@ class ProfileSyncServiceBundle {
base::SingleThreadTaskRunner* db_thread() { return db_thread_.get(); }
- base::SingleThreadTaskRunner* file_thread() { return file_thread_.get(); }
+ void set_db_thread(
+ const scoped_refptr<base::SingleThreadTaskRunner>& db_thread) {
+ db_thread_ = db_thread;
+ }
private:
- struct ThreadProvider; // Helper to create threads and worker pool.
-
- // Either |thread_provider| must be null and or the other arguments non-null,
- // or vice versa.
- ProfileSyncServiceBundle(
- scoped_ptr<ThreadProvider> thread_provider,
- scoped_refptr<base::SingleThreadTaskRunner> db_thread,
- scoped_refptr<base::SingleThreadTaskRunner> file_thread,
- base::SequencedWorkerPool* worker_pool);
-
- scoped_ptr<ThreadProvider> thread_provider_;
- const scoped_refptr<base::SingleThreadTaskRunner> db_thread_;
- const scoped_refptr<base::SingleThreadTaskRunner> file_thread_;
- base::SequencedWorkerPool* const worker_pool_;
+ scoped_refptr<base::SingleThreadTaskRunner> db_thread_;
+ base::SequencedWorkerPoolOwner worker_pool_owner_;
syncable_prefs::TestingPrefServiceSyncable pref_service_;
TestSigninClient signin_client_;
AccountTrackerService account_tracker_;