summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sync/api/model_type_store.cc8
-rw-r--r--sync/api/model_type_store.h19
-rw-r--r--sync/internal_api/model_type_store_impl.cc27
-rw-r--r--sync/internal_api/public/model_type_store_impl.h12
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_;
};