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 #include "sync/api/attachments/attachment_id.h"
7 #include "base/logging.h"
8 #include "sync/internal_api/public/base/attachment_id_proto.h"
9 #include "sync/protocol/sync.pb.h"
13 void AttachmentId::ImmutableAttachmentIdProtoTraits::InitializeWrapper(
15 *wrapper
= new sync_pb::AttachmentIdProto();
18 void AttachmentId::ImmutableAttachmentIdProtoTraits::DestroyWrapper(
23 const sync_pb::AttachmentIdProto
&
24 AttachmentId::ImmutableAttachmentIdProtoTraits::Unwrap(const Wrapper
& wrapper
) {
28 sync_pb::AttachmentIdProto
*
29 AttachmentId::ImmutableAttachmentIdProtoTraits::UnwrapMutable(
34 void AttachmentId::ImmutableAttachmentIdProtoTraits::Swap(
35 sync_pb::AttachmentIdProto
* t1
,
36 sync_pb::AttachmentIdProto
* t2
) {
40 AttachmentId::~AttachmentId() {}
42 bool AttachmentId::operator==(const AttachmentId
& other
) const {
43 return proto_
.Get().unique_id() == other
.proto_
.Get().unique_id();
46 bool AttachmentId::operator!=(const AttachmentId
& other
) const {
47 return !operator==(other
);
50 bool AttachmentId::operator<(const AttachmentId
& other
) const {
51 return proto_
.Get().unique_id() < other
.proto_
.Get().unique_id();
55 AttachmentId
AttachmentId::Create(size_t size
, uint32_t crc32c
) {
56 sync_pb::AttachmentIdProto proto
= CreateAttachmentIdProto(size
, crc32c
);
57 return AttachmentId(&proto
);
61 AttachmentId
AttachmentId::CreateFromProto(
62 const sync_pb::AttachmentIdProto
& proto
) {
63 sync_pb::AttachmentIdProto
copy_of_proto(proto
);
64 return AttachmentId(©_of_proto
);
67 const sync_pb::AttachmentIdProto
& AttachmentId::GetProto() const {
71 AttachmentId::AttachmentId(sync_pb::AttachmentIdProto
* proto
)
74 size_t AttachmentId::GetSize() const {
75 return proto_
.Get().size_bytes();
78 uint32_t AttachmentId::GetCrc32c() const {
79 return proto_
.Get().crc32c();