| 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/fake_server.h" | 5 #include "sync/test/fake_server/fake_server.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 185 |
| 186 bool FakeServer::CreatePermanentBookmarkFolder(const std::string& server_tag, | 186 bool FakeServer::CreatePermanentBookmarkFolder(const std::string& server_tag, |
| 187 const std::string& name) { | 187 const std::string& name) { |
| 188 DCHECK(thread_checker_.CalledOnValidThread()); | 188 DCHECK(thread_checker_.CalledOnValidThread()); |
| 189 scoped_ptr<FakeServerEntity> entity = | 189 scoped_ptr<FakeServerEntity> entity = |
| 190 PermanentEntity::Create(syncer::BOOKMARKS, server_tag, name, | 190 PermanentEntity::Create(syncer::BOOKMARKS, server_tag, name, |
| 191 ModelTypeToRootTag(syncer::BOOKMARKS)); | 191 ModelTypeToRootTag(syncer::BOOKMARKS)); |
| 192 if (!entity) | 192 if (!entity) |
| 193 return false; | 193 return false; |
| 194 | 194 |
| 195 SaveEntity(entity.Pass()); | 195 SaveEntity(std::move(entity)); |
| 196 return true; | 196 return true; |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool FakeServer::CreateDefaultPermanentItems() { | 199 bool FakeServer::CreateDefaultPermanentItems() { |
| 200 // Permanent folders are always required for Bookmarks (hierarchical | 200 // Permanent folders are always required for Bookmarks (hierarchical |
| 201 // structure) and Nigori (data stored in permanent root folder). | 201 // structure) and Nigori (data stored in permanent root folder). |
| 202 ModelTypeSet permanent_folder_types = | 202 ModelTypeSet permanent_folder_types = |
| 203 ModelTypeSet(syncer::BOOKMARKS, syncer::NIGORI); | 203 ModelTypeSet(syncer::BOOKMARKS, syncer::NIGORI); |
| 204 | 204 |
| 205 for (ModelTypeSet::Iterator it = permanent_folder_types.First(); it.Good(); | 205 for (ModelTypeSet::Iterator it = permanent_folder_types.First(); it.Good(); |
| 206 it.Inc()) { | 206 it.Inc()) { |
| 207 ModelType model_type = it.Get(); | 207 ModelType model_type = it.Get(); |
| 208 | 208 |
| 209 scoped_ptr<FakeServerEntity> top_level_entity = | 209 scoped_ptr<FakeServerEntity> top_level_entity = |
| 210 PermanentEntity::CreateTopLevel(model_type); | 210 PermanentEntity::CreateTopLevel(model_type); |
| 211 if (!top_level_entity) { | 211 if (!top_level_entity) { |
| 212 return false; | 212 return false; |
| 213 } | 213 } |
| 214 SaveEntity(top_level_entity.Pass()); | 214 SaveEntity(std::move(top_level_entity)); |
| 215 | 215 |
| 216 if (model_type == syncer::BOOKMARKS) { | 216 if (model_type == syncer::BOOKMARKS) { |
| 217 if (!CreatePermanentBookmarkFolder(kBookmarkBarFolderServerTag, | 217 if (!CreatePermanentBookmarkFolder(kBookmarkBarFolderServerTag, |
| 218 kBookmarkBarFolderName)) | 218 kBookmarkBarFolderName)) |
| 219 return false; | 219 return false; |
| 220 if (!CreatePermanentBookmarkFolder(kOtherBookmarksFolderServerTag, | 220 if (!CreatePermanentBookmarkFolder(kOtherBookmarksFolderServerTag, |
| 221 kOtherBookmarksFolderName)) | 221 kOtherBookmarksFolderName)) |
| 222 return false; | 222 return false; |
| 223 } | 223 } |
| 224 } | 224 } |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } | 402 } |
| 403 } | 403 } |
| 404 | 404 |
| 405 if (!entity) { | 405 if (!entity) { |
| 406 // TODO(pvalenzuela): Add logging so that it is easier to determine why | 406 // TODO(pvalenzuela): Add logging so that it is easier to determine why |
| 407 // creation failed. | 407 // creation failed. |
| 408 return string(); | 408 return string(); |
| 409 } | 409 } |
| 410 | 410 |
| 411 const std::string id = entity->GetId(); | 411 const std::string id = entity->GetId(); |
| 412 SaveEntity(entity.Pass()); | 412 SaveEntity(std::move(entity)); |
| 413 BuildEntryResponseForSuccessfulCommit(id, entry_response); | 413 BuildEntryResponseForSuccessfulCommit(id, entry_response); |
| 414 return id; | 414 return id; |
| 415 } | 415 } |
| 416 | 416 |
| 417 void FakeServer::BuildEntryResponseForSuccessfulCommit( | 417 void FakeServer::BuildEntryResponseForSuccessfulCommit( |
| 418 const std::string& entity_id, | 418 const std::string& entity_id, |
| 419 sync_pb::CommitResponse_EntryResponse* entry_response) { | 419 sync_pb::CommitResponse_EntryResponse* entry_response) { |
| 420 EntityMap::const_iterator iter = entities_.find(entity_id); | 420 EntityMap::const_iterator iter = entities_.find(entity_id); |
| 421 CHECK(iter != entities_.end()); | 421 CHECK(iter != entities_.end()); |
| 422 const FakeServerEntity& entity = *iter->second; | 422 const FakeServerEntity& entity = *iter->second; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 if (!dictionary->GetList(ModelTypeToString(entity.GetModelType()), | 525 if (!dictionary->GetList(ModelTypeToString(entity.GetModelType()), |
| 526 &list_value)) { | 526 &list_value)) { |
| 527 return scoped_ptr<base::DictionaryValue>(); | 527 return scoped_ptr<base::DictionaryValue>(); |
| 528 } | 528 } |
| 529 // TODO(pvalenzuela): Store more data for each entity so additional | 529 // TODO(pvalenzuela): Store more data for each entity so additional |
| 530 // verification can be performed. One example of additional verification | 530 // verification can be performed. One example of additional verification |
| 531 // is checking the correctness of the bookmark hierarchy. | 531 // is checking the correctness of the bookmark hierarchy. |
| 532 list_value->Append(new base::StringValue(entity.GetName())); | 532 list_value->Append(new base::StringValue(entity.GetName())); |
| 533 } | 533 } |
| 534 | 534 |
| 535 return dictionary.Pass(); | 535 return dictionary; |
| 536 } | 536 } |
| 537 | 537 |
| 538 std::vector<sync_pb::SyncEntity> FakeServer::GetSyncEntitiesByModelType( | 538 std::vector<sync_pb::SyncEntity> FakeServer::GetSyncEntitiesByModelType( |
| 539 ModelType model_type) { | 539 ModelType model_type) { |
| 540 std::vector<sync_pb::SyncEntity> sync_entities; | 540 std::vector<sync_pb::SyncEntity> sync_entities; |
| 541 DCHECK(thread_checker_.CalledOnValidThread()); | 541 DCHECK(thread_checker_.CalledOnValidThread()); |
| 542 for (EntityMap::const_iterator it = entities_.begin(); it != entities_.end(); | 542 for (EntityMap::const_iterator it = entities_.begin(); it != entities_.end(); |
| 543 ++it) { | 543 ++it) { |
| 544 const FakeServerEntity& entity = *it->second; | 544 const FakeServerEntity& entity = *it->second; |
| 545 if (!IsDeletedOrPermanent(entity) && entity.GetModelType() == model_type) { | 545 if (!IsDeletedOrPermanent(entity) && entity.GetModelType() == model_type) { |
| 546 sync_pb::SyncEntity sync_entity; | 546 sync_pb::SyncEntity sync_entity; |
| 547 entity.SerializeAsProto(&sync_entity); | 547 entity.SerializeAsProto(&sync_entity); |
| 548 sync_entities.push_back(sync_entity); | 548 sync_entities.push_back(sync_entity); |
| 549 } | 549 } |
| 550 } | 550 } |
| 551 return sync_entities; | 551 return sync_entities; |
| 552 } | 552 } |
| 553 | 553 |
| 554 void FakeServer::InjectEntity(scoped_ptr<FakeServerEntity> entity) { | 554 void FakeServer::InjectEntity(scoped_ptr<FakeServerEntity> entity) { |
| 555 DCHECK(thread_checker_.CalledOnValidThread()); | 555 DCHECK(thread_checker_.CalledOnValidThread()); |
| 556 SaveEntity(entity.Pass()); | 556 SaveEntity(std::move(entity)); |
| 557 } | 557 } |
| 558 | 558 |
| 559 bool FakeServer::ModifyEntitySpecifics( | 559 bool FakeServer::ModifyEntitySpecifics( |
| 560 const std::string& id, | 560 const std::string& id, |
| 561 const sync_pb::EntitySpecifics& updated_specifics) { | 561 const sync_pb::EntitySpecifics& updated_specifics) { |
| 562 EntityMap::const_iterator iter = entities_.find(id); | 562 EntityMap::const_iterator iter = entities_.find(id); |
| 563 if (iter == entities_.end() || | 563 if (iter == entities_.end() || |
| 564 iter->second->GetModelType() != | 564 iter->second->GetModelType() != |
| 565 GetModelTypeFromSpecifics(updated_specifics)) { | 565 GetModelTypeFromSpecifics(updated_specifics)) { |
| 566 return false; | 566 return false; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 DCHECK(thread_checker_.CalledOnValidThread()); | 706 DCHECK(thread_checker_.CalledOnValidThread()); |
| 707 return weak_ptr_factory_.GetWeakPtr(); | 707 return weak_ptr_factory_.GetWeakPtr(); |
| 708 } | 708 } |
| 709 | 709 |
| 710 std::string FakeServer::GetStoreBirthday() const { | 710 std::string FakeServer::GetStoreBirthday() const { |
| 711 DCHECK(thread_checker_.CalledOnValidThread()); | 711 DCHECK(thread_checker_.CalledOnValidThread()); |
| 712 return base::Int64ToString(store_birthday_); | 712 return base::Int64ToString(store_birthday_); |
| 713 } | 713 } |
| 714 | 714 |
| 715 } // namespace fake_server | 715 } // namespace fake_server |
| OLD | NEW |