diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-28 04:42:28 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-28 04:42:28 +0000 |
commit | 6b1d04b133564ed10b434bbfc42736e57144a1e5 (patch) | |
tree | f5241fa6385bcf3c85a56e11c690fb7ad8b19586 /chrome/browser/sync | |
parent | 1116122dc4674b78e2cb2e5aa341f84b4df01761 (diff) | |
download | chromium_src-6b1d04b133564ed10b434bbfc42736e57144a1e5.zip chromium_src-6b1d04b133564ed10b434bbfc42736e57144a1e5.tar.gz chromium_src-6b1d04b133564ed10b434bbfc42736e57144a1e5.tar.bz2 |
Revert 37367 - Implementation of the database safe worker model.
BUG=none
TEST=unit test
Review URL: http://codereview.chromium.org/546138
TBR=albertb@google.com, victorw@chromium.org, rolandsteiner@chromium.org
Review URL: http://codereview.chromium.org/557032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37380 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r-- | chrome/browser/sync/engine/model_safe_worker.h | 5 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread_unittest.cc | 4 | ||||
-rwxr-xr-x | chrome/browser/sync/engine/syncer_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sync/glue/database_model_worker.cc | 36 | ||||
-rw-r--r-- | chrome/browser/sync/glue/database_model_worker.h | 33 | ||||
-rw-r--r-- | chrome/browser/sync/glue/database_model_worker_unittest.cc | 90 | ||||
-rw-r--r-- | chrome/browser/sync/glue/sync_backend_host.cc | 3 | ||||
-rw-r--r-- | chrome/browser/sync/glue/sync_backend_host.h | 2 | ||||
-rw-r--r-- | chrome/browser/sync/glue/ui_model_worker_unittest.cc | 9 |
9 files changed, 12 insertions, 174 deletions
diff --git a/chrome/browser/sync/engine/model_safe_worker.h b/chrome/browser/sync/engine/model_safe_worker.h index 84a6a2f..c68218c 100644 --- a/chrome/browser/sync/engine/model_safe_worker.h +++ b/chrome/browser/sync/engine/model_safe_worker.h @@ -8,7 +8,6 @@ #include <map> #include <vector> -#include "base/ref_counted.h" #include "chrome/browser/sync/syncable/model_type.h" #include "chrome/browser/sync/util/closure.h" #include "chrome/browser/sync/util/sync_types.h" @@ -31,7 +30,7 @@ enum ModelSafeGroup { // is guaranteed to be "model-safe", where "safe" refers to not allowing us to // cause an embedding application model to fall out of sync with the // syncable::Directory due to a race. -class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> { +class ModelSafeWorker { public: ModelSafeWorker() { } virtual ~ModelSafeWorker() { } @@ -48,8 +47,6 @@ class ModelSafeWorker : public base::RefCountedThreadSafe<ModelSafeWorker> { } private: - friend class base::RefCountedThreadSafe<ModelSafeWorker>; - DISALLOW_COPY_AND_ASSIGN(ModelSafeWorker); }; diff --git a/chrome/browser/sync/engine/syncer_thread_unittest.cc b/chrome/browser/sync/engine/syncer_thread_unittest.cc index f676cd6..314237a 100644 --- a/chrome/browser/sync/engine/syncer_thread_unittest.cc +++ b/chrome/browser/sync/engine/syncer_thread_unittest.cc @@ -35,7 +35,7 @@ class SyncerThreadWithSyncerTest : public testing::Test, connection_.reset(new MockConnectionManager(metadb_.manager(), metadb_.name())); allstatus_.reset(new AllStatus()); - worker_ = new ModelSafeWorker(); + worker_.reset(new ModelSafeWorker()); SyncSessionContext* context = new SyncSessionContext(connection_.get(), metadb_.manager(), this); syncer_thread_ = new SyncerThread(context, allstatus_.get()); @@ -85,7 +85,7 @@ class SyncerThreadWithSyncerTest : public testing::Test, scoped_ptr<MockConnectionManager> connection_; scoped_ptr<AllStatus> allstatus_; scoped_refptr<SyncerThread> syncer_thread_; - scoped_refptr<ModelSafeWorker> worker_; + scoped_ptr<ModelSafeWorker> worker_; scoped_ptr<EventListenerHookup> syncer_event_hookup_; base::WaitableEvent sync_cycle_ended_event_; DISALLOW_COPY_AND_ASSIGN(SyncerThreadWithSyncerTest); diff --git a/chrome/browser/sync/engine/syncer_unittest.cc b/chrome/browser/sync/engine/syncer_unittest.cc index 2177e5b..7d2aa38 100755 --- a/chrome/browser/sync/engine/syncer_unittest.cc +++ b/chrome/browser/sync/engine/syncer_unittest.cc @@ -166,7 +166,7 @@ class SyncerTest : public testing::Test, mock_server_.reset( new MockConnectionManager(syncdb_.manager(), syncdb_.name())); - worker_ = new ModelSafeWorker(); + worker_.reset(new ModelSafeWorker()); context_.reset(new SyncSessionContext(mock_server_.get(), syncdb_.manager(), this)); context_->set_account_name(syncdb_.name()); @@ -399,7 +399,7 @@ class SyncerTest : public testing::Test, std::set<SyncerEvent> syncer_events_; base::TimeDelta last_short_poll_interval_received_; base::TimeDelta last_long_poll_interval_received_; - scoped_refptr<ModelSafeWorker> worker_; + scoped_ptr<ModelSafeWorker> worker_; DISALLOW_COPY_AND_ASSIGN(SyncerTest); }; diff --git a/chrome/browser/sync/glue/database_model_worker.cc b/chrome/browser/sync/glue/database_model_worker.cc deleted file mode 100644 index 02516c7..0000000 --- a/chrome/browser/sync/glue/database_model_worker.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/sync/glue/database_model_worker.h" - -#include "chrome/browser/chrome_thread.h" - -using base::WaitableEvent; - -namespace browser_sync { - -void DatabaseModelWorker::DoWorkAndWaitUntilDone(Closure* work) { - if (ChromeThread::CurrentlyOn(ChromeThread::DB)) { - DLOG(WARNING) << "DoWorkAndWaitUntilDone called from the DB thread."; - work->Run(); - return; - } - WaitableEvent done(false, false); - if (!ChromeThread::PostTask(ChromeThread::DB, FROM_HERE, - NewRunnableMethod(this, &DatabaseModelWorker::CallDoWorkAndSignalTask, - work, &done))) { - NOTREACHED() << "Failed to post task to the db thread."; - return; - } - done.Wait(); -} - -void DatabaseModelWorker::CallDoWorkAndSignalTask(Closure* work, - WaitableEvent* done) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::DB)); - work->Run(); - done->Signal(); -} - -} // namespace browser_sync diff --git a/chrome/browser/sync/glue/database_model_worker.h b/chrome/browser/sync/glue/database_model_worker.h deleted file mode 100644 index 64f53ed..0000000 --- a/chrome/browser/sync/glue/database_model_worker.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_SYNC_GLUE_DATABASE_MODEL_WORKER_H_ -#define CHROME_BROWSER_SYNC_GLUE_DATABASE_MODEL_WORKER_H_ - -#include "base/ref_counted.h" -#include "base/waitable_event.h" -#include "chrome/browser/sync/engine/model_safe_worker.h" -#include "chrome/browser/sync/util/closure.h" - -namespace browser_sync { - -// A ModelSafeWorker for database models (eg. autofill) that accepts requests -// from the syncapi that need to be fulfilled on the database thread. -class DatabaseModelWorker : public browser_sync::ModelSafeWorker { - public: - explicit DatabaseModelWorker() {} - - // ModelSafeWorker implementation. Called on syncapi SyncerThread. - void DoWorkAndWaitUntilDone(Closure* work); - virtual ModelSafeGroup GetModelSafeGroup() { return GROUP_DB; } - - private: - void CallDoWorkAndSignalTask(Closure* work, base::WaitableEvent* done); - - DISALLOW_COPY_AND_ASSIGN(DatabaseModelWorker); -}; - -} // namespace browser_sync - -#endif // CHROME_BROWSER_SYNC_GLUE_DATABASE_MODEL_WORKER_H_ diff --git a/chrome/browser/sync/glue/database_model_worker_unittest.cc b/chrome/browser/sync/glue/database_model_worker_unittest.cc deleted file mode 100644 index 81c8e67..0000000 --- a/chrome/browser/sync/glue/database_model_worker_unittest.cc +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/scoped_ptr.h" -#include "base/thread.h" -#include "base/timer.h" -#include "chrome/browser/chrome_thread.h" -#include "chrome/browser/sync/glue/database_model_worker.h" -#include "testing/gtest/include/gtest/gtest.h" - -using base::OneShotTimer; -using base::Thread; -using base::TimeDelta; -using browser_sync::DatabaseModelWorker; - -namespace { - -class DatabaseModelWorkerTest : public testing::Test { - public: - DatabaseModelWorkerTest() : - did_do_work_(false), - db_thread_(ChromeThread::DB), - io_thread_(ChromeThread::IO, &io_loop_), - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {}; - - bool did_do_work() { return did_do_work_; } - DatabaseModelWorker* worker() { return worker_.get(); } - OneShotTimer<DatabaseModelWorkerTest>* timer() { return &timer_; } - ScopedRunnableMethodFactory<DatabaseModelWorkerTest>* factory() { - return &method_factory_; - } - - // Schedule DoWork to be executed on the DB thread and have the test fail if - // DoWork hasn't executed within 10 seconds. - void ScheduleWork() { - timer()->Start(TimeDelta::FromSeconds(10), - this, &DatabaseModelWorkerTest::Timeout); - worker()->DoWorkAndWaitUntilDone( - NewCallback(this, &DatabaseModelWorkerTest::DoWork)); - } - - // This is the work that will be scheduled to be done on the DB thread. - void DoWork() { - EXPECT_TRUE(ChromeThread::CurrentlyOn(ChromeThread::DB)); - timer_.Stop(); // Stop the failure timer so the test succeeds. - ChromeThread::PostTask( - ChromeThread::IO, FROM_HERE, new MessageLoop::QuitTask()); - did_do_work_ = true; - } - - // This will be called by the OneShotTimer and make the test fail unless - // DoWork is called first. - void Timeout() { - ADD_FAILURE() << "Timed out waiting for work to be done on the DB thread."; - ChromeThread::PostTask( - ChromeThread::IO, FROM_HERE, new MessageLoop::QuitTask()); - } - - protected: - virtual void SetUp() { - db_thread_.Start(); - worker_ = new DatabaseModelWorker(); - } - - virtual void Teardown() { - worker_.release(); - db_thread_.Stop(); - } - - private: - bool did_do_work_; - scoped_refptr<DatabaseModelWorker> worker_; - OneShotTimer<DatabaseModelWorkerTest> timer_; - - ChromeThread db_thread_; - MessageLoopForIO io_loop_; - ChromeThread io_thread_; - - ScopedRunnableMethodFactory<DatabaseModelWorkerTest> method_factory_; -}; - -TEST_F(DatabaseModelWorkerTest, DoesWorkOnDatabaseThread) { - MessageLoop::current()->PostTask(FROM_HERE, factory()->NewRunnableMethod( - &DatabaseModelWorkerTest::ScheduleWork)); - MessageLoop::current()->Run(); - EXPECT_TRUE(did_do_work()); -} - -} // namespace diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc index 2336f49..4a6d8d7 100644 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -113,7 +113,8 @@ void SyncBackendHost::Shutdown(bool sync_disabled) { core_thread_.Stop(); registrar_.routing_info.clear(); - registrar_.workers[GROUP_UI].release(); + delete registrar_.workers[GROUP_UI]; + registrar_.workers[GROUP_UI] = NULL; frontend_ = NULL; core_ = NULL; // Releases reference to core_. } diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h index 9e1f8c5..5150d4d 100644 --- a/chrome/browser/sync/glue/sync_backend_host.h +++ b/chrome/browser/sync/glue/sync_backend_host.h @@ -277,7 +277,7 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar { // any dependent types to GROUP_PASSIVE, so that the syncapi doesn't call // into garbage. If an index is non-NULL, it means at least one ModelType // that routes to that model safe group is being synced. - scoped_refptr<browser_sync::ModelSafeWorker> + browser_sync::ModelSafeWorker* workers[browser_sync::MODEL_SAFE_GROUP_COUNT]; browser_sync::ModelSafeRoutingInfo routing_info; } registrar_; diff --git a/chrome/browser/sync/glue/ui_model_worker_unittest.cc b/chrome/browser/sync/glue/ui_model_worker_unittest.cc index e90033d..85b02ab 100644 --- a/chrome/browser/sync/glue/ui_model_worker_unittest.cc +++ b/chrome/browser/sync/glue/ui_model_worker_unittest.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/ref_counted.h" #include "base/thread.h" #include "chrome/browser/sync/engine/syncapi.h" #include "chrome/browser/sync/glue/ui_model_worker.h" @@ -48,7 +47,7 @@ class Syncer { worker_->DoWorkAndWaitUntilDone(c.get()); } private: - scoped_refptr<UIModelWorker> worker_; + UIModelWorker* worker_; DISALLOW_COPY_AND_ASSIGN(Syncer); }; @@ -93,7 +92,7 @@ class FakeSyncapiShutdownTask : public Task { } private: base::Thread* syncer_thread_; - scoped_refptr<UIModelWorker> worker_; + UIModelWorker* worker_; base::WaitableEvent** jobs_; size_t job_count_; base::WaitableEvent all_jobs_done_; @@ -107,7 +106,7 @@ class UIModelWorkerTest : public testing::Test { virtual void SetUp() { faux_syncer_thread_.Start(); - bmw_ = new UIModelWorker(&faux_ui_loop_); + bmw_.reset(new UIModelWorker(&faux_ui_loop_)); syncer_.reset(new Syncer(bmw_.get())); } @@ -120,7 +119,7 @@ class UIModelWorkerTest : public testing::Test { MessageLoop faux_ui_loop_; base::Thread faux_syncer_thread_; base::Thread faux_core_thread_; - scoped_refptr<UIModelWorker> bmw_; + scoped_ptr<UIModelWorker> bmw_; scoped_ptr<Syncer> syncer_; }; |