| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | 5 #ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ |
| 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | 6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 // Default copy and assignment are welcome. | 29 // Default copy and assignment are welcome. |
| 30 | 30 |
| 31 bool operator==(const AttachmentId& other) const; | 31 bool operator==(const AttachmentId& other) const; |
| 32 | 32 |
| 33 bool operator!=(const AttachmentId& other) const; | 33 bool operator!=(const AttachmentId& other) const; |
| 34 | 34 |
| 35 // Needed for using AttachmentId as key in std::map. | 35 // Needed for using AttachmentId as key in std::map. |
| 36 bool operator<(const AttachmentId& other) const; | 36 bool operator<(const AttachmentId& other) const; |
| 37 | 37 |
| 38 // Creates a unique attachment id. | 38 // Creates a unique id for an attachment. |
| 39 static AttachmentId Create(); | 39 // |
| 40 // |size| is the attachment's size in bytes. |
| 41 // |
| 42 // |crc32c| is the attachment's crc32c. |
| 43 static AttachmentId Create(size_t size, uint32_t crc32c); |
| 40 | 44 |
| 41 // Creates an attachment id from an initialized proto. | 45 // Creates an attachment id from an initialized proto. |
| 42 static AttachmentId CreateFromProto(const sync_pb::AttachmentIdProto& proto); | 46 static AttachmentId CreateFromProto(const sync_pb::AttachmentIdProto& proto); |
| 43 | 47 |
| 44 const sync_pb::AttachmentIdProto& GetProto() const; | 48 const sync_pb::AttachmentIdProto& GetProto() const; |
| 45 | 49 |
| 50 // Returns the size (in bytes) the attachment. |
| 51 size_t GetSize() const; |
| 52 |
| 53 // Returns the crc32c the attachment. |
| 54 uint32_t GetCrc32c() const; |
| 55 |
| 46 private: | 56 private: |
| 47 // Necessary since we forward-declare sync_pb::AttachmentIdProto; see comments | 57 // Necessary since we forward-declare sync_pb::AttachmentIdProto; see comments |
| 48 // in immutable.h. | 58 // in immutable.h. |
| 49 struct SYNC_EXPORT ImmutableAttachmentIdProtoTraits { | 59 struct SYNC_EXPORT ImmutableAttachmentIdProtoTraits { |
| 50 typedef sync_pb::AttachmentIdProto* Wrapper; | 60 typedef sync_pb::AttachmentIdProto* Wrapper; |
| 51 static void InitializeWrapper(Wrapper* wrapper); | 61 static void InitializeWrapper(Wrapper* wrapper); |
| 52 static void DestroyWrapper(Wrapper* wrapper); | 62 static void DestroyWrapper(Wrapper* wrapper); |
| 53 static const sync_pb::AttachmentIdProto& Unwrap(const Wrapper& wrapper); | 63 static const sync_pb::AttachmentIdProto& Unwrap(const Wrapper& wrapper); |
| 54 static sync_pb::AttachmentIdProto* UnwrapMutable(Wrapper* wrapper); | 64 static sync_pb::AttachmentIdProto* UnwrapMutable(Wrapper* wrapper); |
| 55 static void Swap(sync_pb::AttachmentIdProto* t1, | 65 static void Swap(sync_pb::AttachmentIdProto* t1, |
| 56 sync_pb::AttachmentIdProto* t2); | 66 sync_pb::AttachmentIdProto* t2); |
| 57 }; | 67 }; |
| 58 | 68 |
| 59 typedef Immutable<sync_pb::AttachmentIdProto, | 69 typedef Immutable<sync_pb::AttachmentIdProto, |
| 60 ImmutableAttachmentIdProtoTraits> | 70 ImmutableAttachmentIdProtoTraits> |
| 61 ImmutableAttachmentIdProto; | 71 ImmutableAttachmentIdProto; |
| 62 | 72 |
| 63 ImmutableAttachmentIdProto proto_; | 73 ImmutableAttachmentIdProto proto_; |
| 64 | 74 |
| 65 AttachmentId(sync_pb::AttachmentIdProto* proto); | 75 AttachmentId(sync_pb::AttachmentIdProto* proto); |
| 66 }; | 76 }; |
| 67 | 77 |
| 68 typedef std::vector<AttachmentId> AttachmentIdList; | 78 typedef std::vector<AttachmentId> AttachmentIdList; |
| 69 typedef std::set<AttachmentId> AttachmentIdSet; | 79 typedef std::set<AttachmentId> AttachmentIdSet; |
| 70 | 80 |
| 71 } // namespace syncer | 81 } // namespace syncer |
| 72 | 82 |
| 73 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | 83 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ |
| OLD | NEW |