| 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/engine_impl/net/loopback_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> |
| 11 | 11 |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "components/sync/base/model_type.h" | 13 #include "components/sync/base/model_type.h" |
| 14 #include "components/sync/engine_impl/net/loopback_server/loopback_server_entity
.h" |
| 15 #include "components/sync/engine_impl/net/loopback_server/permanent_entity.h" |
| 14 #include "components/sync/protocol/sync.pb.h" | 16 #include "components/sync/protocol/sync.pb.h" |
| 15 #include "components/sync/syncable/syncable_util.h" | 17 #include "components/sync/syncable/syncable_util.h" |
| 16 #include "components/sync/test/fake_server/fake_server_entity.h" | |
| 17 #include "components/sync/test/fake_server/permanent_entity.h" | |
| 18 | 18 |
| 19 using std::string; | 19 using std::string; |
| 20 | 20 |
| 21 using syncer::GetModelTypeFromSpecifics; | 21 using syncer::GetModelTypeFromSpecifics; |
| 22 using syncer::ModelType; | 22 using syncer::ModelType; |
| 23 using syncer::syncable::GenerateSyncableHash; | 23 using syncer::syncable::GenerateSyncableHash; |
| 24 | 24 |
| 25 namespace fake_server { | 25 namespace syncer { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // A version must be passed when creating a FakeServerEntity, but this value | 29 // A version must be passed when creating a LoopbackServerEntity, but this value |
| 30 // is overrideen immediately when saving the entity in FakeServer. | 30 // is overrideen immediately when saving the entity in LoopbackServer. |
| 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, | |
| 41 ModelType model_type, | 40 ModelType model_type, |
| 42 int64_t version, | 41 int64_t version, |
| 43 const string& name, | 42 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, | 47 : LoopbackServerEntity(id, model_type, version, name), |
| 48 client_defined_unique_tag, | 48 client_defined_unique_tag_(client_defined_unique_tag), |
| 49 model_type, | |
| 50 version, | |
| 51 name), | |
| 52 creation_time_(creation_time), | 49 creation_time_(creation_time), |
| 53 last_modified_time_(last_modified_time) { | 50 last_modified_time_(last_modified_time) { |
| 54 SetSpecifics(specifics); | 51 SetSpecifics(specifics); |
| 55 } | 52 } |
| 56 | 53 |
| 57 UniqueClientEntity::~UniqueClientEntity() {} | 54 UniqueClientEntity::~UniqueClientEntity() { } |
| 58 | 55 |
| 59 // static | 56 // static |
| 60 std::unique_ptr<FakeServerEntity> UniqueClientEntity::Create( | 57 std::unique_ptr<LoopbackServerEntity> UniqueClientEntity::Create( |
| 61 const sync_pb::SyncEntity& client_entity) { | 58 const sync_pb::SyncEntity& client_entity) { |
| 62 CHECK(client_entity.has_client_defined_unique_tag()) | 59 CHECK(client_entity.has_client_defined_unique_tag()) |
| 63 << "A UniqueClientEntity must have a client-defined unique tag."; | 60 << "A UniqueClientEntity must have a client-defined unique tag."; |
| 64 ModelType model_type = | 61 ModelType model_type = |
| 65 syncer::GetModelTypeFromSpecifics(client_entity.specifics()); | 62 syncer::GetModelTypeFromSpecifics(client_entity.specifics()); |
| 66 string id = EffectiveIdForClientTaggedEntity(client_entity); | 63 string id = EffectiveIdForClientTaggedEntity(client_entity); |
| 67 return std::unique_ptr<FakeServerEntity>(new UniqueClientEntity( | 64 return std::unique_ptr<LoopbackServerEntity>(new UniqueClientEntity( |
| 68 id, client_entity.client_defined_unique_tag(), model_type, | 65 id, model_type, client_entity.version(), client_entity.name(), |
| 69 client_entity.version(), client_entity.name(), client_entity.specifics(), | 66 client_entity.client_defined_unique_tag(), client_entity.specifics(), |
| 70 client_entity.ctime(), client_entity.mtime())); | 67 client_entity.ctime(), client_entity.mtime())); |
| 71 } | 68 } |
| 72 | 69 |
| 73 // static | 70 // static |
| 74 std::unique_ptr<FakeServerEntity> UniqueClientEntity::CreateForInjection( | |
| 75 const string& name, | |
| 76 const sync_pb::EntitySpecifics& entity_specifics) { | |
| 77 ModelType model_type = GetModelTypeFromSpecifics(entity_specifics); | |
| 78 string client_defined_unique_tag = GenerateSyncableHash(model_type, name); | |
| 79 string id = FakeServerEntity::CreateId(model_type, client_defined_unique_tag); | |
| 80 return std::unique_ptr<FakeServerEntity>(new UniqueClientEntity( | |
| 81 id, client_defined_unique_tag, model_type, kUnusedVersion, name, | |
| 82 entity_specifics, kDefaultTime, kDefaultTime)); | |
| 83 } | |
| 84 | |
| 85 // static | |
| 86 std::string UniqueClientEntity::EffectiveIdForClientTaggedEntity( | 71 std::string UniqueClientEntity::EffectiveIdForClientTaggedEntity( |
| 87 const sync_pb::SyncEntity& entity) { | 72 const sync_pb::SyncEntity& entity) { |
| 88 return FakeServerEntity::CreateId( | 73 return LoopbackServerEntity::CreateId( |
| 89 syncer::GetModelTypeFromSpecifics(entity.specifics()), | 74 syncer::GetModelTypeFromSpecifics(entity.specifics()), |
| 90 entity.client_defined_unique_tag()); | 75 entity.client_defined_unique_tag()); |
| 91 } | 76 } |
| 92 | 77 |
| 93 bool UniqueClientEntity::RequiresParentId() const { | 78 bool UniqueClientEntity::RequiresParentId() const { |
| 94 return false; | 79 return false; |
| 95 } | 80 } |
| 96 | 81 |
| 97 string UniqueClientEntity::GetParentId() const { | 82 string UniqueClientEntity::GetParentId() const { |
| 98 // The parent ID for this type of entity should always be its ModelType's | 83 // The parent ID for this type of entity should always be its ModelType's |
| 99 // root node. | 84 // root node. |
| 100 return FakeServerEntity::GetTopLevelId(model_type()); | 85 return LoopbackServerEntity::GetTopLevelId(GetModelType()); |
| 101 } | 86 } |
| 102 | 87 |
| 103 void UniqueClientEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const { | 88 void UniqueClientEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const { |
| 104 FakeServerEntity::SerializeBaseProtoFields(proto); | 89 LoopbackServerEntity::SerializeBaseProtoFields(proto); |
| 105 | 90 |
| 91 proto->set_client_defined_unique_tag(client_defined_unique_tag_); |
| 106 proto->set_ctime(creation_time_); | 92 proto->set_ctime(creation_time_); |
| 107 proto->set_mtime(last_modified_time_); | 93 proto->set_mtime(last_modified_time_); |
| 108 } | 94 } |
| 109 | 95 |
| 110 } // namespace fake_server | 96 } // namespace syncer |
| OLD | NEW |