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 15namespace base { 16class RefCountedMemory; 17} // namespace base 18 19namespace syncer { 20 21class Attachment; 22class 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. 28class SYNC_EXPORT AttachmentStore : public base::RefCounted<AttachmentStore> { 29 public: 30 AttachmentStore(); 31 32 // TODO(maniscalco): Consider udpating Read and Write methods to support 33 // resumable transfers (bug 353292). 34 35 enum Result { 36 SUCCESS, // No error, all completed successfully. 37 UNSPECIFIED_ERROR, // An unspecified error occurred for one or more items. 38 }; 39 40 typedef base::Callback<void(const Result&, 41 scoped_ptr<AttachmentMap>, 42 scoped_ptr<AttachmentIdList>)> 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. AttachmentStore will attempt to 49 // read all attachments specified in ids. If any of the attachments do not 50 // exist or could not be read, |callback|'s Result will be UNSPECIFIED_ERROR. 51 // Callback's AttachmentMap will contain all attachments that were 52 // successfully read, AttachmentIdList will contain attachment ids of 53 // attachments that are unavailable in attachment store, these need to be 54 // downloaded from server. 55 // 56 // Reads on individual attachments are treated atomically; |callback| will not 57 // read only part of an attachment. 58 virtual void Read(const AttachmentIdList& ids, 59 const ReadCallback& callback) = 0; 60 61 // Asynchronously writes |attachments| to the store. 62 // 63 // Will not overwrite stored attachments. Attempting to overwrite an 64 // attachment that already exists is not an error. 65 // 66 // |callback| will be invoked when finished. If any of the attachments could 67 // not be written |callback|'s Result will be UNSPECIFIED_ERROR. When this 68 // happens, some or none of the attachments may have been written 69 // successfully. 70 virtual void Write(const AttachmentList& attachments, 71 const WriteCallback& callback) = 0; 72 73 // Asynchronously drops |attchments| from this store. 74 // 75 // This does not remove attachments from the server. 76 // 77 // |callback| will be invoked when finished. Attempting to drop an attachment 78 // that does not exist is not an error. If any of the existing attachment 79 // could not be dropped, |callback|'s Result will be UNSPECIFIED_ERROR. When 80 // this happens, some or none of the attachments may have been dropped 81 // successfully. 82 virtual void Drop(const AttachmentIdList& ids, 83 const DropCallback& callback) = 0; 84 85 protected: 86 friend class base::RefCounted<AttachmentStore>; 87 virtual ~AttachmentStore(); 88}; 89 90} // namespace syncer 91 92#endif // SYNC_API_ATTACHMENTS_ATTACHMENT_STORE_H_ 93