Chromium Code Reviews| Index: sync/internal_api/model_type_store_impl.cc |
| diff --git a/sync/internal_api/model_type_store_impl.cc b/sync/internal_api/model_type_store_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..55d62cd94568cc599360f39fae5f5e1b3860fd28 |
| --- /dev/null |
| +++ b/sync/internal_api/model_type_store_impl.cc |
| @@ -0,0 +1,132 @@ |
| +// Copyright 2015 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 "sync/internal_api/public/model_type_store_impl.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/location.h" |
| +#include "base/logging.h" |
| +#include "base/task_runner_util.h" |
| +#include "base/thread_task_runner_handle.h" |
| +#include "sync/internal_api/public/model_type_store_backend.h" |
| + |
| +namespace syncer_v2 { |
| + |
| +namespace { |
| + |
| +void NoOpForBackendDtor(scoped_ptr<ModelTypeStoreBackend> backend) { |
| + // This function was intentionally left blank. |
| +} |
| + |
| +} // namespace |
| + |
| +ModelTypeStoreImpl::ModelTypeStoreImpl( |
| + scoped_ptr<ModelTypeStoreBackend> backend, |
| + scoped_refptr<base::SingleThreadTaskRunner> backend_task_runner) |
| + : backend_(backend.Pass()), backend_task_runner_(backend_task_runner) { |
| + DCHECK(backend_); |
| + DCHECK(backend_task_runner_); |
| +} |
| + |
| +ModelTypeStoreImpl::~ModelTypeStoreImpl() { |
| + DCHECK(CalledOnValidThread()); |
| + backend_task_runner_->PostTask( |
| + FROM_HERE, base::Bind(&NoOpForBackendDtor, base::Passed(&backend_))); |
| +} |
| + |
| +// static |
| +void ModelTypeStoreImpl::CreateInMemoryStoreForTest( |
| + const InitCallback& callback) { |
| + // In-memory store backend works on the same thread as test. |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| + base::ThreadTaskRunnerHandle::Get(); |
| + |
| + scoped_ptr<ModelTypeStoreBackend> backend(new ModelTypeStoreBackend()); |
| + scoped_ptr<ModelTypeStoreImpl> store( |
| + new ModelTypeStoreImpl(backend.Pass(), task_runner)); |
| + auto task = base::Bind(&ModelTypeStoreBackend::Init, |
| + base::Unretained(store->backend_.get())); |
| + auto reply = base::Bind(&ModelTypeStoreImpl::BackendInitDone, callback, |
| + base::Passed(&store)); |
| + |
| + base::PostTaskAndReplyWithResult(task_runner.get(), FROM_HERE, task, reply); |
| +} |
| + |
| +// static |
| +void ModelTypeStoreImpl::BackendInitDone(const InitCallback& callback, |
| + scoped_ptr<ModelTypeStoreImpl> store, |
| + Result result) { |
| + DCHECK(!callback.is_null()); |
| + if (result == Result::SUCCESS) { |
| + DCHECK(store->CalledOnValidThread()); |
|
stanisc
2015/11/03 18:52:20
Why this DCHECK is for the SUCCESS case only?
pavely
2015/11/03 21:38:08
You are right. I also forgot that I should reset s
|
| + } |
| + callback.Run(result, store.Pass()); |
| +} |
| + |
| +void ModelTypeStoreImpl::ReadData(const IdList& id_list, |
| + const ReadRecordsCallback& callback) { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ModelTypeStoreImpl::ReadAllData(const ReadRecordsCallback& callback) { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ModelTypeStoreImpl::ReadAllMetadata(const ReadMetadataCallback& callback) { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +scoped_ptr<ModelTypeStore::WriteBatch> ModelTypeStoreImpl::CreateWriteBatch() { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| + return make_scoped_ptr(new WriteBatchImpl()); |
| +} |
| + |
| +void ModelTypeStoreImpl::CommitWriteBatch(scoped_ptr<WriteBatch> write_batch, |
| + const CallbackWithResult& callback) { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ModelTypeStoreImpl::WriteData(WriteBatch* write_batch, |
| + const std::string& id, |
| + const std::string& value) { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ModelTypeStoreImpl::WriteMetadata(WriteBatch* write_batch, |
| + const std::string& id, |
| + const std::string& value) { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ModelTypeStoreImpl::WriteGlobalMetadata(WriteBatch* write_batch, |
| + const std::string& value) { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ModelTypeStoreImpl::DeleteData(WriteBatch* write_batch, |
| + const std::string& id) { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ModelTypeStoreImpl::DeleteMetadata(WriteBatch* write_batch, |
| + const std::string& id) { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +void ModelTypeStoreImpl::DeleteGlobalMetadata(WriteBatch* write_batch) { |
| + DCHECK(CalledOnValidThread()); |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +} // namespace syncer_v2 |