| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sync/api/attachments/attachment_store.h" | 5 #include "sync/api/attachments/attachment_store.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop/message_loop.h" |
| 10 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 12 #include "sync/internal_api/public/attachments/attachment_store_handle.h" | 13 #include "sync/internal_api/public/attachments/attachment_store_handle.h" |
| 13 #include "sync/internal_api/public/attachments/in_memory_attachment_store.h" | 14 #include "sync/internal_api/public/attachments/in_memory_attachment_store.h" |
| 14 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h" | 15 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h" |
| 15 | 16 |
| 16 namespace syncer { | 17 namespace syncer { |
| 17 | 18 |
| 18 AttachmentStoreBase::AttachmentStoreBase() {} | 19 AttachmentStoreBase::AttachmentStoreBase() {} |
| 19 AttachmentStoreBase::~AttachmentStoreBase() {} | 20 AttachmentStoreBase::~AttachmentStoreBase() {} |
| 20 | 21 |
| 21 AttachmentStore::AttachmentStore() {} | 22 AttachmentStore::AttachmentStore() {} |
| 22 AttachmentStore::~AttachmentStore() {} | 23 AttachmentStore::~AttachmentStore() {} |
| 23 | 24 |
| 24 scoped_refptr<AttachmentStore> AttachmentStore::CreateInMemoryStore() { | 25 scoped_refptr<AttachmentStore> AttachmentStore::CreateInMemoryStore() { |
| 25 // Both frontend and backend of attachment store will live on current thread. | 26 // Both frontend and backend of attachment store will live on current thread. |
| 26 scoped_ptr<AttachmentStoreBase> backend( | 27 scoped_refptr<base::SingleThreadTaskRunner> runner; |
| 27 new InMemoryAttachmentStore(base::ThreadTaskRunnerHandle::Get())); | 28 if (base::ThreadTaskRunnerHandle::IsSet()) { |
| 28 return scoped_refptr<AttachmentStore>(new AttachmentStoreHandle( | 29 runner = base::ThreadTaskRunnerHandle::Get(); |
| 29 backend.Pass(), base::ThreadTaskRunnerHandle::Get())); | 30 } else { |
| 31 // Dummy runner for tests that don't have MessageLoop. |
| 32 base::MessageLoop loop; |
| 33 // This works because |runner| takes a ref to the proxy. |
| 34 runner = base::ThreadTaskRunnerHandle::Get(); |
| 35 } |
| 36 scoped_ptr<AttachmentStoreBase> backend(new InMemoryAttachmentStore(runner)); |
| 37 return scoped_refptr<AttachmentStore>( |
| 38 new AttachmentStoreHandle(backend.Pass(), runner)); |
| 30 } | 39 } |
| 31 | 40 |
| 32 scoped_refptr<AttachmentStore> AttachmentStore::CreateOnDiskStore( | 41 scoped_refptr<AttachmentStore> AttachmentStore::CreateOnDiskStore( |
| 33 const base::FilePath& path, | 42 const base::FilePath& path, |
| 34 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner, | 43 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner, |
| 35 const InitCallback& callback) { | 44 const InitCallback& callback) { |
| 36 scoped_ptr<OnDiskAttachmentStore> backend( | 45 scoped_ptr<OnDiskAttachmentStore> backend( |
| 37 new OnDiskAttachmentStore(base::ThreadTaskRunnerHandle::Get(), path)); | 46 new OnDiskAttachmentStore(base::ThreadTaskRunnerHandle::Get(), path)); |
| 38 | 47 |
| 39 scoped_refptr<AttachmentStore> attachment_store = | 48 scoped_refptr<AttachmentStore> attachment_store = |
| 40 new AttachmentStoreHandle(backend.Pass(), backend_task_runner); | 49 new AttachmentStoreHandle(backend.Pass(), backend_task_runner); |
| 41 attachment_store->Init(callback); | 50 attachment_store->Init(callback); |
| 42 | 51 |
| 43 return attachment_store; | 52 return attachment_store; |
| 44 } | 53 } |
| 45 | 54 |
| 46 } // namespace syncer | 55 } // namespace syncer |
| OLD | NEW |