Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / sync / api / attachments / attachment_store.h
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.
4
5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_
6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_
7
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"
12
13 namespace base {
14 class RefCountedMemory;
15 }  // namespace base
16
17 namespace sync_pb {
18 class AttachmentId;
19 }  // namespace sync_pb
20
21 namespace syncer {
22
23 class Attachment;
24
25 // A place to locally store and access Attachments.
26 class SYNC_EXPORT AttachmentStore {
27  public:
28   AttachmentStore();
29   virtual ~AttachmentStore();
30
31   // TODO(maniscalco): Consider udpating Read and Write methods to support
32   // resumable transfers.
33
34   enum Result {
35     SUCCESS,            // No error.
36     NOT_FOUND,          // Attachment was not found or does not exist.
37     UNSPECIFIED_ERROR,  // An unspecified error occurred.
38   };
39
40   typedef base::Callback<void(const Result&, scoped_ptr<Attachment>)>
41       ReadCallback;
42   typedef base::Callback<void(const Result&)> WriteCallback;
43   typedef base::Callback<void(const Result&)> DropCallback;
44
45   // Asynchronously reads the attachment identified by |id|.
46   //
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
49   // null.
50   virtual void Read(const sync_pb::AttachmentId& id,
51                     const ReadCallback& callback) = 0;
52
53   // Asynchronously writes |bytes| to the store under the given |id|.
54   //
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;
60
61   // Asynchronously drops the attchment with the given id from this store.
62   //
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;
68 };
69
70 }  // namespace syncer
71
72 #endif  // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_