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_ATTACHMENT_STORE_HANDLE_H_ | |
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_STORE_HANDLE_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/stl_util.h" | |
13 #include "base/threading/non_thread_safe.h" | |
14 #include "sync/api/attachments/attachment_store.h" | |
15 #include "sync/base/sync_export.h" | |
16 | |
17 namespace base { | |
18 class SequencedTaskRunner; | |
19 } // namespace base | |
20 | |
21 namespace sync_pb { | |
22 class AttachmentId; | |
23 } // namespace sync_pb | |
24 | |
25 namespace syncer { | |
26 | |
27 class Attachment; | |
28 | |
29 // AttachmentStoreHandle is helper to post AttachmentStore calls to backend on | |
30 // different thread. Backend is expected to know on which thread to post | |
31 // callbacks with results. | |
32 // AttachmentStoreHandle takes ownership of backend. Backend is deleted on | |
33 // backend thread. | |
34 // AttachmentStoreHandle is not thread safe, it should only be accessed from | |
35 // model thread. | |
36 class SYNC_EXPORT AttachmentStoreHandle : public AttachmentStore, | |
37 public base::NonThreadSafe { | |
38 public: | |
39 AttachmentStoreHandle( | |
40 scoped_ptr<AttachmentStoreBackend> backend, | |
41 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner); | |
42 | |
43 // AttachmentStore implementation. | |
44 void Init(const InitCallback& callback) override; | |
45 void Read(const AttachmentIdList& id, const ReadCallback& callback) override; | |
46 void Write(const AttachmentList& attachments, | |
47 const WriteCallback& callback) override; | |
48 void Drop(const AttachmentIdList& id, const DropCallback& callback) override; | |
49 void ReadMetadata(const AttachmentIdList& ids, | |
50 const ReadMetadataCallback& callback) override; | |
51 void ReadAllMetadata(const ReadMetadataCallback& callback) override; | |
52 | |
53 private: | |
54 ~AttachmentStoreHandle() override; | |
55 | |
56 // AttachmentStoreHandle controls backend's lifetime. It is safe for | |
57 // AttachmentStoreHandle to bind backend through base::Unretained for posts. | |
58 // Backend is deleted on backend_task_runner, after that backend_ pointer is | |
59 // invalid. | |
60 scoped_ptr<AttachmentStoreBackend> backend_; | |
61 scoped_refptr<base::SequencedTaskRunner> backend_task_runner_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(AttachmentStoreHandle); | |
64 }; | |
65 | |
66 } // namespace syncer | |
67 | |
68 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_STORE_HANDLE_H_ | |
OLD | NEW |