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/base/sync_export.h"
14 class RefCountedMemory;
19 } // namespace sync_pb
25 // A place to locally store and access Attachments.
26 class SYNC_EXPORT AttachmentStore {
29 virtual ~AttachmentStore();
31 // TODO(maniscalco): Consider udpating Read and Write methods to support
32 // resumable transfers.
36 NOT_FOUND, // Attachment was not found or does not exist.
37 UNSPECIFIED_ERROR, // An unspecified error occurred.
40 typedef base::Callback<void(const Result&, scoped_ptr<Attachment>)>
42 typedef base::Callback<void(const Result&)> WriteCallback;
43 typedef base::Callback<void(const Result&)> DropCallback;
45 // Asynchronously reads the attachment identified by |id|.
47 // |callback| will be invoked when finished. If the attachment does not exist,
48 // |callback|'s Result will be NOT_FOUND and |callback|'s attachment will be
50 virtual void Read(const sync_pb::AttachmentId& id,
51 const ReadCallback& callback) = 0;
53 // Asynchronously writes |bytes| to the store under the given |id|.
55 // If the store already contains an attachment with |id| it will be
56 // overwritten. |callback| will be invoked when finished.
57 virtual void Write(const sync_pb::AttachmentId& id,
58 const scoped_refptr<base::RefCountedMemory>& bytes,
59 const WriteCallback& callback) = 0;
61 // Asynchronously drops the attchment with the given id from this store.
63 // This does not remove the attachment from the server. |callback| will be
64 // invoked when finished. If the attachment does not exist, |callback|'s
65 // Result will be NOT_FOUND.
66 virtual void Drop(const sync_pb::AttachmentId& id,
67 const DropCallback& callback) = 0;
72 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_