| 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/message_loop/message_loop.h" |
| 11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "sync/internal_api/public/attachments/attachment_store_frontend.h" | 13 #include "sync/internal_api/public/attachments/attachment_store_frontend.h" |
| 14 #include "sync/internal_api/public/attachments/in_memory_attachment_store.h" | 14 #include "sync/internal_api/public/attachments/in_memory_attachment_store.h" |
| 15 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h" | 15 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h" |
| 16 | 16 |
| 17 namespace syncer { | 17 namespace syncer { |
| 18 | 18 |
| 19 namespace { |
| 20 |
| 21 void NoOpDropCallback(const AttachmentStore::Result& result) { |
| 22 } |
| 23 } |
| 24 |
| 19 AttachmentStore::AttachmentStore( | 25 AttachmentStore::AttachmentStore( |
| 20 const scoped_refptr<AttachmentStoreFrontend>& frontend, | 26 const scoped_refptr<AttachmentStoreFrontend>& frontend, |
| 21 AttachmentReferrer referrer) | 27 Component component) |
| 22 : frontend_(frontend), referrer_(referrer) { | 28 : frontend_(frontend), component_(component) { |
| 23 } | 29 } |
| 24 | 30 |
| 25 AttachmentStore::~AttachmentStore() { | 31 AttachmentStore::~AttachmentStore() { |
| 26 } | 32 } |
| 27 | 33 |
| 28 void AttachmentStore::Read(const AttachmentIdList& ids, | 34 void AttachmentStore::Read(const AttachmentIdList& ids, |
| 29 const ReadCallback& callback) { | 35 const ReadCallback& callback) { |
| 30 frontend_->Read(ids, callback); | 36 frontend_->Read(ids, callback); |
| 31 } | 37 } |
| 32 | 38 |
| 33 void AttachmentStore::Write(const AttachmentList& attachments, | 39 void AttachmentStore::Write(const AttachmentList& attachments, |
| 34 const WriteCallback& callback) { | 40 const WriteCallback& callback) { |
| 35 frontend_->Write(referrer_, attachments, callback); | 41 frontend_->Write(component_, attachments, callback); |
| 36 } | 42 } |
| 37 | 43 |
| 38 void AttachmentStore::Drop(const AttachmentIdList& ids, | 44 void AttachmentStore::Drop(const AttachmentIdList& ids, |
| 39 const DropCallback& callback) { | 45 const DropCallback& callback) { |
| 40 frontend_->Drop(referrer_, ids, callback); | 46 frontend_->DropReference(component_, ids, callback); |
| 41 } | 47 } |
| 42 | 48 |
| 43 void AttachmentStore::ReadMetadata(const AttachmentIdList& ids, | 49 void AttachmentStore::ReadMetadata(const AttachmentIdList& ids, |
| 44 const ReadMetadataCallback& callback) { | 50 const ReadMetadataCallback& callback) { |
| 45 frontend_->ReadMetadata(ids, callback); | 51 frontend_->ReadMetadata(ids, callback); |
| 46 } | 52 } |
| 47 | 53 |
| 48 void AttachmentStore::ReadAllMetadata(const ReadMetadataCallback& callback) { | 54 void AttachmentStore::ReadAllMetadata(const ReadMetadataCallback& callback) { |
| 49 frontend_->ReadAllMetadata(referrer_, callback); | 55 frontend_->ReadAllMetadata(component_, callback); |
| 50 } | 56 } |
| 51 | 57 |
| 52 scoped_ptr<AttachmentStore> AttachmentStore::CreateAttachmentStoreForSync() | 58 scoped_ptr<AttachmentStoreForSync> |
| 53 const { | 59 AttachmentStore::CreateAttachmentStoreForSync() const { |
| 54 scoped_ptr<AttachmentStore> attachment_store( | 60 scoped_ptr<AttachmentStoreForSync> attachment_store_for_sync( |
| 55 new AttachmentStore(frontend_, SYNC)); | 61 new AttachmentStoreForSync(frontend_, component_, SYNC)); |
| 56 return attachment_store.Pass(); | 62 return attachment_store_for_sync.Pass(); |
| 57 } | 63 } |
| 58 | 64 |
| 59 scoped_ptr<AttachmentStore> AttachmentStore::CreateInMemoryStore() { | 65 scoped_ptr<AttachmentStore> AttachmentStore::CreateInMemoryStore() { |
| 60 // Both frontend and backend of attachment store will live on current thread. | 66 // Both frontend and backend of attachment store will live on current thread. |
| 61 scoped_refptr<base::SingleThreadTaskRunner> runner; | 67 scoped_refptr<base::SingleThreadTaskRunner> runner; |
| 62 if (base::ThreadTaskRunnerHandle::IsSet()) { | 68 if (base::ThreadTaskRunnerHandle::IsSet()) { |
| 63 runner = base::ThreadTaskRunnerHandle::Get(); | 69 runner = base::ThreadTaskRunnerHandle::Get(); |
| 64 } else { | 70 } else { |
| 65 // Dummy runner for tests that don't have MessageLoop. | 71 // Dummy runner for tests that don't have MessageLoop. |
| 66 base::MessageLoop loop; | 72 base::MessageLoop loop; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 96 scoped_ptr<AttachmentStoreBackend> backend) { | 102 scoped_ptr<AttachmentStoreBackend> backend) { |
| 97 scoped_refptr<base::SingleThreadTaskRunner> runner = | 103 scoped_refptr<base::SingleThreadTaskRunner> runner = |
| 98 base::ThreadTaskRunnerHandle::Get(); | 104 base::ThreadTaskRunnerHandle::Get(); |
| 99 scoped_refptr<AttachmentStoreFrontend> attachment_store_frontend( | 105 scoped_refptr<AttachmentStoreFrontend> attachment_store_frontend( |
| 100 new AttachmentStoreFrontend(backend.Pass(), runner)); | 106 new AttachmentStoreFrontend(backend.Pass(), runner)); |
| 101 scoped_ptr<AttachmentStore> attachment_store( | 107 scoped_ptr<AttachmentStore> attachment_store( |
| 102 new AttachmentStore(attachment_store_frontend, MODEL_TYPE)); | 108 new AttachmentStore(attachment_store_frontend, MODEL_TYPE)); |
| 103 return attachment_store.Pass(); | 109 return attachment_store.Pass(); |
| 104 } | 110 } |
| 105 | 111 |
| 112 AttachmentStoreForSync::AttachmentStoreForSync( |
| 113 const scoped_refptr<AttachmentStoreFrontend>& frontend, |
| 114 Component consumer_component, |
| 115 Component sync_component) |
| 116 : AttachmentStore(frontend, consumer_component), |
| 117 sync_component_(sync_component) { |
| 118 } |
| 119 |
| 120 void AttachmentStoreForSync::SetSyncReference(const AttachmentIdList& ids) { |
| 121 frontend()->SetReference(sync_component_, ids); |
| 122 } |
| 123 |
| 124 void AttachmentStoreForSync::DropSyncReference(const AttachmentIdList& ids) { |
| 125 frontend()->DropReference(sync_component_, ids, |
| 126 base::Bind(&NoOpDropCallback)); |
| 127 } |
| 128 |
| 106 } // namespace syncer | 129 } // namespace syncer |
| OLD | NEW |