attachment_store.h revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
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
13namespace base {
14class RefCountedMemory;
15}  // namespace base
16
17namespace syncer {
18
19class Attachment;
20class AttachmentId;
21
22// A place to locally store and access Attachments.
23class SYNC_EXPORT AttachmentStore {
24 public:
25  AttachmentStore();
26  virtual ~AttachmentStore();
27
28  // TODO(maniscalco): Consider udpating Read and Write methods to support
29  // resumable transfers.
30
31  enum Result {
32    SUCCESS,            // No error.
33    NOT_FOUND,          // Attachment was not found or does not exist.
34    UNSPECIFIED_ERROR,  // An unspecified error occurred.
35  };
36
37  typedef base::Callback<void(const Result&, scoped_ptr<Attachment>)>
38      ReadCallback;
39  typedef base::Callback<void(const Result&, const AttachmentId& id)>
40      WriteCallback;
41  typedef base::Callback<void(const Result&)> DropCallback;
42
43  // Asynchronously reads the attachment identified by |id|.
44  //
45  // |callback| will be invoked when finished. If the attachment does not exist,
46  // |callback|'s Result will be NOT_FOUND and |callback|'s attachment will be
47  // null.
48  virtual void Read(const AttachmentId& id, const ReadCallback& callback) = 0;
49
50  // Asynchronously writes |bytes| to the store.
51  //
52  // |callback| will be invoked when finished.
53  virtual void Write(const scoped_refptr<base::RefCountedMemory>& bytes,
54                     const WriteCallback& callback) = 0;
55
56  // Asynchronously drops the attchment with the given id from this store.
57  //
58  // This does not remove the attachment from the server. |callback| will be
59  // invoked when finished. If the attachment does not exist, |callback|'s
60  // Result will be NOT_FOUND.
61  virtual void Drop(const AttachmentId& id, const DropCallback& callback) = 0;
62};
63
64}  // namespace syncer
65
66#endif  // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_
67