| OLD | NEW |
| (Empty) |
| 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 COMPONENTS_SYNC_API_ATTACHMENTS_ATTACHMENT_H_ | |
| 6 #define COMPONENTS_SYNC_API_ATTACHMENTS_ATTACHMENT_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <memory> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/memory/ref_counted_memory.h" | |
| 16 #include "components/sync/api/attachments/attachment_id.h" | |
| 17 | |
| 18 namespace syncer { | |
| 19 | |
| 20 // A blob of in-memory data attached to a sync item. | |
| 21 // | |
| 22 // While Attachment objects themselves aren't immutable (they are assignable) | |
| 23 // the data they wrap is immutable. | |
| 24 // | |
| 25 // It is cheap to copy Attachments. Feel free to store and return by value. | |
| 26 class Attachment { | |
| 27 public: | |
| 28 Attachment(const Attachment& other); | |
| 29 ~Attachment(); | |
| 30 | |
| 31 // Default copy and assignment are welcome. | |
| 32 | |
| 33 // Creates an attachment with a unique id and the supplied data. | |
| 34 // | |
| 35 // Used when creating a brand new attachment. | |
| 36 static Attachment Create(const scoped_refptr<base::RefCountedMemory>& data); | |
| 37 | |
| 38 // Creates an attachment with the supplied id and data. | |
| 39 // | |
| 40 // Used when you want to recreate a specific attachment. E.g. creating a local | |
| 41 // copy of an attachment that already exists on the sync server. | |
| 42 static Attachment CreateFromParts( | |
| 43 const AttachmentId& id, | |
| 44 const scoped_refptr<base::RefCountedMemory>& data); | |
| 45 | |
| 46 // Returns this attachment's id. | |
| 47 const AttachmentId& GetId() const; | |
| 48 | |
| 49 // Returns this attachment's data. | |
| 50 const scoped_refptr<base::RefCountedMemory>& GetData() const; | |
| 51 | |
| 52 // Returns precomputed crc32c hash of data. In ideal case this hash is | |
| 53 // computed when attachment is first created. It is then passed around through | |
| 54 // local attachment store and attachment server. Crc is verified when | |
| 55 // attachment is downloaded from server or loaded from local storage. | |
| 56 uint32_t GetCrc32c() const; | |
| 57 | |
| 58 private: | |
| 59 AttachmentId id_; | |
| 60 scoped_refptr<base::RefCountedMemory> data_; | |
| 61 | |
| 62 Attachment(const AttachmentId& id, | |
| 63 const scoped_refptr<base::RefCountedMemory>& data); | |
| 64 }; | |
| 65 | |
| 66 typedef std::vector<Attachment> AttachmentList; | |
| 67 typedef std::map<AttachmentId, Attachment> AttachmentMap; | |
| 68 | |
| 69 } // namespace syncer | |
| 70 | |
| 71 #endif // COMPONENTS_SYNC_API_ATTACHMENTS_ATTACHMENT_H_ | |
| OLD | NEW |