| 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/test/fake_server/unique_client_entity.h" | 5 #include "components/sync/test/fake_server/unique_client_entity.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // is overrideen immediately when saving the entity in FakeServer. | 30 // is overrideen immediately when saving the entity in FakeServer. |
| 31 const int64_t kUnusedVersion = 0L; | 31 const int64_t kUnusedVersion = 0L; |
| 32 | 32 |
| 33 // Default time (creation and last modified) used when creating entities. | 33 // Default time (creation and last modified) used when creating entities. |
| 34 const int64_t kDefaultTime = 1234L; | 34 const int64_t kDefaultTime = 1234L; |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 UniqueClientEntity::UniqueClientEntity( | 38 UniqueClientEntity::UniqueClientEntity( |
| 39 const string& id, | 39 const string& id, |
| 40 const string& client_defined_unique_tag, |
| 40 ModelType model_type, | 41 ModelType model_type, |
| 41 int64_t version, | 42 int64_t version, |
| 42 const string& name, | 43 const string& name, |
| 43 const string& client_defined_unique_tag, | |
| 44 const sync_pb::EntitySpecifics& specifics, | 44 const sync_pb::EntitySpecifics& specifics, |
| 45 int64_t creation_time, | 45 int64_t creation_time, |
| 46 int64_t last_modified_time) | 46 int64_t last_modified_time) |
| 47 : FakeServerEntity(id, model_type, version, name), | 47 : FakeServerEntity(id, |
| 48 client_defined_unique_tag_(client_defined_unique_tag), | 48 client_defined_unique_tag, |
| 49 model_type, |
| 50 version, |
| 51 name), |
| 49 creation_time_(creation_time), | 52 creation_time_(creation_time), |
| 50 last_modified_time_(last_modified_time) { | 53 last_modified_time_(last_modified_time) { |
| 51 SetSpecifics(specifics); | 54 SetSpecifics(specifics); |
| 52 } | 55 } |
| 53 | 56 |
| 54 UniqueClientEntity::~UniqueClientEntity() {} | 57 UniqueClientEntity::~UniqueClientEntity() {} |
| 55 | 58 |
| 56 // static | 59 // static |
| 57 std::unique_ptr<FakeServerEntity> UniqueClientEntity::Create( | 60 std::unique_ptr<FakeServerEntity> UniqueClientEntity::Create( |
| 58 const sync_pb::SyncEntity& client_entity) { | 61 const sync_pb::SyncEntity& client_entity) { |
| 59 CHECK(client_entity.has_client_defined_unique_tag()) | 62 CHECK(client_entity.has_client_defined_unique_tag()) |
| 60 << "A UniqueClientEntity must have a client-defined unique tag."; | 63 << "A UniqueClientEntity must have a client-defined unique tag."; |
| 61 ModelType model_type = | 64 ModelType model_type = |
| 62 syncer::GetModelTypeFromSpecifics(client_entity.specifics()); | 65 syncer::GetModelTypeFromSpecifics(client_entity.specifics()); |
| 63 string id = EffectiveIdForClientTaggedEntity(client_entity); | 66 string id = EffectiveIdForClientTaggedEntity(client_entity); |
| 64 return std::unique_ptr<FakeServerEntity>(new UniqueClientEntity( | 67 return std::unique_ptr<FakeServerEntity>(new UniqueClientEntity( |
| 65 id, model_type, client_entity.version(), client_entity.name(), | 68 id, client_entity.client_defined_unique_tag(), model_type, |
| 66 client_entity.client_defined_unique_tag(), client_entity.specifics(), | 69 client_entity.version(), client_entity.name(), client_entity.specifics(), |
| 67 client_entity.ctime(), client_entity.mtime())); | 70 client_entity.ctime(), client_entity.mtime())); |
| 68 } | 71 } |
| 69 | 72 |
| 70 // static | 73 // static |
| 71 std::unique_ptr<FakeServerEntity> UniqueClientEntity::CreateForInjection( | 74 std::unique_ptr<FakeServerEntity> UniqueClientEntity::CreateForInjection( |
| 72 const string& name, | 75 const string& name, |
| 73 const sync_pb::EntitySpecifics& entity_specifics) { | 76 const sync_pb::EntitySpecifics& entity_specifics) { |
| 74 ModelType model_type = GetModelTypeFromSpecifics(entity_specifics); | 77 ModelType model_type = GetModelTypeFromSpecifics(entity_specifics); |
| 75 string client_defined_unique_tag = GenerateSyncableHash(model_type, name); | 78 string client_defined_unique_tag = GenerateSyncableHash(model_type, name); |
| 76 string id = FakeServerEntity::CreateId(model_type, client_defined_unique_tag); | 79 string id = FakeServerEntity::CreateId(model_type, client_defined_unique_tag); |
| 77 return std::unique_ptr<FakeServerEntity>(new UniqueClientEntity( | 80 return std::unique_ptr<FakeServerEntity>(new UniqueClientEntity( |
| 78 id, model_type, kUnusedVersion, name, client_defined_unique_tag, | 81 id, client_defined_unique_tag, model_type, kUnusedVersion, name, |
| 79 entity_specifics, kDefaultTime, kDefaultTime)); | 82 entity_specifics, kDefaultTime, kDefaultTime)); |
| 80 } | 83 } |
| 81 | 84 |
| 82 // static | 85 // static |
| 83 std::string UniqueClientEntity::EffectiveIdForClientTaggedEntity( | 86 std::string UniqueClientEntity::EffectiveIdForClientTaggedEntity( |
| 84 const sync_pb::SyncEntity& entity) { | 87 const sync_pb::SyncEntity& entity) { |
| 85 return FakeServerEntity::CreateId( | 88 return FakeServerEntity::CreateId( |
| 86 syncer::GetModelTypeFromSpecifics(entity.specifics()), | 89 syncer::GetModelTypeFromSpecifics(entity.specifics()), |
| 87 entity.client_defined_unique_tag()); | 90 entity.client_defined_unique_tag()); |
| 88 } | 91 } |
| 89 | 92 |
| 90 bool UniqueClientEntity::RequiresParentId() const { | 93 bool UniqueClientEntity::RequiresParentId() const { |
| 91 return false; | 94 return false; |
| 92 } | 95 } |
| 93 | 96 |
| 94 string UniqueClientEntity::GetParentId() const { | 97 string UniqueClientEntity::GetParentId() const { |
| 95 // The parent ID for this type of entity should always be its ModelType's | 98 // The parent ID for this type of entity should always be its ModelType's |
| 96 // root node. | 99 // root node. |
| 97 return FakeServerEntity::GetTopLevelId(GetModelType()); | 100 return FakeServerEntity::GetTopLevelId(model_type()); |
| 98 } | 101 } |
| 99 | 102 |
| 100 void UniqueClientEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const { | 103 void UniqueClientEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const { |
| 101 FakeServerEntity::SerializeBaseProtoFields(proto); | 104 FakeServerEntity::SerializeBaseProtoFields(proto); |
| 102 | 105 |
| 103 proto->set_client_defined_unique_tag(client_defined_unique_tag_); | |
| 104 proto->set_ctime(creation_time_); | 106 proto->set_ctime(creation_time_); |
| 105 proto->set_mtime(last_modified_time_); | 107 proto->set_mtime(last_modified_time_); |
| 106 } | 108 } |
| 107 | 109 |
| 108 } // namespace fake_server | 110 } // namespace fake_server |
| OLD | NEW |