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.
5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/threading/non_thread_safe.h"
10 #include "sync/api/attachments/attachment.h"
11 #include "sync/api/attachments/attachment_id.h"
12 #include "sync/api/attachments/attachment_store.h"
13 #include "sync/api/attachments/attachment_store_backend.h"
14 #include "sync/base/sync_export.h"
17 class SequencedTaskRunner
;
22 // An in-memory implementation of AttachmentStore used for testing.
23 // InMemoryAttachmentStore is not threadsafe, it lives on backend thread and
24 // posts callbacks with results on |callback_task_runner|.
25 class SYNC_EXPORT InMemoryAttachmentStore
: public AttachmentStoreBackend
,
26 public base::NonThreadSafe
{
28 InMemoryAttachmentStore(
29 const scoped_refptr
<base::SequencedTaskRunner
>& callback_task_runner
);
30 ~InMemoryAttachmentStore() override
;
32 // AttachmentStoreBackend implementation.
33 void Init(const AttachmentStore::InitCallback
& callback
) override
;
34 void Read(const AttachmentIdList
& ids
,
35 const AttachmentStore::ReadCallback
& callback
) override
;
36 void Write(AttachmentStore::Component component
,
37 const AttachmentList
& attachments
,
38 const AttachmentStore::WriteCallback
& callback
) override
;
39 void SetReference(AttachmentStore::Component component
,
40 const AttachmentIdList
& ids
) override
;
41 void DropReference(AttachmentStore::Component component
,
42 const AttachmentIdList
& ids
,
43 const AttachmentStore::DropCallback
& callback
) override
;
45 const AttachmentIdList
& ids
,
46 const AttachmentStore::ReadMetadataCallback
& callback
) override
;
48 AttachmentStore::Component component
,
49 const AttachmentStore::ReadMetadataCallback
& callback
) override
;
52 struct AttachmentEntry
{
53 AttachmentEntry(const Attachment
& attachment
,
54 AttachmentStore::Component initial_reference_component
);
57 Attachment attachment
;
58 std::set
<AttachmentStore::Component
> components
;
61 typedef std::map
<AttachmentId
, AttachmentEntry
> AttachmentEntryMap
;
62 AttachmentEntryMap attachments_
;
64 DISALLOW_COPY_AND_ASSIGN(InMemoryAttachmentStore
);
69 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_