| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/sync/engine_impl/loopback_server/persistent_unique_client_e
ntity.h" |
| 6 |
| 7 #include <stdint.h> |
| 8 |
| 9 #include <memory> |
| 10 #include <string> |
| 11 |
| 12 #include "base/guid.h" |
| 13 #include "components/sync/base/model_type.h" |
| 14 #include "components/sync/engine_impl/loopback_server/loopback_server_entity.h" |
| 15 #include "components/sync/engine_impl/loopback_server/persistent_permanent_entit
y.h" |
| 16 #include "components/sync/protocol/sync.pb.h" |
| 17 #include "components/sync/syncable/syncable_util.h" |
| 18 |
| 19 using std::string; |
| 20 |
| 21 using syncer::GetModelTypeFromSpecifics; |
| 22 using syncer::ModelType; |
| 23 using syncer::syncable::GenerateSyncableHash; |
| 24 |
| 25 namespace syncer { |
| 26 |
| 27 PersistentUniqueClientEntity::PersistentUniqueClientEntity( |
| 28 const string& id, |
| 29 ModelType model_type, |
| 30 int64_t version, |
| 31 const string& name, |
| 32 const string& client_defined_unique_tag, |
| 33 const sync_pb::EntitySpecifics& specifics, |
| 34 int64_t creation_time, |
| 35 int64_t last_modified_time) |
| 36 : LoopbackServerEntity(id, model_type, version, name), |
| 37 client_defined_unique_tag_(client_defined_unique_tag), |
| 38 creation_time_(creation_time), |
| 39 last_modified_time_(last_modified_time) { |
| 40 SetSpecifics(specifics); |
| 41 } |
| 42 |
| 43 PersistentUniqueClientEntity::~PersistentUniqueClientEntity() {} |
| 44 |
| 45 // static |
| 46 std::unique_ptr<LoopbackServerEntity> PersistentUniqueClientEntity::Create( |
| 47 const sync_pb::SyncEntity& client_entity) { |
| 48 CHECK(client_entity.has_client_defined_unique_tag()) |
| 49 << "A PersistentUniqueClientEntity must have a client-defined unique " |
| 50 "tag."; |
| 51 ModelType model_type = |
| 52 syncer::GetModelTypeFromSpecifics(client_entity.specifics()); |
| 53 string id = EffectiveIdForClientTaggedEntity(client_entity); |
| 54 return std::unique_ptr<LoopbackServerEntity>(new PersistentUniqueClientEntity( |
| 55 id, model_type, client_entity.version(), client_entity.name(), |
| 56 client_entity.client_defined_unique_tag(), client_entity.specifics(), |
| 57 client_entity.ctime(), client_entity.mtime())); |
| 58 } |
| 59 |
| 60 // static |
| 61 std::string PersistentUniqueClientEntity::EffectiveIdForClientTaggedEntity( |
| 62 const sync_pb::SyncEntity& entity) { |
| 63 return LoopbackServerEntity::CreateId( |
| 64 syncer::GetModelTypeFromSpecifics(entity.specifics()), |
| 65 entity.client_defined_unique_tag()); |
| 66 } |
| 67 |
| 68 bool PersistentUniqueClientEntity::RequiresParentId() const { |
| 69 return false; |
| 70 } |
| 71 |
| 72 string PersistentUniqueClientEntity::GetParentId() const { |
| 73 // The parent ID for this type of entity should always be its ModelType's |
| 74 // root node. |
| 75 return LoopbackServerEntity::GetTopLevelId(GetModelType()); |
| 76 } |
| 77 |
| 78 sync_pb::LoopbackServerEntity_Type |
| 79 PersistentUniqueClientEntity::GetLoopbackServerEntityType() const { |
| 80 return sync_pb::LoopbackServerEntity_Type_UNIQUE; |
| 81 } |
| 82 |
| 83 void PersistentUniqueClientEntity::SerializeAsProto( |
| 84 sync_pb::SyncEntity* proto) const { |
| 85 LoopbackServerEntity::SerializeBaseProtoFields(proto); |
| 86 |
| 87 proto->set_client_defined_unique_tag(client_defined_unique_tag_); |
| 88 proto->set_ctime(creation_time_); |
| 89 proto->set_mtime(last_modified_time_); |
| 90 } |
| 91 |
| 92 } // namespace syncer |
| OLD | NEW |