diff options
author | pavely <pavely@chromium.org> | 2015-12-04 12:45:17 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-04 20:45:58 +0000 |
commit | d83166cef0b31328dead989eeee268e407f14b0f (patch) | |
tree | 9716027fa1d5eee82c013f95bcd25a96bc979c9b | |
parent | 67b148846af4f57eb9e68a103bee001d809db60a (diff) | |
download | chromium_src-d83166cef0b31328dead989eeee268e407f14b0f.zip chromium_src-d83166cef0b31328dead989eeee268e407f14b0f.tar.gz chromium_src-d83166cef0b31328dead989eeee268e407f14b0f.tar.bz2 |
[Sync] Implement support for on-disk ModelTypeStore
The change is to pass nullptr environment to ModelTypeStoreImpl. This
causes leveldb to use default file backed environment. Service code that
creates store needs to pass task runner. Comment explains where to get
one. In the future store will be shared between model types, at that
point initialization pattern will change.
BUG=517663
R=stanisc@chromium.org, skym@chromium.org
Review URL: https://codereview.chromium.org/1494333002
Cr-Commit-Position: refs/heads/master@{#363286}
-rw-r--r-- | sync/api/model_type_store.cc | 8 | ||||
-rw-r--r-- | sync/api/model_type_store.h | 19 | ||||
-rw-r--r-- | sync/internal_api/model_type_store_impl.cc | 27 | ||||
-rw-r--r-- | sync/internal_api/public/model_type_store_impl.h | 12 |
4 files changed, 60 insertions, 6 deletions
diff --git a/sync/api/model_type_store.cc b/sync/api/model_type_store.cc index 72af046..17afffc 100644 --- a/sync/api/model_type_store.cc +++ b/sync/api/model_type_store.cc @@ -13,6 +13,14 @@ void ModelTypeStore::CreateInMemoryStoreForTest(const InitCallback& callback) { ModelTypeStoreImpl::CreateInMemoryStoreForTest(callback); } +// static +void ModelTypeStore::CreateStore( + const std::string& path, + scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, + const InitCallback& callback) { + ModelTypeStoreImpl::CreateStore(path, blocking_task_runner, callback); +} + ModelTypeStore::~ModelTypeStore() {} ModelTypeStore::WriteBatch::WriteBatch() {} diff --git a/sync/api/model_type_store.h b/sync/api/model_type_store.h index c37eddd..51ddca6 100644 --- a/sync/api/model_type_store.h +++ b/sync/api/model_type_store.h @@ -12,6 +12,10 @@ #include "base/macros.h" #include "sync/base/sync_export.h" +namespace base { +class SequencedTaskRunner; +} // namespace base + namespace syncer_v2 { // ModelTypeStore is leveldb backed store for model type's data, metadata and @@ -85,6 +89,21 @@ class SYNC_EXPORT ModelTypeStore { const std::string& global_metadata)> ReadMetadataCallback; + // CreateStore takes |path| and |blocking_task_runner|. Here is how to get + // task runner in production code: + // + // base::SequencedWorkerPool* worker_pool = + // content::BrowserThread::GetBlockingPool(); + // scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( + // worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( + // worker_pool->GetSequenceToken(), + // base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); + // + // In test get task runner from MessageLoop::task_runner(). + static void CreateStore( + const std::string& path, + scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, + const InitCallback& callback); // Creates store object backed by in-memory leveldb database. It is used in // tests. static void CreateInMemoryStoreForTest(const InitCallback& callback); diff --git a/sync/internal_api/model_type_store_impl.cc b/sync/internal_api/model_type_store_impl.cc index ba55ef9..fa5a6b7 100644 --- a/sync/internal_api/model_type_store_impl.cc +++ b/sync/internal_api/model_type_store_impl.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/location.h" #include "base/logging.h" +#include "base/sequenced_task_runner.h" #include "base/task_runner_util.h" #include "base/thread_task_runner_handle.h" #include "sync/internal_api/public/model_type_store_backend.h" @@ -48,7 +49,7 @@ leveldb::WriteBatch* ModelTypeStoreImpl::GetLeveldbWriteBatch( ModelTypeStoreImpl::ModelTypeStoreImpl( scoped_ptr<ModelTypeStoreBackend> backend, - scoped_refptr<base::TaskRunner> backend_task_runner) + scoped_refptr<base::SequencedTaskRunner> backend_task_runner) : backend_(backend.Pass()), backend_task_runner_(backend_task_runner), weak_ptr_factory_(this) { @@ -63,6 +64,28 @@ ModelTypeStoreImpl::~ModelTypeStoreImpl() { } // static +void ModelTypeStoreImpl::CreateStore( + const std::string& path, + scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, + const InitCallback& callback) { + DCHECK(!callback.is_null()); + + scoped_ptr<ModelTypeStoreBackend> backend(new ModelTypeStoreBackend()); + + scoped_ptr<ModelTypeStoreImpl> store( + new ModelTypeStoreImpl(backend.Pass(), blocking_task_runner)); + + auto task = + base::Bind(&ModelTypeStoreBackend::Init, + base::Unretained(store->backend_.get()), path, nullptr); + auto reply = base::Bind(&ModelTypeStoreImpl::BackendInitDone, callback, + base::Passed(&store)); + + base::PostTaskAndReplyWithResult(blocking_task_runner.get(), FROM_HERE, task, + reply); +} + +// static void ModelTypeStoreImpl::CreateInMemoryStoreForTest( const InitCallback& callback) { DCHECK(!callback.is_null()); @@ -77,7 +100,7 @@ void ModelTypeStoreImpl::CreateInMemoryStoreForTest( backend->TakeEnvOwnership(env.Pass()); // In-memory store backend works on the same thread as test. - scoped_refptr<base::TaskRunner> task_runner = + scoped_refptr<base::SequencedTaskRunner> task_runner = base::ThreadTaskRunnerHandle::Get(); scoped_ptr<ModelTypeStoreImpl> store( new ModelTypeStoreImpl(backend.Pass(), task_runner)); diff --git a/sync/internal_api/public/model_type_store_impl.h b/sync/internal_api/public/model_type_store_impl.h index d9d0255..227afa0 100644 --- a/sync/internal_api/public/model_type_store_impl.h +++ b/sync/internal_api/public/model_type_store_impl.h @@ -10,7 +10,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/task_runner.h" #include "base/threading/non_thread_safe.h" #include "sync/api/model_type_store.h" @@ -29,6 +28,10 @@ class ModelTypeStoreImpl : public ModelTypeStore, public base::NonThreadSafe { public: ~ModelTypeStoreImpl() override; + static void CreateStore( + const std::string& path, + scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, + const InitCallback& callback); static void CreateInMemoryStoreForTest(const InitCallback& callback); // ModelTypeStore implementation. @@ -69,8 +72,9 @@ class ModelTypeStoreImpl : public ModelTypeStore, public base::NonThreadSafe { static leveldb::WriteBatch* GetLeveldbWriteBatch(WriteBatch* write_batch); - ModelTypeStoreImpl(scoped_ptr<ModelTypeStoreBackend> backend, - scoped_refptr<base::TaskRunner> backend_task_runner); + ModelTypeStoreImpl( + scoped_ptr<ModelTypeStoreBackend> backend, + scoped_refptr<base::SequencedTaskRunner> backend_task_runner); // Callbacks for different calls to ModelTypeStoreBackend. void ReadDataDone(const ReadDataCallback& callback, @@ -95,7 +99,7 @@ class ModelTypeStoreImpl : public ModelTypeStore, public base::NonThreadSafe { // accomplish this store's dtor posts task to backend thread passing backend // ownership to task parameter. scoped_ptr<ModelTypeStoreBackend> backend_; - scoped_refptr<base::TaskRunner> backend_task_runner_; + scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; base::WeakPtrFactory<ModelTypeStoreImpl> weak_ptr_factory_; }; |