Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / sync / api / sync_attachment.cc
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 #include "sync/api/sync_attachment.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ref_counted_memory.h"
9 #include "base/rand_util.h"
10
11 namespace syncer {
12
13 SyncAttachment::~SyncAttachment() {}
14
15 // Static.
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);
22 }
23
24 // Static.
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();
29 }
30
31 const sync_pb::SyncAttachmentId& SyncAttachment::GetId() const { return id_; }
32
33 const scoped_refptr<base::RefCountedMemory>& SyncAttachment::GetBytes() const {
34   return bytes_;
35 }
36
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());
42   DCHECK(bytes);
43 }
44
45 }  // namespace syncer