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 AttachmentStore : public base::RefCounted<AttachmentStore> { | 28 class SYNC_EXPORT AttachmentStoreBase { |
29 public: | 29 public: |
30 AttachmentStore(); | |
31 | |
32 // TODO(maniscalco): Consider udpating Read and Write methods to support | 30 // TODO(maniscalco): Consider udpating Read and Write methods to support |
33 // resumable transfers (bug 353292). | 31 // resumable transfers (bug 353292). |
34 | 32 |
35 enum Result { | 33 enum Result { |
36 SUCCESS, // No error, all completed successfully. | 34 SUCCESS, // No error, all completed successfully. |
37 UNSPECIFIED_ERROR, // An unspecified error occurred for one or more items. | 35 UNSPECIFIED_ERROR, // An unspecified error occurred for one or more items. |
38 }; | 36 }; |
39 | 37 |
40 typedef base::Callback<void(const Result&, | 38 typedef base::Callback<void(const Result&, |
41 scoped_ptr<AttachmentMap>, | 39 scoped_ptr<AttachmentMap>, |
42 scoped_ptr<AttachmentIdList>)> ReadCallback; | 40 scoped_ptr<AttachmentIdList>)> ReadCallback; |
43 typedef base::Callback<void(const Result&)> WriteCallback; | 41 typedef base::Callback<void(const Result&)> WriteCallback; |
44 typedef base::Callback<void(const Result&)> DropCallback; | 42 typedef base::Callback<void(const Result&)> DropCallback; |
45 | 43 |
| 44 AttachmentStoreBase(); |
| 45 virtual ~AttachmentStoreBase(); |
| 46 |
46 // Asynchronously reads the attachments identified by |ids|. | 47 // Asynchronously reads the attachments identified by |ids|. |
47 // | 48 // |
48 // |callback| will be invoked when finished. AttachmentStore will attempt to | 49 // |callback| will be invoked when finished. AttachmentStore will attempt to |
49 // read all attachments specified in ids. If any of the attachments do not | 50 // read all attachments specified in ids. If any of the attachments do not |
50 // exist or could not be read, |callback|'s Result will be UNSPECIFIED_ERROR. | 51 // exist or could not be read, |callback|'s Result will be UNSPECIFIED_ERROR. |
51 // Callback's AttachmentMap will contain all attachments that were | 52 // Callback's AttachmentMap will contain all attachments that were |
52 // successfully read, AttachmentIdList will contain attachment ids of | 53 // successfully read, AttachmentIdList will contain attachment ids of |
53 // attachments that are unavailable in attachment store, these need to be | 54 // attachments that are unavailable in attachment store, these need to be |
54 // downloaded from server. | 55 // downloaded from server. |
55 // | 56 // |
(...skipping 18 matching lines...) Expand all Loading... |
74 // | 75 // |
75 // This does not remove attachments from the server. | 76 // This does not remove attachments from the server. |
76 // | 77 // |
77 // |callback| will be invoked when finished. Attempting to drop an attachment | 78 // |callback| will be invoked when finished. Attempting to drop an attachment |
78 // that does not exist is not an error. If any of the existing attachment | 79 // that does not exist is not an error. If any of the existing attachment |
79 // could not be dropped, |callback|'s Result will be UNSPECIFIED_ERROR. When | 80 // could not be dropped, |callback|'s Result will be UNSPECIFIED_ERROR. When |
80 // this happens, some or none of the attachments may have been dropped | 81 // this happens, some or none of the attachments may have been dropped |
81 // successfully. | 82 // successfully. |
82 virtual void Drop(const AttachmentIdList& ids, | 83 virtual void Drop(const AttachmentIdList& ids, |
83 const DropCallback& callback) = 0; | 84 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(); |
84 | 98 |
85 protected: | 99 protected: |
86 friend class base::RefCounted<AttachmentStore>; | 100 friend class base::RefCountedThreadSafe<AttachmentStore>; |
87 virtual ~AttachmentStore(); | 101 virtual ~AttachmentStore(); |
88 }; | 102 }; |
89 | 103 |
90 } // namespace syncer | 104 } // namespace syncer |
91 | 105 |
92 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ | 106 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ |
OLD | NEW |