| 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/permanent_entity.h" | 5 #include "components/sync/engine_impl/net/loopback_server/permanent_entity.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 11 #include "components/sync/base/model_type.h" | 12 #include "components/sync/base/model_type.h" |
| 13 #include "components/sync/engine_impl/net/loopback_server/loopback_server_entity
.h" |
| 12 #include "components/sync/protocol/sync.pb.h" | 14 #include "components/sync/protocol/sync.pb.h" |
| 13 #include "components/sync/test/fake_server/fake_server_entity.h" | |
| 14 | 15 |
| 15 using std::string; | 16 using std::string; |
| 16 | 17 |
| 17 using syncer::ModelType; | 18 using syncer::ModelType; |
| 18 | 19 |
| 19 // The parent tag for children of the root entity. Entities with this parent are | 20 // The parent tag for children of the root entity. Entities with this parent are |
| 20 // referred to as top level enities. | 21 // referred to as top level enities. |
| 21 static const char kRootParentTag[] = "0"; | 22 static const char kRootParentTag[] = "0"; |
| 22 | 23 |
| 23 namespace fake_server { | 24 namespace syncer { |
| 24 | 25 |
| 25 PermanentEntity::~PermanentEntity() {} | 26 PermanentEntity::~PermanentEntity() { } |
| 26 | 27 |
| 27 // static | 28 // static |
| 28 std::unique_ptr<FakeServerEntity> PermanentEntity::Create( | 29 std::unique_ptr<LoopbackServerEntity> PermanentEntity::Create( |
| 29 const ModelType& model_type, | 30 const ModelType& model_type, |
| 30 const string& server_tag, | 31 const string& server_tag, |
| 31 const string& name, | 32 const string& name, |
| 32 const string& parent_server_tag) { | 33 const string& parent_server_tag) { |
| 33 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " | 34 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " |
| 34 << "invalid."; | 35 << "invalid."; |
| 35 CHECK(!server_tag.empty()) << "A PermanentEntity must have a server tag."; | 36 CHECK(!server_tag.empty()) << "A PermanentEntity must have a server tag."; |
| 36 CHECK(!name.empty()) << "The entity must have a non-empty name."; | 37 CHECK(!name.empty()) << "The entity must have a non-empty name."; |
| 37 CHECK(!parent_server_tag.empty()) << "A PermanentEntity must have a parent " | 38 CHECK(!parent_server_tag.empty()) << "A PermanentEntity must have a parent " |
| 38 << "server tag."; | 39 << "server tag."; |
| 39 CHECK(parent_server_tag != kRootParentTag) << "Top-level entities should not " | 40 CHECK(parent_server_tag != kRootParentTag) << "Top-level entities should not " |
| 40 << "be created with this factory."; | 41 << "be created with this factory."; |
| 41 | 42 |
| 42 string id = FakeServerEntity::CreateId(model_type, server_tag); | 43 string id = LoopbackServerEntity::CreateId(model_type, server_tag); |
| 43 string parent_id = FakeServerEntity::CreateId(model_type, parent_server_tag); | 44 string parent_id = LoopbackServerEntity::CreateId(model_type, |
| 45 parent_server_tag); |
| 44 sync_pb::EntitySpecifics entity_specifics; | 46 sync_pb::EntitySpecifics entity_specifics; |
| 45 AddDefaultFieldValue(model_type, &entity_specifics); | 47 AddDefaultFieldValue(model_type, &entity_specifics); |
| 46 return std::unique_ptr<FakeServerEntity>(new PermanentEntity( | 48 return std::unique_ptr<LoopbackServerEntity>(new PermanentEntity( |
| 47 id, model_type, name, parent_id, server_tag, entity_specifics)); | 49 id, 0, model_type, name, parent_id, server_tag, entity_specifics)); |
| 48 } | 50 } |
| 49 | 51 |
| 50 // static | 52 // static |
| 51 std::unique_ptr<FakeServerEntity> PermanentEntity::CreateTopLevel( | 53 std::unique_ptr<LoopbackServerEntity> PermanentEntity::CreateTopLevel( |
| 52 const ModelType& model_type) { | 54 const ModelType& model_type) { |
| 53 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " | 55 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " |
| 54 << "invalid."; | 56 << "invalid."; |
| 55 string server_tag = syncer::ModelTypeToRootTag(model_type); | 57 string server_tag = syncer::ModelTypeToRootTag(model_type); |
| 56 string name = syncer::ModelTypeToString(model_type); | 58 string name = syncer::ModelTypeToString(model_type); |
| 57 string id = FakeServerEntity::GetTopLevelId(model_type); | 59 string id = LoopbackServerEntity::GetTopLevelId(model_type); |
| 58 sync_pb::EntitySpecifics entity_specifics; | 60 sync_pb::EntitySpecifics entity_specifics; |
| 59 AddDefaultFieldValue(model_type, &entity_specifics); | 61 AddDefaultFieldValue(model_type, &entity_specifics); |
| 60 return std::unique_ptr<FakeServerEntity>(new PermanentEntity( | 62 return std::unique_ptr<LoopbackServerEntity>(new PermanentEntity( |
| 61 id, model_type, name, kRootParentTag, server_tag, entity_specifics)); | 63 id, 0, model_type, name, kRootParentTag, server_tag, entity_specifics)); |
| 62 } | 64 } |
| 63 | 65 |
| 64 // static | 66 // static |
| 65 std::unique_ptr<FakeServerEntity> PermanentEntity::CreateUpdatedNigoriEntity( | 67 std::unique_ptr<LoopbackServerEntity> |
| 68 PermanentEntity::CreateUpdatedNigoriEntity( |
| 66 const sync_pb::SyncEntity& client_entity, | 69 const sync_pb::SyncEntity& client_entity, |
| 67 const FakeServerEntity& current_server_entity) { | 70 const LoopbackServerEntity& current_server_entity) { |
| 68 ModelType model_type = current_server_entity.model_type(); | 71 ModelType model_type = current_server_entity.GetModelType(); |
| 69 CHECK(model_type == syncer::NIGORI) << "This factory only supports NIGORI " | 72 CHECK(model_type == syncer::NIGORI) << "This factory only supports NIGORI " |
| 70 << "entities."; | 73 << "entities."; |
| 71 | 74 |
| 72 return base::WrapUnique<FakeServerEntity>(new PermanentEntity( | 75 return base::WrapUnique<LoopbackServerEntity>(new PermanentEntity( |
| 73 current_server_entity.id(), model_type, current_server_entity.GetName(), | 76 current_server_entity.GetId(), current_server_entity.GetVersion(), |
| 77 model_type, current_server_entity.GetName(), |
| 74 current_server_entity.GetParentId(), | 78 current_server_entity.GetParentId(), |
| 75 syncer::ModelTypeToRootTag(model_type), client_entity.specifics())); | 79 syncer::ModelTypeToRootTag(model_type), client_entity.specifics())); |
| 76 } | 80 } |
| 77 | 81 |
| 78 PermanentEntity::PermanentEntity(const string& id, | 82 PermanentEntity::PermanentEntity(const string& id, |
| 83 int64_t version, |
| 79 const ModelType& model_type, | 84 const ModelType& model_type, |
| 80 const string& name, | 85 const string& name, |
| 81 const string& parent_id, | 86 const string& parent_id, |
| 82 const string& server_defined_unique_tag, | 87 const string& server_defined_unique_tag, |
| 83 const sync_pb::EntitySpecifics& specifics) | 88 const sync_pb::EntitySpecifics& specifics) |
| 84 : FakeServerEntity(id, string(), model_type, 0, name), | 89 : LoopbackServerEntity(id, model_type, version, name), |
| 85 server_defined_unique_tag_(server_defined_unique_tag), | 90 server_defined_unique_tag_(server_defined_unique_tag), |
| 86 parent_id_(parent_id) { | 91 parent_id_(parent_id) { |
| 87 SetSpecifics(specifics); | 92 SetSpecifics(specifics); |
| 88 } | 93 } |
| 89 | 94 |
| 90 bool PermanentEntity::RequiresParentId() const { | 95 bool PermanentEntity::RequiresParentId() const { |
| 91 return true; | 96 return true; |
| 92 } | 97 } |
| 93 | 98 |
| 94 string PermanentEntity::GetParentId() const { | 99 string PermanentEntity::GetParentId() const { |
| 95 return parent_id_; | 100 return parent_id_; |
| 96 } | 101 } |
| 97 | 102 |
| 98 void PermanentEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const { | 103 void PermanentEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const { |
| 99 FakeServerEntity::SerializeBaseProtoFields(proto); | 104 LoopbackServerEntity::SerializeBaseProtoFields(proto); |
| 100 proto->set_server_defined_unique_tag(server_defined_unique_tag_); | 105 proto->set_server_defined_unique_tag(server_defined_unique_tag_); |
| 101 } | 106 } |
| 102 | 107 |
| 103 bool PermanentEntity::IsFolder() const { | 108 bool PermanentEntity::IsFolder() const { |
| 104 return true; | 109 return true; |
| 105 } | 110 } |
| 106 | 111 |
| 107 bool PermanentEntity::IsPermanent() const { | 112 bool PermanentEntity::IsPermanent() const { |
| 108 return true; | 113 return true; |
| 109 } | 114 } |
| 110 | 115 |
| 111 } // namespace fake_server | 116 } // namespace syncer |
| OLD | NEW |