| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/test_entry_factory.h" | 5 #include "components/sync/engine_impl/test_entry_factory.h" |
| 6 | 6 |
| 7 #include "components/sync/base/hash_util.h" | 7 #include "components/sync/base/hash_util.h" |
| 8 #include "components/sync/base/model_type.h" | 8 #include "components/sync/base/model_type.h" |
| 9 #include "components/sync/syncable/directory.h" | 9 #include "components/sync/syncable/directory.h" |
| 10 #include "components/sync/syncable/entry.h" | 10 #include "components/sync/syncable/entry.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 int64_t TestEntryFactory::CreateSyncedItem( | 151 int64_t TestEntryFactory::CreateSyncedItem( |
| 152 const std::string& name, | 152 const std::string& name, |
| 153 ModelType model_type, | 153 ModelType model_type, |
| 154 bool is_folder, | 154 bool is_folder, |
| 155 const sync_pb::EntitySpecifics& specifics) { | 155 const sync_pb::EntitySpecifics& specifics) { |
| 156 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); | 156 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
| 157 | 157 |
| 158 // Use the type root if it exists or the real root otherwise. | 158 // Use the type root if it exists or the real root otherwise. |
| 159 syncable::Entry root(&trans, syncable::GET_TYPE_ROOT, model_type); | 159 syncable::Entry root(&trans, syncable::GET_TYPE_ROOT, model_type); |
| 160 syncable::Id parent_id = root.good() ? root.GetId() : TestIdFactory::root(); | 160 syncable::Id parent_id = root.good() ? root.GetId() : TestIdFactory::root(); |
| 161 syncable::Id item_id(TestIdFactory::MakeServer(name)); | |
| 162 int64_t version = GetNextRevision(); | |
| 163 base::Time now = base::Time::Now(); | |
| 164 | 161 |
| 165 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name); | 162 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name); |
| 166 if (!entry.good()) { | 163 if (!entry.good()) { |
| 167 NOTREACHED(); | 164 NOTREACHED(); |
| 168 return syncable::kInvalidMetaHandle; | 165 return syncable::kInvalidMetaHandle; |
| 169 } | 166 } |
| 170 | 167 |
| 171 entry.PutId(item_id); | 168 PopulateEntry(parent_id, name, model_type, &entry); |
| 172 entry.PutCtime(now); | |
| 173 entry.PutMtime(now); | |
| 174 entry.PutUniqueClientTag(GenerateSyncableHash(model_type, name)); | |
| 175 entry.PutBaseVersion(version); | |
| 176 entry.PutIsUnsynced(false); | |
| 177 entry.PutNonUniqueName(name); | |
| 178 entry.PutIsDir(is_folder); | 169 entry.PutIsDir(is_folder); |
| 179 entry.PutIsDel(false); | |
| 180 entry.PutParentId(parent_id); | |
| 181 | |
| 182 entry.PutServerCtime(now); | |
| 183 entry.PutServerMtime(now); | |
| 184 entry.PutServerVersion(version); | |
| 185 entry.PutIsUnappliedUpdate(false); | |
| 186 entry.PutServerNonUniqueName(name); | |
| 187 entry.PutServerParentId(parent_id); | |
| 188 entry.PutServerIsDir(is_folder); | 170 entry.PutServerIsDir(is_folder); |
| 189 entry.PutServerIsDel(false); | |
| 190 | 171 |
| 191 // Only rewrite the default specifics inside the entry (which have the model | 172 // Only rewrite the default specifics inside the entry (which have the model |
| 192 // type marker already) if |specifics| actually contains data. | 173 // type marker already) if |specifics| actually contains data. |
| 193 if (specifics.ByteSize() > 0) { | 174 if (specifics.ByteSize() > 0) { |
| 194 entry.PutSpecifics(specifics); | 175 entry.PutSpecifics(specifics); |
| 195 entry.PutServerSpecifics(specifics); | 176 entry.PutServerSpecifics(specifics); |
| 196 } else { | 177 } else { |
| 197 entry.PutServerSpecifics(entry.GetSpecifics()); | 178 entry.PutServerSpecifics(entry.GetSpecifics()); |
| 198 } | 179 } |
| 199 | 180 |
| 200 return entry.GetMetahandle(); | 181 return entry.GetMetahandle(); |
| 201 } | 182 } |
| 202 | 183 |
| 184 int64_t TestEntryFactory::CreateTombstone(const std::string& name, |
| 185 ModelType model_type) { |
| 186 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); |
| 187 |
| 188 // Use the type root if it exists or the real root otherwise. |
| 189 syncable::Entry root(&trans, syncable::GET_TYPE_ROOT, model_type); |
| 190 syncable::Id parent_id = root.good() ? root.GetId() : TestIdFactory::root(); |
| 191 |
| 192 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name); |
| 193 if (!entry.good()) { |
| 194 NOTREACHED(); |
| 195 return syncable::kInvalidMetaHandle; |
| 196 } |
| 197 |
| 198 PopulateEntry(parent_id, name, model_type, &entry); |
| 199 entry.PutIsDel(true); |
| 200 entry.PutServerIsDel(true); |
| 201 return entry.GetMetahandle(); |
| 202 } |
| 203 |
| 203 int64_t TestEntryFactory::CreateTypeRootNode(ModelType model_type) { | 204 int64_t TestEntryFactory::CreateTypeRootNode(ModelType model_type) { |
| 204 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, syncable::UNITTEST, | 205 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, syncable::UNITTEST, |
| 205 directory_); | 206 directory_); |
| 206 sync_pb::EntitySpecifics specifics; | 207 sync_pb::EntitySpecifics specifics; |
| 207 AddDefaultFieldValue(model_type, &specifics); | 208 AddDefaultFieldValue(model_type, &specifics); |
| 208 syncable::ModelNeutralMutableEntry entry( | 209 syncable::ModelNeutralMutableEntry entry( |
| 209 &trans, syncable::CREATE_NEW_TYPE_ROOT, model_type); | 210 &trans, syncable::CREATE_NEW_TYPE_ROOT, model_type); |
| 210 DCHECK(entry.good()); | 211 DCHECK(entry.good()); |
| 211 entry.PutServerIsDir(true); | 212 entry.PutServerIsDir(true); |
| 212 entry.PutUniqueServerTag(ModelTypeToRootTag(model_type)); | 213 entry.PutUniqueServerTag(ModelTypeToRootTag(model_type)); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 NOTREACHED(); | 337 NOTREACHED(); |
| 337 return false; | 338 return false; |
| 338 } | 339 } |
| 339 return entry.GetIsUnappliedUpdate(); | 340 return entry.GetIsUnappliedUpdate(); |
| 340 } | 341 } |
| 341 | 342 |
| 342 int64_t TestEntryFactory::GetNextRevision() { | 343 int64_t TestEntryFactory::GetNextRevision() { |
| 343 return next_revision_++; | 344 return next_revision_++; |
| 344 } | 345 } |
| 345 | 346 |
| 347 void TestEntryFactory::PopulateEntry(const syncable::Id& parent_id, |
| 348 const std::string& name, |
| 349 ModelType model_type, |
| 350 MutableEntry* entry) { |
| 351 syncable::Id item_id(TestIdFactory::MakeServer(name)); |
| 352 int64_t version = GetNextRevision(); |
| 353 base::Time now = base::Time::Now(); |
| 354 |
| 355 entry->PutId(item_id); |
| 356 entry->PutCtime(now); |
| 357 entry->PutMtime(now); |
| 358 entry->PutUniqueClientTag(GenerateSyncableHash(model_type, name)); |
| 359 entry->PutBaseVersion(version); |
| 360 entry->PutIsUnsynced(false); |
| 361 entry->PutNonUniqueName(name); |
| 362 entry->PutIsDir(false); |
| 363 entry->PutIsDel(false); |
| 364 entry->PutParentId(parent_id); |
| 365 |
| 366 entry->PutServerCtime(now); |
| 367 entry->PutServerMtime(now); |
| 368 entry->PutServerVersion(version); |
| 369 entry->PutIsUnappliedUpdate(false); |
| 370 entry->PutServerNonUniqueName(name); |
| 371 entry->PutServerParentId(parent_id); |
| 372 entry->PutServerIsDir(false); |
| 373 entry->PutServerIsDel(false); |
| 374 } |
| 375 |
| 346 } // namespace syncer | 376 } // namespace syncer |
| OLD | NEW |