OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ | 5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ |
6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ | 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "sync/api/attachments/attachment.h" | 11 #include "sync/api/attachments/attachment.h" |
12 #include "sync/api/attachments/attachment_id.h" | 12 #include "sync/api/attachments/attachment_id.h" |
13 #include "sync/base/sync_export.h" | 13 #include "sync/base/sync_export.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class RefCountedMemory; | 16 class RefCountedMemory; |
17 } // namespace base | 17 } // namespace base |
18 | 18 |
19 namespace syncer { | 19 namespace syncer { |
20 | 20 |
21 class Attachment; | 21 class Attachment; |
22 class AttachmentId; | 22 class AttachmentId; |
23 | 23 |
24 // A place to locally store and access Attachments. | 24 // A place to locally store and access Attachments. |
25 // | 25 // |
26 // Destroying this object does not necessarily cancel outstanding async | 26 // Destroying this object does not necessarily cancel outstanding async |
27 // operations. If you need cancel like semantics, use WeakPtr in the callbacks. | 27 // operations. If you need cancel like semantics, use WeakPtr in the callbacks. |
28 class SYNC_EXPORT AttachmentStoreBase { | 28 class SYNC_EXPORT AttachmentStore : public base::RefCounted<AttachmentStore> { |
29 public: | 29 public: |
| 30 AttachmentStore(); |
| 31 |
30 // TODO(maniscalco): Consider udpating Read and Write methods to support | 32 // TODO(maniscalco): Consider udpating Read and Write methods to support |
31 // resumable transfers (bug 353292). | 33 // resumable transfers (bug 353292). |
32 | 34 |
33 enum Result { | 35 enum Result { |
34 SUCCESS, // No error, all completed successfully. | 36 SUCCESS, // No error, all completed successfully. |
35 UNSPECIFIED_ERROR, // An unspecified error occurred for one or more items. | 37 UNSPECIFIED_ERROR, // An unspecified error occurred for one or more items. |
36 }; | 38 }; |
37 | 39 |
38 typedef base::Callback<void(const Result&, | 40 typedef base::Callback<void(const Result&, |
39 scoped_ptr<AttachmentMap>, | 41 scoped_ptr<AttachmentMap>, |
40 scoped_ptr<AttachmentIdList>)> ReadCallback; | 42 scoped_ptr<AttachmentIdList>)> ReadCallback; |
41 typedef base::Callback<void(const Result&)> WriteCallback; | 43 typedef base::Callback<void(const Result&)> WriteCallback; |
42 typedef base::Callback<void(const Result&)> DropCallback; | 44 typedef base::Callback<void(const Result&)> DropCallback; |
43 | 45 |
44 AttachmentStoreBase(); | |
45 virtual ~AttachmentStoreBase(); | |
46 | |
47 // Asynchronously reads the attachments identified by |ids|. | 46 // Asynchronously reads the attachments identified by |ids|. |
48 // | 47 // |
49 // |callback| will be invoked when finished. AttachmentStore will attempt to | 48 // |callback| will be invoked when finished. AttachmentStore will attempt to |
50 // read all attachments specified in ids. If any of the attachments do not | 49 // read all attachments specified in ids. If any of the attachments do not |
51 // exist or could not be read, |callback|'s Result will be UNSPECIFIED_ERROR. | 50 // exist or could not be read, |callback|'s Result will be UNSPECIFIED_ERROR. |
52 // Callback's AttachmentMap will contain all attachments that were | 51 // Callback's AttachmentMap will contain all attachments that were |
53 // successfully read, AttachmentIdList will contain attachment ids of | 52 // successfully read, AttachmentIdList will contain attachment ids of |
54 // attachments that are unavailable in attachment store, these need to be | 53 // attachments that are unavailable in attachment store, these need to be |
55 // downloaded from server. | 54 // downloaded from server. |
56 // | 55 // |
(...skipping 18 matching lines...) Expand all Loading... |
75 // | 74 // |
76 // This does not remove attachments from the server. | 75 // This does not remove attachments from the server. |
77 // | 76 // |
78 // |callback| will be invoked when finished. Attempting to drop an attachment | 77 // |callback| will be invoked when finished. Attempting to drop an attachment |
79 // that does not exist is not an error. If any of the existing attachment | 78 // that does not exist is not an error. If any of the existing attachment |
80 // could not be dropped, |callback|'s Result will be UNSPECIFIED_ERROR. When | 79 // could not be dropped, |callback|'s Result will be UNSPECIFIED_ERROR. When |
81 // this happens, some or none of the attachments may have been dropped | 80 // this happens, some or none of the attachments may have been dropped |
82 // successfully. | 81 // successfully. |
83 virtual void Drop(const AttachmentIdList& ids, | 82 virtual void Drop(const AttachmentIdList& ids, |
84 const DropCallback& callback) = 0; | 83 const DropCallback& callback) = 0; |
85 }; | |
86 | |
87 // AttachmentStore is an interface exposed to data type and AttachmentService | |
88 // code. Also contains factory methods for default implementations. | |
89 class SYNC_EXPORT AttachmentStore | |
90 : public AttachmentStoreBase, | |
91 public base::RefCountedThreadSafe<AttachmentStore> { | |
92 public: | |
93 AttachmentStore(); | |
94 | |
95 // Creates an AttachmentStoreHandle backed by in-memory implementation of | |
96 // attachment store. For now frontend lives on the same thread as backend. | |
97 static scoped_refptr<AttachmentStore> CreateInMemoryStore(); | |
98 | 84 |
99 protected: | 85 protected: |
100 friend class base::RefCountedThreadSafe<AttachmentStore>; | 86 friend class base::RefCounted<AttachmentStore>; |
101 virtual ~AttachmentStore(); | 87 virtual ~AttachmentStore(); |
102 }; | 88 }; |
103 | 89 |
104 } // namespace syncer | 90 } // namespace syncer |
105 | 91 |
106 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ | 92 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ |
OLD | NEW |