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