Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: components/sync/test/fake_server/fake_server.cc

Issue 2948303002: [Sync] Sanity test for UserEvents. (Closed)
Patch Set: Rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/BUILD.gn ('k') | components/sync/test/fake_server/unique_client_entity.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/test/fake_server/fake_server.h" 5 #include "components/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 <utility> 10 #include <utility>
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 string FakeServer::CommitEntity( 363 string FakeServer::CommitEntity(
364 const sync_pb::SyncEntity& client_entity, 364 const sync_pb::SyncEntity& client_entity,
365 sync_pb::CommitResponse_EntryResponse* entry_response, 365 sync_pb::CommitResponse_EntryResponse* entry_response,
366 const string& client_guid, 366 const string& client_guid,
367 const string& parent_id) { 367 const string& parent_id) {
368 if (client_entity.version() == 0 && client_entity.deleted()) { 368 if (client_entity.version() == 0 && client_entity.deleted()) {
369 return string(); 369 return string();
370 } 370 }
371 371
372 std::unique_ptr<FakeServerEntity> entity; 372 std::unique_ptr<FakeServerEntity> entity;
373 syncer::ModelType type = GetModelType(client_entity);
373 if (client_entity.deleted()) { 374 if (client_entity.deleted()) {
374 entity = TombstoneEntity::Create(client_entity.id_string(), 375 entity = TombstoneEntity::Create(client_entity.id_string(),
375 client_entity.client_defined_unique_tag()); 376 client_entity.client_defined_unique_tag());
376 DeleteChildren(client_entity.id_string()); 377 DeleteChildren(client_entity.id_string());
377 } else if (GetModelType(client_entity) == syncer::NIGORI) { 378 } else if (type == syncer::NIGORI) {
378 // NIGORI is the only permanent item type that should be updated by the 379 // NIGORI is the only permanent item type that should be updated by the
379 // client. 380 // client.
380 EntityMap::const_iterator iter = entities_.find(client_entity.id_string()); 381 EntityMap::const_iterator iter = entities_.find(client_entity.id_string());
381 CHECK(iter != entities_.end()); 382 CHECK(iter != entities_.end());
382 entity = PermanentEntity::CreateUpdatedNigoriEntity(client_entity, 383 entity = PermanentEntity::CreateUpdatedNigoriEntity(client_entity,
383 *iter->second); 384 *iter->second);
384 } else if (client_entity.has_client_defined_unique_tag()) { 385 } else if (type == syncer::BOOKMARKS) {
385 entity = UniqueClientEntity::Create(client_entity);
386 } else {
387 // TODO(pvalenzuela): Validate entity's parent ID. 386 // TODO(pvalenzuela): Validate entity's parent ID.
388 EntityMap::const_iterator iter = entities_.find(client_entity.id_string()); 387 EntityMap::const_iterator iter = entities_.find(client_entity.id_string());
389 if (iter != entities_.end()) { 388 if (iter != entities_.end()) {
390 entity = BookmarkEntity::CreateUpdatedVersion(client_entity, 389 entity = BookmarkEntity::CreateUpdatedVersion(client_entity,
391 *iter->second, parent_id); 390 *iter->second, parent_id);
392 } else { 391 } else {
393 entity = BookmarkEntity::CreateNew(client_entity, parent_id, client_guid); 392 entity = BookmarkEntity::CreateNew(client_entity, parent_id, client_guid);
394 } 393 }
395 } 394 } else {
396 395 entity = UniqueClientEntity::Create(client_entity);
397 if (!entity) {
398 // TODO(pvalenzuela): Add logging so that it is easier to determine why
399 // creation failed.
400 return string();
401 } 396 }
402 397
403 const std::string id = entity->id(); 398 const std::string id = entity->id();
404 SaveEntity(std::move(entity)); 399 SaveEntity(std::move(entity));
405 BuildEntryResponseForSuccessfulCommit(id, entry_response); 400 BuildEntryResponseForSuccessfulCommit(id, entry_response);
406 return id; 401 return id;
407 } 402 }
408 403
409 void FakeServer::BuildEntryResponseForSuccessfulCommit( 404 void FakeServer::BuildEntryResponseForSuccessfulCommit(
410 const std::string& entity_id, 405 const std::string& entity_id,
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 DCHECK(thread_checker_.CalledOnValidThread()); 696 DCHECK(thread_checker_.CalledOnValidThread());
702 return weak_ptr_factory_.GetWeakPtr(); 697 return weak_ptr_factory_.GetWeakPtr();
703 } 698 }
704 699
705 std::string FakeServer::GetStoreBirthday() const { 700 std::string FakeServer::GetStoreBirthday() const {
706 DCHECK(thread_checker_.CalledOnValidThread()); 701 DCHECK(thread_checker_.CalledOnValidThread());
707 return base::Int64ToString(store_birthday_); 702 return base::Int64ToString(store_birthday_);
708 } 703 }
709 704
710 } // namespace fake_server 705 } // namespace fake_server
OLDNEW
« no previous file with comments | « chrome/test/BUILD.gn ('k') | components/sync/test/fake_server/unique_client_entity.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698