Upstream version 7.36.149.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/api/attachments/attachment.h"
12 #include "sync/api/attachments/attachment_id.h"
13 #include "sync/base/sync_export.h"
14
15 namespace base {
16 class RefCountedMemory;
17 }  // namespace base
18
19 namespace syncer {
20
21 class Attachment;
22 class AttachmentId;
23
24 // A place to locally store and access Attachments.
25 //
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 {
29  public:
30   AttachmentStore();
31   virtual ~AttachmentStore();
32
33   // TODO(maniscalco): Consider udpating Read and Write methods to support
34   // resumable transfers (bug 353292).
35
36   enum Result {
37     SUCCESS,            // No error, all completed successfully.
38     UNSPECIFIED_ERROR,  // An unspecified error occurred for one or more items.
39   };
40
41   typedef base::Callback<void(const Result&, scoped_ptr<AttachmentMap>)>
42       ReadCallback;
43   typedef base::Callback<void(const Result&)> WriteCallback;
44   typedef base::Callback<void(const Result&)> DropCallback;
45
46   // Asynchronously reads the attachments identified by |ids|.
47   //
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.
52   //
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;
57
58   // Asynchronously writes |attachments| to the store.
59   //
60   // Will not overwrite stored attachments. Attempting to overwrite an
61   // attachment that already exists is not an error.
62   //
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
66   // successfully.
67   virtual void Write(const AttachmentList& attachments,
68                      const WriteCallback& callback) = 0;
69
70   // Asynchronously drops |attchments| from this store.
71   //
72   // This does not remove attachments from the server.
73   //
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
78   // successfully.
79   virtual void Drop(const AttachmentIdList& ids,
80                     const DropCallback& callback) = 0;
81 };
82
83 }  // namespace syncer
84
85 #endif  // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_