Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(768)

Unified Diff: components/sync/driver/glue/sync_backend_registrar_unittest.cc

Issue 2480203002: ui: Cleanup class/struct forward declarations (Closed)
Patch Set: Sync CL to position 430550 Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/sync/driver/glue/sync_backend_registrar_unittest.cc
diff --git a/components/sync/driver/glue/sync_backend_registrar_unittest.cc b/components/sync/driver/glue/sync_backend_registrar_unittest.cc
index 8ae4fe549d61bccbbe1c76c6208a70e0fc8a181f..4723b568cf1ca1c66796976ab34980b274a053a4 100644
--- a/components/sync/driver/glue/sync_backend_registrar_unittest.cc
+++ b/components/sync/driver/glue/sync_backend_registrar_unittest.cc
@@ -4,6 +4,8 @@
#include "components/sync/driver/glue/sync_backend_registrar.h"
+#include <memory>
+
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
@@ -42,17 +44,16 @@ class RegistrarSyncClient : public FakeSyncClient {
file_task_runner_(file_task_runner) {}
scoped_refptr<ModelSafeWorker> CreateModelWorkerForGroup(
- ModelSafeGroup group,
- WorkerLoopDestructionObserver* observer) override {
+ ModelSafeGroup group) override {
switch (group) {
case GROUP_UI:
- return new BrowserThreadModelWorker(ui_task_runner_, group, observer);
+ return new BrowserThreadModelWorker(ui_task_runner_, group);
case GROUP_DB:
- return new BrowserThreadModelWorker(db_task_runner_, group, observer);
+ return new BrowserThreadModelWorker(db_task_runner_, group);
case GROUP_FILE:
- return new BrowserThreadModelWorker(file_task_runner_, group, observer);
+ return new BrowserThreadModelWorker(file_task_runner_, group);
case GROUP_PASSIVE:
- return new PassiveModelWorker(observer);
+ return new PassiveModelWorker();
default:
return nullptr;
}
@@ -81,30 +82,27 @@ class SyncBackendRegistrarTest : public testing::Test {
SyncBackendRegistrarTest()
: db_thread_("DBThreadForTest"),
file_thread_("FileThreadForTest"),
- sync_thread_(nullptr) {}
+ sync_thread_("SyncThreadForTest") {}
~SyncBackendRegistrarTest() override {}
void SetUp() override {
db_thread_.StartAndWaitForTesting();
file_thread_.StartAndWaitForTesting();
+ sync_thread_.StartAndWaitForTesting();
test_user_share_.SetUp();
sync_client_ = base::MakeUnique<RegistrarSyncClient>(
ui_task_runner(), db_task_runner(), file_task_runner());
registrar_ = base::MakeUnique<SyncBackendRegistrar>(
- "test", sync_client_.get(), std::unique_ptr<base::Thread>(),
- ui_task_runner(), db_task_runner(), file_task_runner());
- sync_thread_ = registrar_->sync_thread();
+ "test", sync_client_.get(), ui_task_runner(), db_task_runner(),
+ file_task_runner());
}
void TearDown() override {
registrar_->RequestWorkerStopOnUIThread();
test_user_share_.TearDown();
- sync_thread_->task_runner()->PostTask(
- FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown,
- base::Unretained(registrar_.release())));
- sync_thread_->WaitUntilThreadStarted();
- base::RunLoop().RunUntilIdle();
+ sync_thread_.task_runner()->DeleteSoon(FROM_HERE, registrar_.release());
+ sync_thread_.FlushForTesting();
}
void ExpectRoutingInfo(SyncBackendRegistrar* registrar,
@@ -144,12 +142,11 @@ class SyncBackendRegistrarTest : public testing::Test {
base::MessageLoop message_loop_;
base::Thread db_thread_;
base::Thread file_thread_;
+ base::Thread sync_thread_;
TestUserShare test_user_share_;
std::unique_ptr<RegistrarSyncClient> sync_client_;
std::unique_ptr<SyncBackendRegistrar> registrar_;
-
- base::Thread* sync_thread_;
};
TEST_F(SyncBackendRegistrarTest, ConstructorEmpty) {
@@ -304,130 +301,6 @@ TEST_F(SyncBackendRegistrarTest, ConfigureNonBlockingDataType) {
{BOOKMARKS, GROUP_NON_BLOCKING}});
}
-class SyncBackendRegistrarShutdownTest : public testing::Test {
- public:
- void BlockDBThread() {
- EXPECT_FALSE(db_thread_lock_.Try());
-
- db_thread_blocked_.Signal();
- base::AutoLock l(db_thread_lock_);
- }
-
- protected:
- friend class TestRegistrar;
-
- SyncBackendRegistrarShutdownTest()
- : db_thread_("DBThreadForTest"),
- file_thread_("FileThreadForTest"),
- db_thread_blocked_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
- base::WaitableEvent::InitialState::NOT_SIGNALED) {
- quit_closure_ = run_loop_.QuitClosure();
- }
-
- ~SyncBackendRegistrarShutdownTest() override {}
-
- void SetUp() override {
- db_thread_.StartAndWaitForTesting();
- file_thread_.StartAndWaitForTesting();
- sync_client_ = base::MakeUnique<RegistrarSyncClient>(
- ui_task_runner(), db_task_runner(), file_task_runner());
- }
-
- void PostQuitOnUIMessageLoop() {
- ui_task_runner()->PostTask(FROM_HERE, quit_closure_);
- }
-
- const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner() {
- return message_loop_.task_runner();
- }
-
- const scoped_refptr<base::SingleThreadTaskRunner> db_task_runner() {
- return db_thread_.task_runner();
- }
-
- const scoped_refptr<base::SingleThreadTaskRunner> file_task_runner() {
- return file_thread_.task_runner();
- }
-
- base::MessageLoop message_loop_;
- base::Thread db_thread_;
- base::Thread file_thread_;
-
- std::unique_ptr<RegistrarSyncClient> sync_client_;
- base::WaitableEvent db_thread_blocked_;
-
- base::Lock db_thread_lock_;
- base::RunLoop run_loop_;
- base::Closure quit_closure_;
-};
-
-// Wrap SyncBackendRegistrar so that we can monitor its lifetime.
-class TestRegistrar : public SyncBackendRegistrar {
- public:
- explicit TestRegistrar(
- SyncClient* sync_client,
- const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
- const scoped_refptr<base::SingleThreadTaskRunner>& db_thread,
- const scoped_refptr<base::SingleThreadTaskRunner>& file_thread,
- SyncBackendRegistrarShutdownTest* test)
- : SyncBackendRegistrar("test",
- sync_client,
- std::unique_ptr<base::Thread>(),
- ui_thread,
- db_thread,
- file_thread),
- test_(test) {}
-
- ~TestRegistrar() override { test_->PostQuitOnUIMessageLoop(); }
-
- private:
- SyncBackendRegistrarShutdownTest* test_;
-};
-
-TEST_F(SyncBackendRegistrarShutdownTest, BlockingShutdown) {
- // Take ownership of |db_thread_lock_| so that the DB thread can't acquire it.
- db_thread_lock_.Acquire();
-
- // This will block the DB thread by waiting on |db_thread_lock_|.
- db_task_runner()->PostTask(
- FROM_HERE, base::Bind(&SyncBackendRegistrarShutdownTest::BlockDBThread,
- base::Unretained(this)));
-
- std::unique_ptr<TestRegistrar> registrar(
- new TestRegistrar(sync_client_.get(), ui_task_runner(), db_task_runner(),
- file_task_runner(), this));
- base::Thread* sync_thread = registrar->sync_thread();
-
- // Stop here until the DB thread gets a chance to run and block on the lock.
- // Please note that since the task above didn't finish, the task to
- // initialize the worker on the DB thread hasn't had a chance to run yet too.
- // Which means ModelSafeWorker::SetWorkingLoopToCurrent hasn't been called
- // for the DB worker.
- db_thread_blocked_.Wait();
-
- registrar->SetInitialTypes(ModelTypeSet());
-
- // Start the shutdown.
- registrar->RequestWorkerStopOnUIThread();
-
- sync_thread->task_runner()->PostTask(
- FROM_HERE, base::Bind(&SyncBackendRegistrar::Shutdown,
- base::Unretained(registrar.release())));
-
- // Make sure the thread starts running.
- sync_thread->WaitUntilThreadStarted();
-
- // The test verifies that the sync thread doesn't block because
- // of the blocked DB thread and can finish the shutdown.
- base::RunLoop().RunUntilIdle();
-
- db_thread_lock_.Release();
-
- // Run the main thread loop until all workers have been removed and the
- // registrar destroyed.
- run_loop_.Run();
-}
-
} // namespace
} // namespace syncer
« no previous file with comments | « components/sync/driver/glue/sync_backend_registrar.cc ('k') | components/sync/driver/glue/ui_model_worker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698