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.
5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_
6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "sync/api/attachments/attachment.h"
12 #include "sync/api/attachments/attachment_id.h"
13 #include "sync/base/sync_export.h"
16 class RefCountedMemory;
24 // A place to locally store and access Attachments.
26 // Destroying this object does not necessarily cancel outstanding async
27 // operations. If you need cancel like semantics, use WeakPtr in the callbacks.
28 class SYNC_EXPORT AttachmentStore {
31 virtual ~AttachmentStore();
33 // TODO(maniscalco): Consider udpating Read and Write methods to support
34 // resumable transfers (bug 353292).
37 SUCCESS, // No error, all completed successfully.
38 UNSPECIFIED_ERROR, // An unspecified error occurred for one or more items.
41 typedef base::Callback<void(const Result&, scoped_ptr<AttachmentMap>)>
43 typedef base::Callback<void(const Result&)> WriteCallback;
44 typedef base::Callback<void(const Result&)> DropCallback;
46 // Asynchronously reads the attachments identified by |ids|.
48 // |callback| will be invoked when finished. If any of the attachments do not
49 // exist or could not be read, |callback|'s Result will be UNSPECIFIED_ERROR
50 // and |callback| may receive a partial result. That is, AttachmentMap may be
51 // empty or may contain the attachments that were read successfully.
53 // Reads on individual attachments are treated atomically; |callback| will not
54 // read only part of an attachment.
55 virtual void Read(const AttachmentIdList& ids,
56 const ReadCallback& callback) = 0;
58 // Asynchronously writes |attachments| to the store.
60 // Will not overwrite stored attachments. Attempting to overwrite an
61 // attachment that already exists is not an error.
63 // |callback| will be invoked when finished. If any of the attachments could
64 // not be written |callback|'s Result will be UNSPECIFIED_ERROR. When this
65 // happens, some or none of the attachments may have been written
67 virtual void Write(const AttachmentList& attachments,
68 const WriteCallback& callback) = 0;
70 // Asynchronously drops |attchments| from this store.
72 // This does not remove attachments from the server.
74 // |callback| will be invoked when finished. Attempting to drop an attachment
75 // that does not exist is not an error. If any of the existing attachment
76 // could not be dropped, |callback|'s Result will be UNSPECIFIED_ERROR. When
77 // this happens, some or none of the attachments may have been dropped
79 virtual void Drop(const AttachmentIdList& ids,
80 const DropCallback& callback) = 0;
85 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_