| OLD | NEW |
| 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_id.h" | 5 #include "sync/api/attachments/attachment_id.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "sync/internal_api/public/base/attachment_id_proto.h" | 8 #include "base/rand_util.h" |
| 9 #include "sync/protocol/sync.pb.h" | 9 #include "sync/protocol/sync.pb.h" |
| 10 | 10 |
| 11 namespace syncer { | 11 namespace syncer { |
| 12 | 12 |
| 13 void AttachmentId::ImmutableAttachmentIdProtoTraits::InitializeWrapper( | 13 void AttachmentId::ImmutableAttachmentIdProtoTraits::InitializeWrapper( |
| 14 Wrapper* wrapper) { | 14 Wrapper* wrapper) { |
| 15 *wrapper = new sync_pb::AttachmentIdProto(); | 15 *wrapper = new sync_pb::AttachmentIdProto(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 void AttachmentId::ImmutableAttachmentIdProtoTraits::DestroyWrapper( | 18 void AttachmentId::ImmutableAttachmentIdProtoTraits::DestroyWrapper( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 46 bool AttachmentId::operator!=(const AttachmentId& other) const { | 46 bool AttachmentId::operator!=(const AttachmentId& other) const { |
| 47 return !operator==(other); | 47 return !operator==(other); |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool AttachmentId::operator<(const AttachmentId& other) const { | 50 bool AttachmentId::operator<(const AttachmentId& other) const { |
| 51 return proto_.Get().unique_id() < other.proto_.Get().unique_id(); | 51 return proto_.Get().unique_id() < other.proto_.Get().unique_id(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Static. | 54 // Static. |
| 55 AttachmentId AttachmentId::Create() { | 55 AttachmentId AttachmentId::Create() { |
| 56 sync_pb::AttachmentIdProto proto = CreateAttachmentIdProto(); | 56 // Only requirement here is that this id must be globally unique. |
| 57 // TODO(maniscalco): Consider making this base64 encoded. |
| 58 sync_pb::AttachmentIdProto proto; |
| 59 proto.set_unique_id(base::RandBytesAsString(16)); |
| 57 return AttachmentId(&proto); | 60 return AttachmentId(&proto); |
| 58 } | 61 } |
| 59 | 62 |
| 60 // Static. | 63 // Static. |
| 61 AttachmentId AttachmentId::CreateFromProto( | 64 AttachmentId AttachmentId::CreateFromProto( |
| 62 const sync_pb::AttachmentIdProto& proto) { | 65 const sync_pb::AttachmentIdProto& proto) { |
| 63 sync_pb::AttachmentIdProto copy_of_proto(proto); | 66 sync_pb::AttachmentIdProto copy_of_proto(proto); |
| 64 return AttachmentId(©_of_proto); | 67 return AttachmentId(©_of_proto); |
| 65 } | 68 } |
| 66 | 69 |
| 67 const sync_pb::AttachmentIdProto& AttachmentId::GetProto() const { | 70 const sync_pb::AttachmentIdProto& AttachmentId::GetProto() const { |
| 68 return proto_.Get(); | 71 return proto_.Get(); |
| 69 } | 72 } |
| 70 | 73 |
| 71 AttachmentId::AttachmentId(sync_pb::AttachmentIdProto* proto) | 74 AttachmentId::AttachmentId(sync_pb::AttachmentIdProto* proto) |
| 72 : proto_(proto) {} | 75 : proto_(proto) {} |
| 73 | 76 |
| 74 } // namespace syncer | 77 } // namespace syncer |
| OLD | NEW |