| 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 "components/sync/engine_impl/loopback_server/persistent_tombstone_entit
y.h" | 5 #include "components/sync/engine_impl/loopback_server/persistent_tombstone_entit
y.h" |
| 6 | 6 |
| 7 using std::string; | 7 using std::string; |
| 8 | 8 |
| 9 using syncer::ModelType; | 9 using syncer::ModelType; |
| 10 | 10 |
| 11 namespace syncer { | 11 namespace syncer { |
| 12 | 12 |
| 13 PersistentTombstoneEntity::~PersistentTombstoneEntity() {} | 13 PersistentTombstoneEntity::~PersistentTombstoneEntity() {} |
| 14 | 14 |
| 15 // static | 15 // static |
| 16 std::unique_ptr<LoopbackServerEntity> | 16 std::unique_ptr<LoopbackServerEntity> PersistentTombstoneEntity::Create( |
| 17 PersistentTombstoneEntity::CreateFromEntity(const sync_pb::SyncEntity& entity) { | 17 const sync_pb::SyncEntity& entity) { |
| 18 const ModelType model_type = GetModelTypeFromId(entity.id_string()); | 18 const ModelType model_type = GetModelTypeFromId(entity.id_string()); |
| 19 CHECK_NE(model_type, syncer::UNSPECIFIED) << "Invalid ID was given: " | 19 CHECK_NE(model_type, syncer::UNSPECIFIED) << "Invalid ID was given: " |
| 20 << entity.id_string(); | 20 << entity.id_string(); |
| 21 return std::unique_ptr<LoopbackServerEntity>(new PersistentTombstoneEntity( | 21 return std::unique_ptr<LoopbackServerEntity>(new PersistentTombstoneEntity( |
| 22 entity.id_string(), entity.version(), model_type, | 22 entity.id_string(), entity.version(), model_type)); |
| 23 entity.client_defined_unique_tag())); | |
| 24 } | |
| 25 | |
| 26 // static | |
| 27 std::unique_ptr<LoopbackServerEntity> PersistentTombstoneEntity::CreateNew( | |
| 28 const std::string& id, | |
| 29 const std::string& client_defined_unique_tag) { | |
| 30 const ModelType model_type = GetModelTypeFromId(id); | |
| 31 CHECK_NE(model_type, syncer::UNSPECIFIED) << "Invalid ID was given: " << id; | |
| 32 return std::unique_ptr<LoopbackServerEntity>(new PersistentTombstoneEntity( | |
| 33 id, 0, model_type, client_defined_unique_tag)); | |
| 34 } | 23 } |
| 35 | 24 |
| 36 PersistentTombstoneEntity::PersistentTombstoneEntity( | 25 PersistentTombstoneEntity::PersistentTombstoneEntity( |
| 37 const string& id, | 26 const string& id, |
| 38 int64_t version, | 27 int64_t version, |
| 39 const ModelType& model_type, | 28 const ModelType& model_type) |
| 40 const std::string& client_defined_unique_tag) | 29 : LoopbackServerEntity(id, model_type, version, string()) { |
| 41 : LoopbackServerEntity(id, model_type, version, string()), | |
| 42 client_defined_unique_tag_(client_defined_unique_tag) { | |
| 43 sync_pb::EntitySpecifics specifics; | 30 sync_pb::EntitySpecifics specifics; |
| 44 AddDefaultFieldValue(model_type, &specifics); | 31 AddDefaultFieldValue(model_type, &specifics); |
| 45 SetSpecifics(specifics); | 32 SetSpecifics(specifics); |
| 46 } | 33 } |
| 47 | 34 |
| 48 bool PersistentTombstoneEntity::RequiresParentId() const { | 35 bool PersistentTombstoneEntity::RequiresParentId() const { |
| 49 return false; | 36 return false; |
| 50 } | 37 } |
| 51 | 38 |
| 52 string PersistentTombstoneEntity::GetParentId() const { | 39 string PersistentTombstoneEntity::GetParentId() const { |
| 53 return string(); | 40 return string(); |
| 54 } | 41 } |
| 55 | 42 |
| 56 void PersistentTombstoneEntity::SerializeAsProto( | 43 void PersistentTombstoneEntity::SerializeAsProto( |
| 57 sync_pb::SyncEntity* proto) const { | 44 sync_pb::SyncEntity* proto) const { |
| 58 LoopbackServerEntity::SerializeBaseProtoFields(proto); | 45 LoopbackServerEntity::SerializeBaseProtoFields(proto); |
| 59 if (!client_defined_unique_tag_.empty()) | |
| 60 proto->set_client_defined_unique_tag(client_defined_unique_tag_); | |
| 61 } | 46 } |
| 62 | 47 |
| 63 bool PersistentTombstoneEntity::IsDeleted() const { | 48 bool PersistentTombstoneEntity::IsDeleted() const { |
| 64 return true; | 49 return true; |
| 65 } | 50 } |
| 66 | 51 |
| 67 sync_pb::LoopbackServerEntity_Type | 52 sync_pb::LoopbackServerEntity_Type |
| 68 PersistentTombstoneEntity::GetLoopbackServerEntityType() const { | 53 PersistentTombstoneEntity::GetLoopbackServerEntityType() const { |
| 69 return sync_pb::LoopbackServerEntity_Type_TOMBSTONE; | 54 return sync_pb::LoopbackServerEntity_Type_TOMBSTONE; |
| 70 } | 55 } |
| 71 | 56 |
| 72 } // namespace syncer | 57 } // namespace syncer |
| OLD | NEW |