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_ID_H_
6 #define SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_
12 #include "sync/base/sync_export.h"
13 #include "sync/internal_api/public/util/immutable.h"
16 class AttachmentIdProto
;
17 } // namespace sync_pb
21 // Uniquely identifies an attachment.
23 // Two attachments with equal (operator==) AttachmentIds are considered
25 class SYNC_EXPORT AttachmentId
{
29 // Default copy and assignment are welcome.
31 bool operator==(const AttachmentId
& other
) const;
33 bool operator!=(const AttachmentId
& other
) const;
35 // Needed for using AttachmentId as key in std::map.
36 bool operator<(const AttachmentId
& other
) const;
38 // Creates a unique id for an attachment.
40 // |size| is the attachment's size in bytes.
42 // |crc32c| is the attachment's crc32c.
43 static AttachmentId
Create(size_t size
, uint32_t crc32c
);
45 // Creates an attachment id from an initialized proto.
46 static AttachmentId
CreateFromProto(const sync_pb::AttachmentIdProto
& proto
);
48 const sync_pb::AttachmentIdProto
& GetProto() const;
50 // Returns the size (in bytes) the attachment.
51 size_t GetSize() const;
53 // Returns the crc32c the attachment.
54 uint32_t GetCrc32c() const;
57 // Necessary since we forward-declare sync_pb::AttachmentIdProto; see comments
59 struct SYNC_EXPORT ImmutableAttachmentIdProtoTraits
{
60 typedef sync_pb::AttachmentIdProto
* Wrapper
;
61 static void InitializeWrapper(Wrapper
* wrapper
);
62 static void DestroyWrapper(Wrapper
* wrapper
);
63 static const sync_pb::AttachmentIdProto
& Unwrap(const Wrapper
& wrapper
);
64 static sync_pb::AttachmentIdProto
* UnwrapMutable(Wrapper
* wrapper
);
65 static void Swap(sync_pb::AttachmentIdProto
* t1
,
66 sync_pb::AttachmentIdProto
* t2
);
69 typedef Immutable
<sync_pb::AttachmentIdProto
,
70 ImmutableAttachmentIdProtoTraits
>
71 ImmutableAttachmentIdProto
;
73 ImmutableAttachmentIdProto proto_
;
75 AttachmentId(sync_pb::AttachmentIdProto
* proto
);
78 // All public interfaces use AttachmentIdList. AttachmentIdSet is used in
79 // implementations of algorithms where set properties are needed.
80 typedef std::vector
<AttachmentId
> AttachmentIdList
;
81 typedef std::set
<AttachmentId
> AttachmentIdSet
;
85 #endif // SYNC_API_ATTACHMENTS_ATTACHMENT_ID_H_