| 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 #include "sync/api/attachments/attachment.h" | 5 #include "sync/api/attachments/attachment.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "sync/internal_api/public/attachments/attachment_util.h" | 8 #include "sync/internal_api/public/attachments/attachment_util.h" |
| 9 | 9 |
| 10 namespace syncer { | 10 namespace syncer { |
| 11 | 11 |
| 12 Attachment::~Attachment() {} | 12 Attachment::~Attachment() {} |
| 13 | 13 |
| 14 // Static. | 14 // Static. |
| 15 Attachment Attachment::Create( | 15 Attachment Attachment::Create( |
| 16 const scoped_refptr<base::RefCountedMemory>& data) { | 16 const scoped_refptr<base::RefCountedMemory>& data) { |
| 17 uint32_t crc32c = ComputeCrc32c(data); | 17 uint32_t crc32c = ComputeCrc32c(data); |
| 18 return CreateFromParts(AttachmentId::Create(), data, crc32c); | 18 return CreateFromParts(AttachmentId::Create(data->size(), crc32c), data); |
| 19 } | 19 } |
| 20 | 20 |
| 21 // Static. | 21 // Static. |
| 22 Attachment Attachment::CreateFromParts( | 22 Attachment Attachment::CreateFromParts( |
| 23 const AttachmentId& id, | 23 const AttachmentId& id, |
| 24 const scoped_refptr<base::RefCountedMemory>& data, | 24 const scoped_refptr<base::RefCountedMemory>& data) { |
| 25 uint32_t crc32c) { | 25 return Attachment(id, data); |
| 26 return Attachment(id, data, crc32c); | |
| 27 } | 26 } |
| 28 | 27 |
| 29 const AttachmentId& Attachment::GetId() const { return id_; } | 28 const AttachmentId& Attachment::GetId() const { return id_; } |
| 30 | 29 |
| 31 const scoped_refptr<base::RefCountedMemory>& Attachment::GetData() const { | 30 const scoped_refptr<base::RefCountedMemory>& Attachment::GetData() const { |
| 32 return data_; | 31 return data_; |
| 33 } | 32 } |
| 34 | 33 |
| 35 uint32_t Attachment::GetCrc32c() const { return crc32c_; } | 34 uint32_t Attachment::GetCrc32c() const { |
| 35 return id_.GetCrc32c(); |
| 36 } |
| 36 | 37 |
| 37 Attachment::Attachment(const AttachmentId& id, | 38 Attachment::Attachment(const AttachmentId& id, |
| 38 const scoped_refptr<base::RefCountedMemory>& data, | 39 const scoped_refptr<base::RefCountedMemory>& data) |
| 39 uint32_t crc32c) | 40 : id_(id), data_(data) { |
| 40 : id_(id), data_(data), crc32c_(crc32c) { | 41 DCHECK_EQ(id.GetSize(), data->size()); |
| 41 DCHECK(data.get()); | 42 DCHECK(data.get()); |
| 42 } | 43 } |
| 43 | 44 |
| 44 } // namespace syncer | 45 } // namespace syncer |
| OLD | NEW |