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/sync_attachment.h"
7 #include "base/logging.h"
8 #include "base/memory/ref_counted_memory.h"
9 #include "base/rand_util.h"
13 SyncAttachment::~SyncAttachment() {}
16 scoped_ptr<SyncAttachment> SyncAttachment::Create(
17 const scoped_refptr<base::RefCountedMemory>& bytes) {
18 sync_pb::SyncAttachmentId id;
19 // Only requirement here is that this id must be globally unique.
20 id.set_unique_id(base::RandBytesAsString(16));
21 return CreateWithId(id, bytes);
25 scoped_ptr<SyncAttachment> SyncAttachment::CreateWithId(
26 const sync_pb::SyncAttachmentId& id,
27 const scoped_refptr<base::RefCountedMemory>& bytes) {
28 return scoped_ptr<SyncAttachment>(new SyncAttachment(id, bytes)).Pass();
31 const sync_pb::SyncAttachmentId& SyncAttachment::GetId() const { return id_; }
33 const scoped_refptr<base::RefCountedMemory>& SyncAttachment::GetBytes() const {
37 SyncAttachment::SyncAttachment(
38 const sync_pb::SyncAttachmentId& id,
39 const scoped_refptr<base::RefCountedMemory>& bytes)
40 : id_(id), bytes_(bytes) {
41 DCHECK(!id.unique_id().empty());