summaryrefslogtreecommitdiffstats
path: root/sync/api/sync_attachment.cc
blob: a214307ddc91c44e5fec243468428d165802924b (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
// 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/sync_attachment.h"

#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/rand_util.h"

namespace syncer {

SyncAttachment::~SyncAttachment() {}

// Static.
scoped_ptr<SyncAttachment> SyncAttachment::Create(
    const scoped_refptr<base::RefCountedMemory>& bytes) {
  sync_pb::SyncAttachmentId id;
  // Only requirement here is that this id must be globally unique.
  id.set_unique_id(base::RandBytesAsString(16));
  return CreateWithId(id, bytes);
}

// Static.
scoped_ptr<SyncAttachment> SyncAttachment::CreateWithId(
    const sync_pb::SyncAttachmentId& id,
    const scoped_refptr<base::RefCountedMemory>& bytes) {
  return scoped_ptr<SyncAttachment>(new SyncAttachment(id, bytes)).Pass();
}

const sync_pb::SyncAttachmentId& SyncAttachment::GetId() const { return id_; }

const scoped_refptr<base::RefCountedMemory>& SyncAttachment::GetBytes() const {
  return bytes_;
}

SyncAttachment::SyncAttachment(
    const sync_pb::SyncAttachmentId& id,
    const scoped_refptr<base::RefCountedMemory>& bytes)
    : id_(id), bytes_(bytes) {
  DCHECK(!id.unique_id().empty());
  DCHECK(bytes);
}

}  // namespace syncer