| 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/unique_client_entity.h" | 5 #include "sync/test/fake_server/unique_client_entity.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/guid.h" | 12 #include "base/guid.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "sync/internal_api/public/base/model_type.h" | 13 #include "sync/internal_api/public/base/model_type.h" |
| 14 #include "sync/protocol/sync.pb.h" | 14 #include "sync/protocol/sync.pb.h" |
| 15 #include "sync/syncable/syncable_util.h" | 15 #include "sync/syncable/syncable_util.h" |
| 16 #include "sync/test/fake_server/fake_server_entity.h" | 16 #include "sync/test/fake_server/fake_server_entity.h" |
| 17 #include "sync/test/fake_server/permanent_entity.h" | 17 #include "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; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 : FakeServerEntity(id, model_type, version, name), | 47 : FakeServerEntity(id, model_type, version, name), |
| 48 client_defined_unique_tag_(client_defined_unique_tag), | 48 client_defined_unique_tag_(client_defined_unique_tag), |
| 49 creation_time_(creation_time), | 49 creation_time_(creation_time), |
| 50 last_modified_time_(last_modified_time) { | 50 last_modified_time_(last_modified_time) { |
| 51 SetSpecifics(specifics); | 51 SetSpecifics(specifics); |
| 52 } | 52 } |
| 53 | 53 |
| 54 UniqueClientEntity::~UniqueClientEntity() { } | 54 UniqueClientEntity::~UniqueClientEntity() { } |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 scoped_ptr<FakeServerEntity> UniqueClientEntity::Create( | 57 std::unique_ptr<FakeServerEntity> UniqueClientEntity::Create( |
| 58 const sync_pb::SyncEntity& client_entity) { | 58 const sync_pb::SyncEntity& client_entity) { |
| 59 CHECK(client_entity.has_client_defined_unique_tag()) | 59 CHECK(client_entity.has_client_defined_unique_tag()) |
| 60 << "A UniqueClientEntity must have a client-defined unique tag."; | 60 << "A UniqueClientEntity must have a client-defined unique tag."; |
| 61 ModelType model_type = | 61 ModelType model_type = |
| 62 syncer::GetModelTypeFromSpecifics(client_entity.specifics()); | 62 syncer::GetModelTypeFromSpecifics(client_entity.specifics()); |
| 63 string id = EffectiveIdForClientTaggedEntity(client_entity); | 63 string id = EffectiveIdForClientTaggedEntity(client_entity); |
| 64 return scoped_ptr<FakeServerEntity>(new UniqueClientEntity( | 64 return std::unique_ptr<FakeServerEntity>(new UniqueClientEntity( |
| 65 id, model_type, client_entity.version(), client_entity.name(), | 65 id, model_type, client_entity.version(), client_entity.name(), |
| 66 client_entity.client_defined_unique_tag(), client_entity.specifics(), | 66 client_entity.client_defined_unique_tag(), client_entity.specifics(), |
| 67 client_entity.ctime(), client_entity.mtime())); | 67 client_entity.ctime(), client_entity.mtime())); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // static | 70 // static |
| 71 scoped_ptr<FakeServerEntity> UniqueClientEntity::CreateForInjection( | 71 std::unique_ptr<FakeServerEntity> UniqueClientEntity::CreateForInjection( |
| 72 const string& name, | 72 const string& name, |
| 73 const sync_pb::EntitySpecifics& entity_specifics) { | 73 const sync_pb::EntitySpecifics& entity_specifics) { |
| 74 ModelType model_type = GetModelTypeFromSpecifics(entity_specifics); | 74 ModelType model_type = GetModelTypeFromSpecifics(entity_specifics); |
| 75 string client_defined_unique_tag = GenerateSyncableHash(model_type, name); | 75 string client_defined_unique_tag = GenerateSyncableHash(model_type, name); |
| 76 string id = FakeServerEntity::CreateId(model_type, client_defined_unique_tag); | 76 string id = FakeServerEntity::CreateId(model_type, client_defined_unique_tag); |
| 77 return scoped_ptr<FakeServerEntity>( | 77 return std::unique_ptr<FakeServerEntity>(new UniqueClientEntity( |
| 78 new UniqueClientEntity(id, | 78 id, model_type, kUnusedVersion, name, client_defined_unique_tag, |
| 79 model_type, | 79 entity_specifics, kDefaultTime, kDefaultTime)); |
| 80 kUnusedVersion, | |
| 81 name, | |
| 82 client_defined_unique_tag, | |
| 83 entity_specifics, | |
| 84 kDefaultTime, | |
| 85 kDefaultTime)); | |
| 86 } | 80 } |
| 87 | 81 |
| 88 // static | 82 // static |
| 89 std::string UniqueClientEntity::EffectiveIdForClientTaggedEntity( | 83 std::string UniqueClientEntity::EffectiveIdForClientTaggedEntity( |
| 90 const sync_pb::SyncEntity& entity) { | 84 const sync_pb::SyncEntity& entity) { |
| 91 return FakeServerEntity::CreateId( | 85 return FakeServerEntity::CreateId( |
| 92 syncer::GetModelTypeFromSpecifics(entity.specifics()), | 86 syncer::GetModelTypeFromSpecifics(entity.specifics()), |
| 93 entity.client_defined_unique_tag()); | 87 entity.client_defined_unique_tag()); |
| 94 } | 88 } |
| 95 | 89 |
| 96 bool UniqueClientEntity::RequiresParentId() const { | 90 bool UniqueClientEntity::RequiresParentId() const { |
| 97 return false; | 91 return false; |
| 98 } | 92 } |
| 99 | 93 |
| 100 string UniqueClientEntity::GetParentId() const { | 94 string UniqueClientEntity::GetParentId() const { |
| 101 // The parent ID for this type of entity should always be its ModelType's | 95 // The parent ID for this type of entity should always be its ModelType's |
| 102 // root node. | 96 // root node. |
| 103 return FakeServerEntity::GetTopLevelId(GetModelType()); | 97 return FakeServerEntity::GetTopLevelId(GetModelType()); |
| 104 } | 98 } |
| 105 | 99 |
| 106 void UniqueClientEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const { | 100 void UniqueClientEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const { |
| 107 FakeServerEntity::SerializeBaseProtoFields(proto); | 101 FakeServerEntity::SerializeBaseProtoFields(proto); |
| 108 | 102 |
| 109 proto->set_client_defined_unique_tag(client_defined_unique_tag_); | 103 proto->set_client_defined_unique_tag(client_defined_unique_tag_); |
| 110 proto->set_ctime(creation_time_); | 104 proto->set_ctime(creation_time_); |
| 111 proto->set_mtime(last_modified_time_); | 105 proto->set_mtime(last_modified_time_); |
| 112 } | 106 } |
| 113 | 107 |
| 114 } // namespace fake_server | 108 } // namespace fake_server |
| OLD | NEW |