| 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 "sync/test/fake_server/permanent_entity.h" | 5 #include "sync/test/fake_server/permanent_entity.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace fake_server { | 23 namespace fake_server { |
| 24 | 24 |
| 25 PermanentEntity::~PermanentEntity() { } | 25 PermanentEntity::~PermanentEntity() { } |
| 26 | 26 |
| 27 // static | 27 // static |
| 28 FakeServerEntity* PermanentEntity::Create(const ModelType& model_type, | 28 FakeServerEntity* PermanentEntity::Create(const ModelType& model_type, |
| 29 const string& server_tag, | 29 const string& server_tag, |
| 30 const string& name, | 30 const string& name, |
| 31 const string& parent_server_tag) { | 31 const string& parent_server_tag) { |
| 32 DCHECK(model_type != syncer::UNSPECIFIED); | 32 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " |
| 33 DCHECK(!server_tag.empty()); | 33 << "invalid."; |
| 34 DCHECK(!name.empty()); | 34 CHECK(!server_tag.empty()) << "A PermanentEntity must have a server tag."; |
| 35 DCHECK(!parent_server_tag.empty()); | 35 CHECK(!name.empty()) << "The entity must have a non-empty name."; |
| 36 if (parent_server_tag == kRootParentTag) { | 36 CHECK(!parent_server_tag.empty()) << "A PermanentEntity must have a parent " |
| 37 return NULL; | 37 << "server tag."; |
| 38 } | 38 CHECK(parent_server_tag != kRootParentTag) << "Top-level entities should not " |
| 39 << "be created with this factory."; |
| 39 | 40 |
| 40 string id = FakeServerEntity::CreateId(model_type, server_tag); | 41 string id = FakeServerEntity::CreateId(model_type, server_tag); |
| 41 string parent_id = FakeServerEntity::CreateId(model_type, parent_server_tag); | 42 string parent_id = FakeServerEntity::CreateId(model_type, parent_server_tag); |
| 42 sync_pb::EntitySpecifics entity_specifics; | 43 sync_pb::EntitySpecifics entity_specifics; |
| 43 AddDefaultFieldValue(model_type, &entity_specifics); | 44 AddDefaultFieldValue(model_type, &entity_specifics); |
| 44 return new PermanentEntity(id, | 45 return new PermanentEntity(id, |
| 45 model_type, | 46 model_type, |
| 46 name, | 47 name, |
| 47 parent_id, | 48 parent_id, |
| 48 server_tag, | 49 server_tag, |
| 49 entity_specifics); | 50 entity_specifics); |
| 50 } | 51 } |
| 51 | 52 |
| 52 // static | 53 // static |
| 53 FakeServerEntity* PermanentEntity::CreateTopLevel( | 54 FakeServerEntity* PermanentEntity::CreateTopLevel(const ModelType& model_type) { |
| 54 const ModelType& model_type) { | 55 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " |
| 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::CreateId(model_type, server_tag); | 59 string id = FakeServerEntity::CreateId(model_type, server_tag); |
| 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 new PermanentEntity(id, | 62 return new PermanentEntity(id, |
| 61 model_type, | 63 model_type, |
| 62 name, | 64 name, |
| 63 kRootParentTag, | 65 kRootParentTag, |
| 64 server_tag, | 66 server_tag, |
| 65 entity_specifics); | 67 entity_specifics); |
| 66 } | 68 } |
| 67 | 69 |
| 68 // static | 70 // static |
| 69 FakeServerEntity* PermanentEntity::CreateUpdatedNigoriEntity( | 71 FakeServerEntity* PermanentEntity::CreateUpdatedNigoriEntity( |
| 70 const sync_pb::SyncEntity& client_entity, | 72 const sync_pb::SyncEntity& client_entity, |
| 71 FakeServerEntity* current_server_entity) { | 73 FakeServerEntity* current_server_entity) { |
| 72 ModelType model_type = current_server_entity->GetModelType(); | 74 ModelType model_type = current_server_entity->GetModelType(); |
| 73 if (model_type != syncer::NIGORI) { | 75 CHECK(model_type == syncer::NIGORI) << "This factory only supports NIGORI " |
| 74 return NULL; | 76 << "entities."; |
| 75 } | |
| 76 | 77 |
| 77 return new PermanentEntity(current_server_entity->GetId(), | 78 return new PermanentEntity(current_server_entity->GetId(), |
| 78 model_type, | 79 model_type, |
| 79 current_server_entity->GetName(), | 80 current_server_entity->GetName(), |
| 80 current_server_entity->GetParentId(), | 81 current_server_entity->GetParentId(), |
| 81 syncer::ModelTypeToRootTag(model_type), | 82 syncer::ModelTypeToRootTag(model_type), |
| 82 client_entity.specifics()); | 83 client_entity.specifics()); |
| 83 } | 84 } |
| 84 | 85 |
| 85 PermanentEntity::PermanentEntity(const string& id, | 86 PermanentEntity::PermanentEntity(const string& id, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 112 | 113 |
| 113 bool PermanentEntity::IsDeleted() const { | 114 bool PermanentEntity::IsDeleted() const { |
| 114 return false; | 115 return false; |
| 115 } | 116 } |
| 116 | 117 |
| 117 bool PermanentEntity::IsFolder() const { | 118 bool PermanentEntity::IsFolder() const { |
| 118 return true; | 119 return true; |
| 119 } | 120 } |
| 120 | 121 |
| 121 } // namespace fake_server | 122 } // namespace fake_server |
| OLD | NEW |