1 // Copyright 2015 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_ATTACHMENT_STORE_FRONTEND_H_
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_STORE_FRONTEND_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "sync/api/attachments/attachment_store.h"
14 class SequencedTaskRunner
;
19 class AttachmentStoreBackend
;
21 // AttachmentStoreFrontend is helper to post AttachmentStore calls to backend on
22 // different thread. Backend is expected to know on which thread to post
23 // callbacks with results.
24 // AttachmentStoreFrontend takes ownership of backend. Backend is deleted on
26 // AttachmentStoreFrontend is not thread safe, it should only be accessed from
28 // Method signatures of AttachmentStoreFrontend match exactly methods of
29 // AttachmentStoreBackend.
30 class SYNC_EXPORT AttachmentStoreFrontend
31 : public base::RefCounted
<AttachmentStoreFrontend
>,
32 public base::NonThreadSafe
{
34 AttachmentStoreFrontend(
35 scoped_ptr
<AttachmentStoreBackend
> backend
,
36 const scoped_refptr
<base::SequencedTaskRunner
>& backend_task_runner
);
38 void Init(const AttachmentStore::InitCallback
& callback
);
40 void Read(const AttachmentIdList
& ids
,
41 const AttachmentStore::ReadCallback
& callback
);
43 void Write(AttachmentStore::Component component
,
44 const AttachmentList
& attachments
,
45 const AttachmentStore::WriteCallback
& callback
);
46 void SetReference(AttachmentStore::Component component
,
47 const AttachmentIdList
& ids
);
48 void DropReference(AttachmentStore::Component component
,
49 const AttachmentIdList
& ids
,
50 const AttachmentStore::DropCallback
& callback
);
52 void ReadMetadata(const AttachmentIdList
& ids
,
53 const AttachmentStore::ReadMetadataCallback
& callback
);
55 void ReadAllMetadata(AttachmentStore::Component component
,
56 const AttachmentStore::ReadMetadataCallback
& callback
);
59 friend class base::RefCounted
<AttachmentStoreFrontend
>;
60 virtual ~AttachmentStoreFrontend();
62 scoped_ptr
<AttachmentStoreBackend
> backend_
;
63 scoped_refptr
<base::SequencedTaskRunner
> backend_task_runner_
;
65 DISALLOW_COPY_AND_ASSIGN(AttachmentStoreFrontend
);
70 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_STORE_FRONTEND_H_