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