| 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/engine_impl/loopback_server/persistent_permanent_entit
y.h" | 5 #include "components/sync/engine_impl/loopback_server/persistent_permanent_entit
y.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 namespace syncer { | 26 namespace syncer { |
| 27 | 27 |
| 28 PersistentPermanentEntity::~PersistentPermanentEntity() {} | 28 PersistentPermanentEntity::~PersistentPermanentEntity() {} |
| 29 | 29 |
| 30 // static | 30 // static |
| 31 std::unique_ptr<LoopbackServerEntity> PersistentPermanentEntity::Create( | 31 std::unique_ptr<LoopbackServerEntity> PersistentPermanentEntity::Create( |
| 32 const ModelType& model_type, | 32 const ModelType& model_type, |
| 33 const string& server_tag, | 33 const string& server_tag, |
| 34 const string& name, | 34 const string& name, |
| 35 const string& parent_server_tag) { | 35 const string& parent_server_tag) { |
| 36 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " | 36 // The entity's ModelType is invalid. |
| 37 << "invalid."; | 37 CHECK(model_type != syncer::UNSPECIFIED); |
| 38 CHECK(!server_tag.empty()) | 38 // A PersistentPermanentEntity must have a server tag. |
| 39 << "A PersistentPermanentEntity must have a server tag."; | 39 CHECK(!server_tag.empty()); |
| 40 CHECK(!name.empty()) << "The entity must have a non-empty name."; | 40 // The entity must have a non-empty name. |
| 41 CHECK(!parent_server_tag.empty()) | 41 CHECK(!name.empty()); |
| 42 << "A PersistentPermanentEntity must have a parent " | 42 // A PersistentPermanentEntity must have a parent server tag. |
| 43 << "server tag."; | 43 CHECK(!parent_server_tag.empty()); |
| 44 CHECK(parent_server_tag != kRootParentTag) << "Top-level entities should not " | 44 // Top-level entities should not be created with this factory. |
| 45 << "be created with this factory."; | 45 CHECK(parent_server_tag != kRootParentTag); |
| 46 | 46 |
| 47 string id = LoopbackServerEntity::CreateId(model_type, server_tag); | 47 string id = LoopbackServerEntity::CreateId(model_type, server_tag); |
| 48 string parent_id = | 48 string parent_id = |
| 49 LoopbackServerEntity::CreateId(model_type, parent_server_tag); | 49 LoopbackServerEntity::CreateId(model_type, parent_server_tag); |
| 50 sync_pb::EntitySpecifics entity_specifics; | 50 sync_pb::EntitySpecifics entity_specifics; |
| 51 AddDefaultFieldValue(model_type, &entity_specifics); | 51 AddDefaultFieldValue(model_type, &entity_specifics); |
| 52 return std::unique_ptr<LoopbackServerEntity>(new PersistentPermanentEntity( | 52 return std::unique_ptr<LoopbackServerEntity>(new PersistentPermanentEntity( |
| 53 id, 0, model_type, name, parent_id, server_tag, entity_specifics)); | 53 id, 0, model_type, name, parent_id, server_tag, entity_specifics)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 std::unique_ptr<LoopbackServerEntity> PersistentPermanentEntity::CreateTopLevel( | 57 std::unique_ptr<LoopbackServerEntity> PersistentPermanentEntity::CreateTopLevel( |
| 58 const ModelType& model_type) { | 58 const ModelType& model_type) { |
| 59 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is " | 59 // The entity's ModelType is invalid. |
| 60 << "invalid."; | 60 CHECK(model_type != syncer::UNSPECIFIED); |
| 61 string server_tag = syncer::ModelTypeToRootTag(model_type); | 61 string server_tag = syncer::ModelTypeToRootTag(model_type); |
| 62 string name = syncer::ModelTypeToString(model_type); | 62 string name = syncer::ModelTypeToString(model_type); |
| 63 string id = LoopbackServerEntity::GetTopLevelId(model_type); | 63 string id = LoopbackServerEntity::GetTopLevelId(model_type); |
| 64 sync_pb::EntitySpecifics entity_specifics; | 64 sync_pb::EntitySpecifics entity_specifics; |
| 65 AddDefaultFieldValue(model_type, &entity_specifics); | 65 AddDefaultFieldValue(model_type, &entity_specifics); |
| 66 return std::unique_ptr<LoopbackServerEntity>(new PersistentPermanentEntity( | 66 return std::unique_ptr<LoopbackServerEntity>(new PersistentPermanentEntity( |
| 67 id, 0, model_type, name, kRootParentTag, server_tag, entity_specifics)); | 67 id, 0, model_type, name, kRootParentTag, server_tag, entity_specifics)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // static | 70 // static |
| 71 std::unique_ptr<LoopbackServerEntity> | 71 std::unique_ptr<LoopbackServerEntity> |
| 72 PersistentPermanentEntity::CreateUpdatedNigoriEntity( | 72 PersistentPermanentEntity::CreateUpdatedNigoriEntity( |
| 73 const sync_pb::SyncEntity& client_entity, | 73 const sync_pb::SyncEntity& client_entity, |
| 74 const LoopbackServerEntity& current_server_entity) { | 74 const LoopbackServerEntity& current_server_entity) { |
| 75 ModelType model_type = current_server_entity.GetModelType(); | 75 ModelType model_type = current_server_entity.GetModelType(); |
| 76 CHECK(model_type == syncer::NIGORI) << "This factory only supports NIGORI " | 76 // This factory only supports NIGORI entities. |
| 77 << "entities."; | 77 CHECK(model_type == syncer::NIGORI); |
| 78 | 78 |
| 79 return base::WrapUnique<LoopbackServerEntity>(new PersistentPermanentEntity( | 79 return base::WrapUnique<LoopbackServerEntity>(new PersistentPermanentEntity( |
| 80 current_server_entity.GetId(), current_server_entity.GetVersion(), | 80 current_server_entity.GetId(), current_server_entity.GetVersion(), |
| 81 model_type, current_server_entity.GetName(), | 81 model_type, current_server_entity.GetName(), |
| 82 current_server_entity.GetParentId(), | 82 current_server_entity.GetParentId(), |
| 83 syncer::ModelTypeToRootTag(model_type), client_entity.specifics())); | 83 syncer::ModelTypeToRootTag(model_type), client_entity.specifics())); |
| 84 } | 84 } |
| 85 | 85 |
| 86 PersistentPermanentEntity::PersistentPermanentEntity( | 86 PersistentPermanentEntity::PersistentPermanentEntity( |
| 87 const string& id, | 87 const string& id, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 118 bool PersistentPermanentEntity::IsPermanent() const { | 118 bool PersistentPermanentEntity::IsPermanent() const { |
| 119 return true; | 119 return true; |
| 120 } | 120 } |
| 121 | 121 |
| 122 sync_pb::LoopbackServerEntity_Type | 122 sync_pb::LoopbackServerEntity_Type |
| 123 PersistentPermanentEntity::GetLoopbackServerEntityType() const { | 123 PersistentPermanentEntity::GetLoopbackServerEntityType() const { |
| 124 return sync_pb::LoopbackServerEntity_Type_PERMANENT; | 124 return sync_pb::LoopbackServerEntity_Type_PERMANENT; |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace syncer | 127 } // namespace syncer |
| OLD | NEW |