| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_ | |
| 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/threading/non_thread_safe.h" | |
| 14 #include "sync/api/attachments/attachment.h" | |
| 15 #include "sync/api/attachments/attachment_id.h" | |
| 16 #include "sync/api/attachments/attachment_store.h" | |
| 17 #include "sync/api/attachments/attachment_store_backend.h" | |
| 18 #include "sync/base/sync_export.h" | |
| 19 | |
| 20 namespace base { | |
| 21 class SequencedTaskRunner; | |
| 22 } // namespace base | |
| 23 | |
| 24 namespace syncer { | |
| 25 | |
| 26 // An in-memory implementation of AttachmentStore used for testing. | |
| 27 // InMemoryAttachmentStore is not threadsafe, it lives on backend thread and | |
| 28 // posts callbacks with results on |callback_task_runner|. | |
| 29 class SYNC_EXPORT InMemoryAttachmentStore : public AttachmentStoreBackend, | |
| 30 public base::NonThreadSafe { | |
| 31 public: | |
| 32 InMemoryAttachmentStore( | |
| 33 const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner); | |
| 34 ~InMemoryAttachmentStore() override; | |
| 35 | |
| 36 // AttachmentStoreBackend implementation. | |
| 37 void Init(const AttachmentStore::InitCallback& callback) override; | |
| 38 void Read(AttachmentStore::Component component, | |
| 39 const AttachmentIdList& ids, | |
| 40 const AttachmentStore::ReadCallback& callback) override; | |
| 41 void Write(AttachmentStore::Component component, | |
| 42 const AttachmentList& attachments, | |
| 43 const AttachmentStore::WriteCallback& callback) override; | |
| 44 void SetReference(AttachmentStore::Component component, | |
| 45 const AttachmentIdList& ids) override; | |
| 46 void DropReference(AttachmentStore::Component component, | |
| 47 const AttachmentIdList& ids, | |
| 48 const AttachmentStore::DropCallback& callback) override; | |
| 49 void ReadMetadataById( | |
| 50 AttachmentStore::Component component, | |
| 51 const AttachmentIdList& ids, | |
| 52 const AttachmentStore::ReadMetadataCallback& callback) override; | |
| 53 void ReadMetadata( | |
| 54 AttachmentStore::Component component, | |
| 55 const AttachmentStore::ReadMetadataCallback& callback) override; | |
| 56 | |
| 57 private: | |
| 58 struct AttachmentEntry { | |
| 59 AttachmentEntry(const Attachment& attachment, | |
| 60 AttachmentStore::Component initial_reference_component); | |
| 61 AttachmentEntry(const AttachmentEntry& other); | |
| 62 ~AttachmentEntry(); | |
| 63 | |
| 64 Attachment attachment; | |
| 65 std::set<AttachmentStore::Component> components; | |
| 66 }; | |
| 67 | |
| 68 typedef std::map<AttachmentId, AttachmentEntry> AttachmentEntryMap; | |
| 69 AttachmentEntryMap attachments_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(InMemoryAttachmentStore); | |
| 72 }; | |
| 73 | |
| 74 } // namespace syncer | |
| 75 | |
| 76 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_ | |
| OLD | NEW |