diff options
Diffstat (limited to 'sync/api/attachments/attachment_store.cc')
-rw-r--r-- | sync/api/attachments/attachment_store.cc | 83 |
1 files changed, 62 insertions, 21 deletions
diff --git a/sync/api/attachments/attachment_store.cc b/sync/api/attachments/attachment_store.cc index 91b3f95..7cf774e 100644 --- a/sync/api/attachments/attachment_store.cc +++ b/sync/api/attachments/attachment_store.cc @@ -10,16 +10,53 @@ #include "base/message_loop/message_loop.h" #include "base/sequenced_task_runner.h" #include "base/thread_task_runner_handle.h" -#include "sync/internal_api/public/attachments/attachment_store_handle.h" +#include "sync/internal_api/public/attachments/attachment_store_frontend.h" #include "sync/internal_api/public/attachments/in_memory_attachment_store.h" #include "sync/internal_api/public/attachments/on_disk_attachment_store.h" namespace syncer { -AttachmentStore::AttachmentStore() {} -AttachmentStore::~AttachmentStore() {} +AttachmentStore::AttachmentStore( + const scoped_refptr<AttachmentStoreFrontend>& frontend, + AttachmentReferrer referrer) + : frontend_(frontend), referrer_(referrer) { +} + +AttachmentStore::~AttachmentStore() { +} + +void AttachmentStore::Read(const AttachmentIdList& ids, + const ReadCallback& callback) { + frontend_->Read(ids, callback); +} -scoped_refptr<AttachmentStore> AttachmentStore::CreateInMemoryStore() { +void AttachmentStore::Write(const AttachmentList& attachments, + const WriteCallback& callback) { + frontend_->Write(referrer_, attachments, callback); +} + +void AttachmentStore::Drop(const AttachmentIdList& ids, + const DropCallback& callback) { + frontend_->Drop(referrer_, ids, callback); +} + +void AttachmentStore::ReadMetadata(const AttachmentIdList& ids, + const ReadMetadataCallback& callback) { + frontend_->ReadMetadata(ids, callback); +} + +void AttachmentStore::ReadAllMetadata(const ReadMetadataCallback& callback) { + frontend_->ReadAllMetadata(referrer_, callback); +} + +scoped_ptr<AttachmentStore> AttachmentStore::CreateAttachmentStoreForSync() + const { + scoped_ptr<AttachmentStore> attachment_store( + new AttachmentStore(frontend_, SYNC)); + return attachment_store.Pass(); +} + +scoped_ptr<AttachmentStore> AttachmentStore::CreateInMemoryStore() { // Both frontend and backend of attachment store will live on current thread. scoped_refptr<base::SingleThreadTaskRunner> runner; if (base::ThreadTaskRunnerHandle::IsSet()) { @@ -32,34 +69,38 @@ scoped_refptr<AttachmentStore> AttachmentStore::CreateInMemoryStore() { } scoped_ptr<AttachmentStoreBackend> backend( new InMemoryAttachmentStore(runner)); - return scoped_refptr<AttachmentStore>( - new AttachmentStoreHandle(backend.Pass(), runner)); + scoped_refptr<AttachmentStoreFrontend> frontend( + new AttachmentStoreFrontend(backend.Pass(), runner)); + scoped_ptr<AttachmentStore> attachment_store( + new AttachmentStore(frontend, MODEL_TYPE)); + return attachment_store.Pass(); } -scoped_refptr<AttachmentStore> AttachmentStore::CreateOnDiskStore( +scoped_ptr<AttachmentStore> AttachmentStore::CreateOnDiskStore( const base::FilePath& path, const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner, const InitCallback& callback) { scoped_ptr<OnDiskAttachmentStore> backend( new OnDiskAttachmentStore(base::ThreadTaskRunnerHandle::Get(), path)); - scoped_refptr<AttachmentStore> attachment_store = - new AttachmentStoreHandle(backend.Pass(), backend_task_runner); - attachment_store->Init(callback); - - return attachment_store; -} - -AttachmentStoreBackend::AttachmentStoreBackend( - const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner) - : callback_task_runner_(callback_task_runner) { -} + scoped_refptr<AttachmentStoreFrontend> frontend = + new AttachmentStoreFrontend(backend.Pass(), backend_task_runner); + scoped_ptr<AttachmentStore> attachment_store( + new AttachmentStore(frontend, MODEL_TYPE)); + frontend->Init(callback); -AttachmentStoreBackend::~AttachmentStoreBackend() { + return attachment_store.Pass(); } -void AttachmentStoreBackend::PostCallback(const base::Closure& callback) { - callback_task_runner_->PostTask(FROM_HERE, callback); +scoped_ptr<AttachmentStore> AttachmentStore::CreateMockStoreForTest( + scoped_ptr<AttachmentStoreBackend> backend) { + scoped_refptr<base::SingleThreadTaskRunner> runner = + base::ThreadTaskRunnerHandle::Get(); + scoped_refptr<AttachmentStoreFrontend> attachment_store_frontend( + new AttachmentStoreFrontend(backend.Pass(), runner)); + scoped_ptr<AttachmentStore> attachment_store( + new AttachmentStore(attachment_store_frontend, MODEL_TYPE)); + return attachment_store.Pass(); } } // namespace syncer |