Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: sync/api/attachments/attachment.cc

Issue 187303006: Update sync API to support attachments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@attachmentapi
Patch Set: Pull in upstream changes. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/rand_util.h" 8 #include "base/rand_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 scoped_ptr<Attachment> Attachment::Create( 15 sync_pb::AttachmentId Attachment::CreateId() {
16 sync_pb::AttachmentId result;
17 // Only requirement here is that this id must be globally unique.
18 // TODO(maniscalco): Consider making this base64 encoded.
19 result.set_unique_id(base::RandBytesAsString(16));
20 return result;
21 }
22
23 // Static.
24 Attachment Attachment::Create(
16 const scoped_refptr<base::RefCountedMemory>& data) { 25 const scoped_refptr<base::RefCountedMemory>& data) {
17 return CreateWithId(CreateId(), data); 26 return CreateWithId(CreateId(), data);
18 } 27 }
19 28
20 // Static. 29 // Static.
21 scoped_ptr<Attachment> Attachment::CreateWithId( 30 Attachment Attachment::CreateWithId(
22 const sync_pb::AttachmentId& id, 31 const sync_pb::AttachmentId& id,
23 const scoped_refptr<base::RefCountedMemory>& data) { 32 const scoped_refptr<base::RefCountedMemory>& data) {
24 return scoped_ptr<Attachment>(new Attachment(id, data)).Pass(); 33 return Attachment(id, data);
25 } 34 }
26 35
27 const sync_pb::AttachmentId& Attachment::GetId() const { return id_; } 36 const sync_pb::AttachmentId& Attachment::GetId() const { return id_; }
28 37
29 const scoped_refptr<base::RefCountedMemory>& Attachment::GetData() const { 38 const scoped_refptr<base::RefCountedMemory>& Attachment::GetData() const {
30 return data_; 39 return data_;
31 } 40 }
32 41
33 Attachment::Attachment(const sync_pb::AttachmentId& id, 42 Attachment::Attachment(const sync_pb::AttachmentId& id,
34 const scoped_refptr<base::RefCountedMemory>& data) 43 const scoped_refptr<base::RefCountedMemory>& data)
35 : id_(id), data_(data) { 44 : id_(id), data_(data) {
36 DCHECK(!id.unique_id().empty()); 45 DCHECK(!id.unique_id().empty());
37 DCHECK(data); 46 DCHECK(data);
38 } 47 }
39 48
40 // Static.
41 sync_pb::AttachmentId Attachment::CreateId() {
42 sync_pb::AttachmentId result;
43 // Only requirement here is that this id must be globally unique.
44 // TODO(maniscalco): Consider making this base64 encoded.
45 result.set_unique_id(base::RandBytesAsString(16));
46 return result;
47 }
48
49 } // namespace syncer 49 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698