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_ID_H_ | |
6 #define COMPONENTS_SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include <set> | |
12 #include <string> | |
13 #include <vector> | |
14 | |
15 #include "components/sync/base/immutable.h" | |
16 | |
17 namespace sync_pb { | |
18 class AttachmentIdProto; | |
19 } // namespace sync_pb | |
20 | |
21 namespace syncer { | |
22 | |
23 // Uniquely identifies an attachment. | |
24 // | |
25 // Two attachments with equal (operator==) AttachmentIds are considered | |
26 // equivalent. | |
27 class AttachmentId { | |
28 public: | |
29 AttachmentId(const AttachmentId& other); | |
30 ~AttachmentId(); | |
31 | |
32 // Default copy and assignment are welcome. | |
33 | |
34 bool operator==(const AttachmentId& other) const; | |
35 | |
36 bool operator!=(const AttachmentId& other) const; | |
37 | |
38 // Needed for using AttachmentId as key in std::map. | |
39 bool operator<(const AttachmentId& other) const; | |
40 | |
41 // Creates a unique id for an attachment. | |
42 // | |
43 // |size| is the attachment's size in bytes. | |
44 // | |
45 // |crc32c| is the attachment's crc32c. | |
46 static AttachmentId Create(size_t size, uint32_t crc32c); | |
47 | |
48 // Creates an attachment id from an initialized proto. | |
49 static AttachmentId CreateFromProto(const sync_pb::AttachmentIdProto& proto); | |
50 | |
51 const sync_pb::AttachmentIdProto& GetProto() const; | |
52 | |
53 // Returns the size (in bytes) the attachment. | |
54 size_t GetSize() const; | |
55 | |
56 // Returns the crc32c the attachment. | |
57 uint32_t GetCrc32c() const; | |
58 | |
59 private: | |
60 // Necessary since we forward-declare sync_pb::AttachmentIdProto; see comments | |
61 // in immutable.h. | |
62 struct ImmutableAttachmentIdProtoTraits { | |
63 typedef sync_pb::AttachmentIdProto* Wrapper; | |
64 static void InitializeWrapper(Wrapper* wrapper); | |
65 static void DestroyWrapper(Wrapper* wrapper); | |
66 static const sync_pb::AttachmentIdProto& Unwrap(const Wrapper& wrapper); | |
67 static sync_pb::AttachmentIdProto* UnwrapMutable(Wrapper* wrapper); | |
68 static void Swap(sync_pb::AttachmentIdProto* t1, | |
69 sync_pb::AttachmentIdProto* t2); | |
70 }; | |
71 | |
72 typedef Immutable<sync_pb::AttachmentIdProto, | |
73 ImmutableAttachmentIdProtoTraits> | |
74 ImmutableAttachmentIdProto; | |
75 | |
76 ImmutableAttachmentIdProto proto_; | |
77 | |
78 explicit AttachmentId(sync_pb::AttachmentIdProto* proto); | |
79 }; | |
80 | |
81 // All public interfaces use AttachmentIdList. AttachmentIdSet is used in | |
82 // implementations of algorithms where set properties are needed. | |
83 typedef std::vector<AttachmentId> AttachmentIdList; | |
84 typedef std::set<AttachmentId> AttachmentIdSet; | |
85 | |
86 } // namespace syncer | |
87 | |
88 #endif // COMPONENTS_SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_ | |
OLD | NEW |