blob: 896ff1fbde1b8bf4ef7237a55149b47f1fadd54d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sync/api/attachments/attachment.h"
#include "base/logging.h"
#include "base/rand_util.h"
namespace syncer {
Attachment::~Attachment() {}
// Static.
scoped_ptr<Attachment> Attachment::Create(
const scoped_refptr<base::RefCountedMemory>& data) {
return CreateWithId(CreateId(), data);
}
// Static.
scoped_ptr<Attachment> Attachment::CreateWithId(
const sync_pb::AttachmentId& id,
const scoped_refptr<base::RefCountedMemory>& data) {
return scoped_ptr<Attachment>(new Attachment(id, data)).Pass();
}
const sync_pb::AttachmentId& Attachment::GetId() const { return id_; }
const scoped_refptr<base::RefCountedMemory>& Attachment::GetData() const {
return data_;
}
Attachment::Attachment(const sync_pb::AttachmentId& id,
const scoped_refptr<base::RefCountedMemory>& data)
: id_(id), data_(data) {
DCHECK(!id.unique_id().empty());
DCHECK(data);
}
// Static.
sync_pb::AttachmentId Attachment::CreateId() {
sync_pb::AttachmentId result;
// Only requirement here is that this id must be globally unique.
// TODO(maniscalco): Consider making this base64 encoded.
result.set_unique_id(base::RandBytesAsString(16));
return result;
}
} // namespace syncer
|