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(AttachmentStore::Component component
,
41 const AttachmentIdList
& ids
,
42 const AttachmentStore::ReadCallback
& callback
);
44 void Write(AttachmentStore::Component component
,
45 const AttachmentList
& attachments
,
46 const AttachmentStore::WriteCallback
& callback
);
47 void SetReference(AttachmentStore::Component component
,
48 const AttachmentIdList
& ids
);
49 void DropReference(AttachmentStore::Component component
,
50 const AttachmentIdList
& ids
,
51 const AttachmentStore::DropCallback
& callback
);
53 void ReadMetadataById(AttachmentStore::Component component
,
54 const AttachmentIdList
& ids
,
55 const AttachmentStore::ReadMetadataCallback
& callback
);
57 void ReadMetadata(AttachmentStore::Component component
,
58 const AttachmentStore::ReadMetadataCallback
& callback
);
61 friend class base::RefCounted
<AttachmentStoreFrontend
>;
62 virtual ~AttachmentStoreFrontend();
64 scoped_ptr
<AttachmentStoreBackend
> backend_
;
65 scoped_refptr
<base::SequencedTaskRunner
> backend_task_runner_
;
67 DISALLOW_COPY_AND_ASSIGN(AttachmentStoreFrontend
);
72 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_STORE_FRONTEND_H_