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 { |
maniscalco
2014/09/29 20:57:52
Can/should ASB be made SYNC_PRIVATE?
pavely
2014/09/29 23:27:08
It is base class for AttachmentStore which should
maniscalco
2014/09/30 00:26:13
You're right, I agree.
| |
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 device type and AttachmentService | |
maniscalco
2014/09/29 20:57:52
s/device/data/
pavely
2014/09/29 23:27:07
Done.
| |
88 // code. Also contains factory methods for default implementations. | |
89 class SYNC_EXPORT AttachmentStore : public AttachmentStoreBase, | |
90 public base::RefCounted<AttachmentStore> { | |
maniscalco
2014/09/29 20:57:52
I would be inclined to use RefCountedThreadSafe (h
pavely
2014/09/29 23:27:07
Done.
| |
91 public: | |
92 AttachmentStore(); | |
93 | |
94 // Creates an AttachmentStoreProxy backed by in-memory implementation of | |
95 // attachment store. For now frontend lives on the same thread as backend. | |
96 static scoped_refptr<AttachmentStore> CreateInMemoryStore(); | |
84 | 97 |
85 protected: | 98 protected: |
86 friend class base::RefCounted<AttachmentStore>; | 99 friend class base::RefCounted<AttachmentStore>; |
87 virtual ~AttachmentStore(); | 100 virtual ~AttachmentStore(); |
88 }; | 101 }; |
89 | 102 |
90 } // namespace syncer | 103 } // namespace syncer |
91 | 104 |
92 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ | 105 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ |
OLD | NEW |