OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/engine/syncer_util.h" | 5 #include "chrome/browser/sync/engine/syncer_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 VLOG(2) << "Received a decryptable " | 355 VLOG(2) << "Received a decryptable " |
356 << syncable::ModelTypeToString(entry->GetServerModelType()) | 356 << syncable::ModelTypeToString(entry->GetServerModelType()) |
357 << " update, applying normally."; | 357 << " update, applying normally."; |
358 } else { | 358 } else { |
359 VLOG(2) << "Received an unencrypted " | 359 VLOG(2) << "Received an unencrypted " |
360 << syncable::ModelTypeToString(entry->GetServerModelType()) | 360 << syncable::ModelTypeToString(entry->GetServerModelType()) |
361 << " update, applying normally."; | 361 << " update, applying normally."; |
362 } | 362 } |
363 } | 363 } |
364 | 364 |
365 SyncerUtil::UpdateLocalDataFromServerData(trans, entry); | 365 if (!SyncerUtil::UpdateLocalDataFromServerData(trans, entry)) |
| 366 return FAILED_UPDATE; |
366 | 367 |
367 return SUCCESS; | 368 return SUCCESS; |
368 } | 369 } |
369 | 370 |
370 namespace { | 371 namespace { |
371 // Helper to synthesize a new-style sync_pb::EntitySpecifics for use locally, | 372 // Helper to synthesize a new-style sync_pb::EntitySpecifics for use locally, |
372 // when the server speaks only the old sync_pb::SyncEntity_BookmarkData-based | 373 // when the server speaks only the old sync_pb::SyncEntity_BookmarkData-based |
373 // protocol. | 374 // protocol. |
374 void UpdateBookmarkSpecifics(const std::string& singleton_tag, | 375 void UpdateBookmarkSpecifics(const std::string& singleton_tag, |
375 const std::string& url, | 376 const std::string& url, |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 CopyServerFields(entry, &new_entry); | 548 CopyServerFields(entry, &new_entry); |
548 ClearServerData(entry); | 549 ClearServerData(entry); |
549 | 550 |
550 VLOG(1) << "Splitting server information, local entry: " << *entry | 551 VLOG(1) << "Splitting server information, local entry: " << *entry |
551 << " server entry: " << new_entry; | 552 << " server entry: " << new_entry; |
552 } | 553 } |
553 | 554 |
554 // This function is called on an entry when we can update the user-facing data | 555 // This function is called on an entry when we can update the user-facing data |
555 // from the server data. | 556 // from the server data. |
556 // static | 557 // static |
557 void SyncerUtil::UpdateLocalDataFromServerData( | 558 bool SyncerUtil::UpdateLocalDataFromServerData( |
558 syncable::WriteTransaction* trans, | 559 syncable::WriteTransaction* trans, |
559 syncable::MutableEntry* entry) { | 560 syncable::MutableEntry* entry) { |
560 DCHECK(!entry->Get(IS_UNSYNCED)); | 561 DCHECK(!entry->Get(IS_UNSYNCED)); |
561 DCHECK(entry->Get(IS_UNAPPLIED_UPDATE)); | 562 DCHECK(entry->Get(IS_UNAPPLIED_UPDATE)); |
562 | 563 |
563 VLOG(2) << "Updating entry : " << *entry; | 564 VLOG(2) << "Updating entry : " << *entry; |
564 // Start by setting the properties that determine the model_type. | 565 // Start by setting the properties that determine the model_type. |
565 entry->Put(SPECIFICS, entry->Get(SERVER_SPECIFICS)); | 566 entry->Put(SPECIFICS, entry->Get(SERVER_SPECIFICS)); |
566 entry->Put(IS_DIR, entry->Get(SERVER_IS_DIR)); | 567 entry->Put(IS_DIR, entry->Get(SERVER_IS_DIR)); |
567 // This strange dance around the IS_DEL flag avoids problems when setting | 568 // This strange dance around the IS_DEL flag avoids problems when setting |
568 // the name. | 569 // the name. |
569 // TODO(chron): Is this still an issue? Unit test this codepath. | 570 // TODO(chron): Is this still an issue? Unit test this codepath. |
570 if (entry->Get(SERVER_IS_DEL)) { | 571 if (entry->Get(SERVER_IS_DEL)) { |
571 entry->Put(IS_DEL, true); | 572 entry->Put(IS_DEL, true); |
572 } else { | 573 } else { |
573 entry->Put(NON_UNIQUE_NAME, entry->Get(SERVER_NON_UNIQUE_NAME)); | 574 entry->Put(NON_UNIQUE_NAME, entry->Get(SERVER_NON_UNIQUE_NAME)); |
574 entry->Put(PARENT_ID, entry->Get(SERVER_PARENT_ID)); | 575 entry->Put(PARENT_ID, entry->Get(SERVER_PARENT_ID)); |
575 CHECK(entry->Put(IS_DEL, false)); | 576 if (!entry->Put(IS_DEL, false)) |
| 577 return false; |
576 Id new_predecessor = | 578 Id new_predecessor = |
577 entry->ComputePrevIdFromServerPosition(entry->Get(SERVER_PARENT_ID)); | 579 entry->ComputePrevIdFromServerPosition(entry->Get(SERVER_PARENT_ID)); |
578 CHECK(entry->PutPredecessor(new_predecessor)) | 580 if (!entry->PutPredecessor(new_predecessor)) |
579 << " Illegal predecessor after converting from server position."; | 581 return false; |
580 } | 582 } |
581 | 583 |
582 entry->Put(CTIME, entry->Get(SERVER_CTIME)); | 584 entry->Put(CTIME, entry->Get(SERVER_CTIME)); |
583 entry->Put(MTIME, entry->Get(SERVER_MTIME)); | 585 entry->Put(MTIME, entry->Get(SERVER_MTIME)); |
584 entry->Put(BASE_VERSION, entry->Get(SERVER_VERSION)); | 586 entry->Put(BASE_VERSION, entry->Get(SERVER_VERSION)); |
585 entry->Put(IS_DEL, entry->Get(SERVER_IS_DEL)); | 587 entry->Put(IS_DEL, entry->Get(SERVER_IS_DEL)); |
586 entry->Put(IS_UNAPPLIED_UPDATE, false); | 588 entry->Put(IS_UNAPPLIED_UPDATE, false); |
| 589 |
| 590 return true; |
587 } | 591 } |
588 | 592 |
589 // static | 593 // static |
590 VerifyCommitResult SyncerUtil::ValidateCommitEntry( | 594 VerifyCommitResult SyncerUtil::ValidateCommitEntry( |
591 syncable::Entry* entry) { | 595 syncable::Entry* entry) { |
592 syncable::Id id = entry->Get(ID); | 596 syncable::Id id = entry->Get(ID); |
593 if (id == entry->Get(PARENT_ID)) { | 597 if (id == entry->Get(PARENT_ID)) { |
594 CHECK(id.IsRoot()) << "Non-root item is self parenting." << *entry; | 598 CHECK(id.IsRoot()) << "Non-root item is self parenting." << *entry; |
595 // If the root becomes unsynced it can cause us problems. | 599 // If the root becomes unsynced it can cause us problems. |
596 LOG(ERROR) << "Root item became unsynced " << *entry; | 600 LOG(ERROR) << "Root item became unsynced " << *entry; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 if (update.version() < target->Get(SERVER_VERSION)) { | 830 if (update.version() < target->Get(SERVER_VERSION)) { |
827 LOG(WARNING) << "Update older than current server version for " | 831 LOG(WARNING) << "Update older than current server version for " |
828 << *target << " Update:" | 832 << *target << " Update:" |
829 << SyncerProtoUtil::SyncEntityDebugString(update); | 833 << SyncerProtoUtil::SyncEntityDebugString(update); |
830 return VERIFY_SUCCESS; // Expected in new sync protocol. | 834 return VERIFY_SUCCESS; // Expected in new sync protocol. |
831 } | 835 } |
832 return VERIFY_UNDECIDED; | 836 return VERIFY_UNDECIDED; |
833 } | 837 } |
834 | 838 |
835 } // namespace browser_sync | 839 } // namespace browser_sync |
OLD | NEW |