Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "sync/engine/syncer_util.h" | 5 #include "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> |
| 11 | 11 |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "sync/engine/conflict_resolver.h" | 14 #include "sync/engine/conflict_resolver.h" |
| 15 #include "sync/engine/syncer_proto_util.h" | 15 #include "sync/engine/syncer_proto_util.h" |
| 16 #include "sync/engine/syncer_types.h" | 16 #include "sync/engine/syncer_types.h" |
| 17 #include "sync/engine/syncproto.h" | |
| 18 #include "sync/internal_api/public/base/model_type.h" | 17 #include "sync/internal_api/public/base/model_type.h" |
| 19 #include "sync/protocol/bookmark_specifics.pb.h" | 18 #include "sync/protocol/bookmark_specifics.pb.h" |
| 20 #include "sync/protocol/nigori_specifics.pb.h" | 19 #include "sync/protocol/nigori_specifics.pb.h" |
| 21 #include "sync/protocol/password_specifics.pb.h" | 20 #include "sync/protocol/password_specifics.pb.h" |
| 22 #include "sync/protocol/sync.pb.h" | 21 #include "sync/protocol/sync.pb.h" |
| 23 #include "sync/syncable/directory.h" | 22 #include "sync/syncable/directory.h" |
| 24 #include "sync/syncable/entry.h" | 23 #include "sync/syncable/entry.h" |
| 25 #include "sync/syncable/mutable_entry.h" | 24 #include "sync/syncable/mutable_entry.h" |
| 26 #include "sync/syncable/nigori_util.h" | 25 #include "sync/syncable/nigori_util.h" |
| 27 #include "sync/syncable/read_transaction.h" | 26 #include "sync/syncable/read_transaction.h" |
| 28 #include "sync/syncable/syncable_changes_version.h" | 27 #include "sync/syncable/syncable_changes_version.h" |
| 28 #include "sync/syncable/syncable_proto_util.h" | |
| 29 #include "sync/syncable/syncable_util.h" | 29 #include "sync/syncable/syncable_util.h" |
| 30 #include "sync/syncable/write_transaction.h" | 30 #include "sync/syncable/write_transaction.h" |
| 31 #include "sync/util/cryptographer.h" | 31 #include "sync/util/cryptographer.h" |
| 32 #include "sync/util/time.h" | 32 #include "sync/util/time.h" |
| 33 | 33 |
| 34 namespace syncer { | 34 namespace syncer { |
| 35 | 35 |
| 36 using syncable::BASE_VERSION; | 36 using syncable::BASE_VERSION; |
| 37 using syncable::CHANGES_VERSION; | 37 using syncable::CHANGES_VERSION; |
| 38 using syncable::CREATE_NEW_UPDATE_ITEM; | 38 using syncable::CREATE_NEW_UPDATE_ITEM; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 64 using syncable::SERVER_SPECIFICS; | 64 using syncable::SERVER_SPECIFICS; |
| 65 using syncable::SERVER_VERSION; | 65 using syncable::SERVER_VERSION; |
| 66 using syncable::UNIQUE_CLIENT_TAG; | 66 using syncable::UNIQUE_CLIENT_TAG; |
| 67 using syncable::UNIQUE_SERVER_TAG; | 67 using syncable::UNIQUE_SERVER_TAG; |
| 68 using syncable::SPECIFICS; | 68 using syncable::SPECIFICS; |
| 69 using syncable::SYNCER; | 69 using syncable::SYNCER; |
| 70 using syncable::WriteTransaction; | 70 using syncable::WriteTransaction; |
| 71 | 71 |
| 72 syncable::Id FindLocalIdToUpdate( | 72 syncable::Id FindLocalIdToUpdate( |
| 73 syncable::BaseTransaction* trans, | 73 syncable::BaseTransaction* trans, |
| 74 const SyncEntity& update) { | 74 const sync_pb::SyncEntity& update) { |
| 75 // Expected entry points of this function: | 75 // Expected entry points of this function: |
| 76 // SyncEntity has NOT been applied to SERVER fields. | 76 // SyncEntity has NOT been applied to SERVER fields. |
| 77 // SyncEntity has NOT been applied to LOCAL fields. | 77 // SyncEntity has NOT been applied to LOCAL fields. |
| 78 // DB has not yet been modified, no entries created for this update. | 78 // DB has not yet been modified, no entries created for this update. |
| 79 | 79 |
| 80 const std::string& client_id = trans->directory()->cache_guid(); | 80 const std::string& client_id = trans->directory()->cache_guid(); |
| 81 syncable::Id update_id = SyncableIdFromProto(update.id_string()); | |
| 81 | 82 |
| 82 if (update.has_client_defined_unique_tag() && | 83 if (update.has_client_defined_unique_tag() && |
| 83 !update.client_defined_unique_tag().empty()) { | 84 !update.client_defined_unique_tag().empty()) { |
| 84 // When a server sends down a client tag, the following cases can occur: | 85 // When a server sends down a client tag, the following cases can occur: |
| 85 // 1) Client has entry for tag already, ID is server style, matches | 86 // 1) Client has entry for tag already, ID is server style, matches |
| 86 // 2) Client has entry for tag already, ID is server, doesn't match. | 87 // 2) Client has entry for tag already, ID is server, doesn't match. |
| 87 // 3) Client has entry for tag already, ID is local, (never matches) | 88 // 3) Client has entry for tag already, ID is local, (never matches) |
| 88 // 4) Client has no entry for tag | 89 // 4) Client has no entry for tag |
| 89 | 90 |
| 90 // Case 1, we don't have to do anything since the update will | 91 // Case 1, we don't have to do anything since the update will |
| 91 // work just fine. Update will end up in the proper entry, via ID lookup. | 92 // work just fine. Update will end up in the proper entry, via ID lookup. |
| 92 // Case 2 - Happens very rarely due to lax enforcement of client tags | 93 // Case 2 - Happens very rarely due to lax enforcement of client tags |
| 93 // on the server, if two clients commit the same tag at the same time. | 94 // on the server, if two clients commit the same tag at the same time. |
| 94 // When this happens, we pick the lexically-least ID and ignore all other | 95 // When this happens, we pick the lexically-least ID and ignore all other |
| 95 // items. | 96 // items. |
| 96 // Case 3 - We need to replace the local ID with the server ID so that | 97 // Case 3 - We need to replace the local ID with the server ID so that |
| 97 // this update gets targeted at the correct local entry; we expect conflict | 98 // this update gets targeted at the correct local entry; we expect conflict |
| 98 // resolution to occur. | 99 // resolution to occur. |
| 99 // Case 4 - Perfect. Same as case 1. | 100 // Case 4 - Perfect. Same as case 1. |
| 100 | 101 |
| 101 syncable::Entry local_entry(trans, syncable::GET_BY_CLIENT_TAG, | 102 syncable::Entry local_entry(trans, syncable::GET_BY_CLIENT_TAG, |
| 102 update.client_defined_unique_tag()); | 103 update.client_defined_unique_tag()); |
| 103 | 104 |
| 104 // The SyncAPI equivalent of this function will return !good if IS_DEL. | 105 // The SyncAPI equivalent of this function will return !good if IS_DEL. |
| 105 // The syncable version will return good even if IS_DEL. | 106 // The syncable version will return good even if IS_DEL. |
| 106 // TODO(chron): Unit test the case with IS_DEL and make sure. | 107 // TODO(chron): Unit test the case with IS_DEL and make sure. |
| 107 if (local_entry.good()) { | 108 if (local_entry.good()) { |
| 108 if (local_entry.Get(ID).ServerKnows()) { | 109 if (local_entry.Get(ID).ServerKnows()) { |
| 109 if (local_entry.Get(ID) != update.id()) { | 110 if (local_entry.Get(ID) != update_id) { |
| 110 // Case 2. | 111 // Case 2. |
| 111 LOG(WARNING) << "Duplicated client tag."; | 112 LOG(WARNING) << "Duplicated client tag."; |
| 112 if (local_entry.Get(ID) < update.id()) { | 113 if (local_entry.Get(ID) < update_id) { |
| 113 // Signal an error; drop this update on the floor. Note that | 114 // Signal an error; drop this update on the floor. Note that |
| 114 // we don't server delete the item, because we don't allow it to | 115 // we don't server delete the item, because we don't allow it to |
| 115 // exist locally at all. So the item will remain orphaned on | 116 // exist locally at all. So the item will remain orphaned on |
| 116 // the server, and we won't pay attention to it. | 117 // the server, and we won't pay attention to it. |
| 117 return syncable::GetNullId(); | 118 return syncable::GetNullId(); |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 // Target this change to the existing local entry; later, | 121 // Target this change to the existing local entry; later, |
| 121 // we'll change the ID of the local entry to update.id() | 122 // we'll change the ID of the local entry to update_id |
| 122 // if needed. | 123 // if needed. |
| 123 return local_entry.Get(ID); | 124 return local_entry.Get(ID); |
| 124 } else { | 125 } else { |
| 125 // Case 3: We have a local entry with the same client tag. | 126 // Case 3: We have a local entry with the same client tag. |
| 126 // We should change the ID of the local entry to the server entry. | 127 // We should change the ID of the local entry to the server entry. |
| 127 // This will result in an server ID with base version == 0, but that's | 128 // This will result in an server ID with base version == 0, but that's |
| 128 // a legal state for an item with a client tag. By changing the ID, | 129 // a legal state for an item with a client tag. By changing the ID, |
| 129 // update will now be applied to local_entry. | 130 // update will now be applied to local_entry. |
| 130 DCHECK(0 == local_entry.Get(BASE_VERSION) || | 131 DCHECK(0 == local_entry.Get(BASE_VERSION) || |
| 131 CHANGES_VERSION == local_entry.Get(BASE_VERSION)); | 132 CHANGES_VERSION == local_entry.Get(BASE_VERSION)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 DCHECK_LE(old_version, 0); | 166 DCHECK_LE(old_version, 0); |
| 166 DCHECK_GT(new_version, 0); | 167 DCHECK_GT(new_version, 0); |
| 167 // Otherwise setting the base version could cause a consistency failure. | 168 // Otherwise setting the base version could cause a consistency failure. |
| 168 // An entry should never be version 0 and SYNCED. | 169 // An entry should never be version 0 and SYNCED. |
| 169 DCHECK(local_entry.Get(IS_UNSYNCED)); | 170 DCHECK(local_entry.Get(IS_UNSYNCED)); |
| 170 | 171 |
| 171 // Just a quick sanity check. | 172 // Just a quick sanity check. |
| 172 DCHECK(!local_entry.Get(ID).ServerKnows()); | 173 DCHECK(!local_entry.Get(ID).ServerKnows()); |
| 173 | 174 |
| 174 DVLOG(1) << "Reuniting lost commit response IDs. server id: " | 175 DVLOG(1) << "Reuniting lost commit response IDs. server id: " |
| 175 << update.id() << " local id: " << local_entry.Get(ID) | 176 << update_id << " local id: " << local_entry.Get(ID) |
| 176 << " new version: " << new_version; | 177 << " new version: " << new_version; |
| 177 | 178 |
| 178 return local_entry.Get(ID); | 179 return local_entry.Get(ID); |
| 179 } | 180 } |
| 180 } | 181 } |
| 181 // Fallback: target an entry having the server ID, creating one if needed. | 182 // Fallback: target an entry having the server ID, creating one if needed. |
| 182 return update.id(); | 183 return update_id; |
| 183 } | 184 } |
| 184 | 185 |
| 185 UpdateAttemptResponse AttemptToUpdateEntry( | 186 UpdateAttemptResponse AttemptToUpdateEntry( |
| 186 syncable::WriteTransaction* const trans, | 187 syncable::WriteTransaction* const trans, |
| 187 syncable::MutableEntry* const entry, | 188 syncable::MutableEntry* const entry, |
| 188 ConflictResolver* resolver, | 189 ConflictResolver* resolver, |
| 189 Cryptographer* cryptographer) { | 190 Cryptographer* cryptographer) { |
| 190 CHECK(entry->good()); | 191 CHECK(entry->good()); |
| 191 if (!entry->Get(IS_UNAPPLIED_UPDATE)) | 192 if (!entry->Get(IS_UNAPPLIED_UPDATE)) |
| 192 return SUCCESS; // No work to do. | 193 return SUCCESS; // No work to do. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 if (!favicon_bytes.empty()) | 335 if (!favicon_bytes.empty()) |
| 335 bookmark->set_favicon(favicon_bytes); | 336 bookmark->set_favicon(favicon_bytes); |
| 336 local_entry->Put(SERVER_SPECIFICS, pb); | 337 local_entry->Put(SERVER_SPECIFICS, pb); |
| 337 } | 338 } |
| 338 | 339 |
| 339 } // namespace | 340 } // namespace |
| 340 | 341 |
| 341 // Pass in name and checksum because of UTF8 conversion. | 342 // Pass in name and checksum because of UTF8 conversion. |
| 342 void UpdateServerFieldsFromUpdate( | 343 void UpdateServerFieldsFromUpdate( |
| 343 MutableEntry* target, | 344 MutableEntry* target, |
| 344 const SyncEntity& update, | 345 const sync_pb::SyncEntity& update, |
| 345 const std::string& name) { | 346 const std::string& name) { |
| 346 if (update.deleted()) { | 347 if (update.deleted()) { |
| 347 if (target->Get(SERVER_IS_DEL)) { | 348 if (target->Get(SERVER_IS_DEL)) { |
| 348 // If we already think the item is server-deleted, we're done. | 349 // If we already think the item is server-deleted, we're done. |
| 349 // Skipping these cases prevents our committed deletions from coming | 350 // Skipping these cases prevents our committed deletions from coming |
| 350 // back and overriding subsequent undeletions. For non-deleted items, | 351 // back and overriding subsequent undeletions. For non-deleted items, |
| 351 // the version number check has a similar effect. | 352 // the version number check has a similar effect. |
| 352 return; | 353 return; |
| 353 } | 354 } |
| 354 // The server returns very lightweight replies for deletions, so we don't | 355 // The server returns very lightweight replies for deletions, so we don't |
| 355 // clobber a bunch of fields on delete. | 356 // clobber a bunch of fields on delete. |
| 356 target->Put(SERVER_IS_DEL, true); | 357 target->Put(SERVER_IS_DEL, true); |
| 357 if (!target->Get(UNIQUE_CLIENT_TAG).empty()) { | 358 if (!target->Get(UNIQUE_CLIENT_TAG).empty()) { |
| 358 // Items identified by the client unique tag are undeletable; when | 359 // Items identified by the client unique tag are undeletable; when |
| 359 // they're deleted, they go back to version 0. | 360 // they're deleted, they go back to version 0. |
| 360 target->Put(SERVER_VERSION, 0); | 361 target->Put(SERVER_VERSION, 0); |
| 361 } else { | 362 } else { |
| 362 // Otherwise, fake a server version by bumping the local number. | 363 // Otherwise, fake a server version by bumping the local number. |
| 363 target->Put(SERVER_VERSION, | 364 target->Put(SERVER_VERSION, |
| 364 std::max(target->Get(SERVER_VERSION), | 365 std::max(target->Get(SERVER_VERSION), |
| 365 target->Get(BASE_VERSION)) + 1); | 366 target->Get(BASE_VERSION)) + 1); |
| 366 } | 367 } |
| 367 target->Put(IS_UNAPPLIED_UPDATE, true); | 368 target->Put(IS_UNAPPLIED_UPDATE, true); |
| 368 return; | 369 return; |
| 369 } | 370 } |
| 370 | 371 |
| 371 DCHECK(target->Get(ID) == update.id()) | 372 DCHECK(target->Get(ID) == SyncableIdFromProto(update.id_string())) |
|
akalin
2012/07/11 01:42:22
DCHECK_EQ?
| |
| 372 << "ID Changing not supported here"; | 373 << "ID Changing not supported here"; |
| 373 target->Put(SERVER_PARENT_ID, update.parent_id()); | 374 target->Put(SERVER_PARENT_ID, SyncableIdFromProto(update.parent_id_string())); |
| 374 target->Put(SERVER_NON_UNIQUE_NAME, name); | 375 target->Put(SERVER_NON_UNIQUE_NAME, name); |
| 375 target->Put(SERVER_VERSION, update.version()); | 376 target->Put(SERVER_VERSION, update.version()); |
| 376 target->Put(SERVER_CTIME, ProtoTimeToTime(update.ctime())); | 377 target->Put(SERVER_CTIME, ProtoTimeToTime(update.ctime())); |
| 377 target->Put(SERVER_MTIME, ProtoTimeToTime(update.mtime())); | 378 target->Put(SERVER_MTIME, ProtoTimeToTime(update.mtime())); |
| 378 target->Put(SERVER_IS_DIR, update.IsFolder()); | 379 target->Put(SERVER_IS_DIR, IsFolder(update)); |
| 379 if (update.has_server_defined_unique_tag()) { | 380 if (update.has_server_defined_unique_tag()) { |
| 380 const std::string& tag = update.server_defined_unique_tag(); | 381 const std::string& tag = update.server_defined_unique_tag(); |
| 381 target->Put(UNIQUE_SERVER_TAG, tag); | 382 target->Put(UNIQUE_SERVER_TAG, tag); |
| 382 } | 383 } |
| 383 if (update.has_client_defined_unique_tag()) { | 384 if (update.has_client_defined_unique_tag()) { |
| 384 const std::string& tag = update.client_defined_unique_tag(); | 385 const std::string& tag = update.client_defined_unique_tag(); |
| 385 target->Put(UNIQUE_CLIENT_TAG, tag); | 386 target->Put(UNIQUE_CLIENT_TAG, tag); |
| 386 } | 387 } |
| 387 // Store the datatype-specific part as a protobuf. | 388 // Store the datatype-specific part as a protobuf. |
| 388 if (update.has_specifics()) { | 389 if (update.has_specifics()) { |
| 389 DCHECK(update.GetModelType() != syncer::UNSPECIFIED) | 390 DCHECK(GetModelType(update) != UNSPECIFIED) |
|
akalin
2012/07/11 01:42:22
DCHECK_NE?
| |
| 390 << "Storing unrecognized datatype in sync database."; | 391 << "Storing unrecognized datatype in sync database."; |
| 391 target->Put(SERVER_SPECIFICS, update.specifics()); | 392 target->Put(SERVER_SPECIFICS, update.specifics()); |
| 392 } else if (update.has_bookmarkdata()) { | 393 } else if (update.has_bookmarkdata()) { |
| 393 // Legacy protocol response for bookmark data. | 394 // Legacy protocol response for bookmark data. |
| 394 const SyncEntity::BookmarkData& bookmark = update.bookmarkdata(); | 395 const sync_pb::SyncEntity::BookmarkData& bookmark = update.bookmarkdata(); |
| 395 UpdateBookmarkSpecifics(update.server_defined_unique_tag(), | 396 UpdateBookmarkSpecifics(update.server_defined_unique_tag(), |
| 396 bookmark.bookmark_url(), | 397 bookmark.bookmark_url(), |
| 397 bookmark.bookmark_favicon(), | 398 bookmark.bookmark_favicon(), |
| 398 target); | 399 target); |
| 399 } | 400 } |
| 400 if (update.has_position_in_parent()) | 401 if (update.has_position_in_parent()) |
| 401 target->Put(SERVER_POSITION_IN_PARENT, update.position_in_parent()); | 402 target->Put(SERVER_POSITION_IN_PARENT, update.position_in_parent()); |
| 402 | 403 |
| 403 target->Put(SERVER_IS_DEL, update.deleted()); | 404 target->Put(SERVER_IS_DEL, update.deleted()); |
| 404 // We only mark the entry as unapplied if its version is greater than the | 405 // We only mark the entry as unapplied if its version is greater than the |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 } | 566 } |
| 566 Entry parent(&trans, GET_BY_ID, id); | 567 Entry parent(&trans, GET_BY_ID, id); |
| 567 if (!parent.good() || !parent.Get(IS_DEL)) | 568 if (!parent.good() || !parent.Get(IS_DEL)) |
| 568 break; | 569 break; |
| 569 id = parent.Get(PARENT_ID); | 570 id = parent.Get(PARENT_ID); |
| 570 } | 571 } |
| 571 } | 572 } |
| 572 } | 573 } |
| 573 | 574 |
| 574 VerifyResult VerifyNewEntry( | 575 VerifyResult VerifyNewEntry( |
| 575 const SyncEntity& update, | 576 const sync_pb::SyncEntity& update, |
| 576 syncable::Entry* target, | 577 syncable::Entry* target, |
| 577 const bool deleted) { | 578 const bool deleted) { |
| 578 if (target->good()) { | 579 if (target->good()) { |
| 579 // Not a new update. | 580 // Not a new update. |
| 580 return VERIFY_UNDECIDED; | 581 return VERIFY_UNDECIDED; |
| 581 } | 582 } |
| 582 if (deleted) { | 583 if (deleted) { |
| 583 // Deletion of an item we've never seen can be ignored. | 584 // Deletion of an item we've never seen can be ignored. |
| 584 return VERIFY_SKIP; | 585 return VERIFY_SKIP; |
| 585 } | 586 } |
| 586 | 587 |
| 587 return VERIFY_SUCCESS; | 588 return VERIFY_SUCCESS; |
| 588 } | 589 } |
| 589 | 590 |
| 590 // Assumes we have an existing entry; check here for updates that break | 591 // Assumes we have an existing entry; check here for updates that break |
| 591 // consistency rules. | 592 // consistency rules. |
| 592 VerifyResult VerifyUpdateConsistency( | 593 VerifyResult VerifyUpdateConsistency( |
| 593 syncable::WriteTransaction* trans, | 594 syncable::WriteTransaction* trans, |
| 594 const SyncEntity& update, | 595 const sync_pb::SyncEntity& update, |
| 595 syncable::MutableEntry* target, | 596 syncable::MutableEntry* target, |
| 596 const bool deleted, | 597 const bool deleted, |
| 597 const bool is_directory, | 598 const bool is_directory, |
| 598 syncer::ModelType model_type) { | 599 syncer::ModelType model_type) { |
| 599 | 600 |
| 600 CHECK(target->good()); | 601 CHECK(target->good()); |
| 602 syncable::Id update_id = SyncableIdFromProto(update.id_string()); | |
| 601 | 603 |
| 602 // If the update is a delete, we don't really need to worry at this stage. | 604 // If the update is a delete, we don't really need to worry at this stage. |
| 603 if (deleted) | 605 if (deleted) |
| 604 return VERIFY_SUCCESS; | 606 return VERIFY_SUCCESS; |
| 605 | 607 |
| 606 if (model_type == syncer::UNSPECIFIED) { | 608 if (model_type == syncer::UNSPECIFIED) { |
| 607 // This update is to an item of a datatype we don't recognize. The server | 609 // This update is to an item of a datatype we don't recognize. The server |
| 608 // shouldn't have sent it to us. Throw it on the ground. | 610 // shouldn't have sent it to us. Throw it on the ground. |
| 609 return VERIFY_SKIP; | 611 return VERIFY_SKIP; |
| 610 } | 612 } |
| 611 | 613 |
| 612 if (target->Get(SERVER_VERSION) > 0) { | 614 if (target->Get(SERVER_VERSION) > 0) { |
| 613 // Then we've had an update for this entry before. | 615 // Then we've had an update for this entry before. |
| 614 if (is_directory != target->Get(SERVER_IS_DIR) || | 616 if (is_directory != target->Get(SERVER_IS_DIR) || |
| 615 model_type != target->GetServerModelType()) { | 617 model_type != target->GetServerModelType()) { |
| 616 if (target->Get(IS_DEL)) { // If we've deleted the item, we don't care. | 618 if (target->Get(IS_DEL)) { // If we've deleted the item, we don't care. |
| 617 return VERIFY_SKIP; | 619 return VERIFY_SKIP; |
| 618 } else { | 620 } else { |
| 619 LOG(ERROR) << "Server update doesn't agree with previous updates. "; | 621 LOG(ERROR) << "Server update doesn't agree with previous updates. "; |
| 620 LOG(ERROR) << " Entry: " << *target; | 622 LOG(ERROR) << " Entry: " << *target; |
| 621 LOG(ERROR) << " Update: " | 623 LOG(ERROR) << " Update: " |
| 622 << SyncerProtoUtil::SyncEntityDebugString(update); | 624 << SyncerProtoUtil::SyncEntityDebugString(update); |
| 623 return VERIFY_FAIL; | 625 return VERIFY_FAIL; |
| 624 } | 626 } |
| 625 } | 627 } |
| 626 | 628 |
| 627 if (!deleted && (target->Get(ID) == update.id()) && | 629 if (!deleted && (target->Get(ID) == update_id) && |
| 628 (target->Get(SERVER_IS_DEL) || | 630 (target->Get(SERVER_IS_DEL) || |
| 629 (!target->Get(IS_UNSYNCED) && target->Get(IS_DEL) && | 631 (!target->Get(IS_UNSYNCED) && target->Get(IS_DEL) && |
| 630 target->Get(BASE_VERSION) > 0))) { | 632 target->Get(BASE_VERSION) > 0))) { |
| 631 // An undelete. The latter case in the above condition is for | 633 // An undelete. The latter case in the above condition is for |
| 632 // when the server does not give us an update following the | 634 // when the server does not give us an update following the |
| 633 // commit of a delete, before undeleting. | 635 // commit of a delete, before undeleting. |
| 634 // Undeletion is common for items that reuse the client-unique tag. | 636 // Undeletion is common for items that reuse the client-unique tag. |
| 635 VerifyResult result = VerifyUndelete(trans, update, target); | 637 VerifyResult result = VerifyUndelete(trans, update, target); |
| 636 if (VERIFY_UNDECIDED != result) | 638 if (VERIFY_UNDECIDED != result) |
| 637 return result; | 639 return result; |
| 638 } | 640 } |
| 639 } | 641 } |
| 640 if (target->Get(BASE_VERSION) > 0) { | 642 if (target->Get(BASE_VERSION) > 0) { |
| 641 // We've committed this update in the past. | 643 // We've committed this update in the past. |
| 642 if (is_directory != target->Get(IS_DIR) || | 644 if (is_directory != target->Get(IS_DIR) || |
| 643 model_type != target->GetModelType()) { | 645 model_type != target->GetModelType()) { |
| 644 LOG(ERROR) << "Server update doesn't agree with committed item. "; | 646 LOG(ERROR) << "Server update doesn't agree with committed item. "; |
| 645 LOG(ERROR) << " Entry: " << *target; | 647 LOG(ERROR) << " Entry: " << *target; |
| 646 LOG(ERROR) << " Update: " | 648 LOG(ERROR) << " Update: " |
| 647 << SyncerProtoUtil::SyncEntityDebugString(update); | 649 << SyncerProtoUtil::SyncEntityDebugString(update); |
| 648 return VERIFY_FAIL; | 650 return VERIFY_FAIL; |
| 649 } | 651 } |
| 650 if (target->Get(ID) == update.id()) { | 652 if (target->Get(ID) == update_id) { |
| 651 if (target->Get(SERVER_VERSION) > update.version()) { | 653 if (target->Get(SERVER_VERSION) > update.version()) { |
| 652 LOG(WARNING) << "We've already seen a more recent version."; | 654 LOG(WARNING) << "We've already seen a more recent version."; |
| 653 LOG(WARNING) << " Entry: " << *target; | 655 LOG(WARNING) << " Entry: " << *target; |
| 654 LOG(WARNING) << " Update: " | 656 LOG(WARNING) << " Update: " |
| 655 << SyncerProtoUtil::SyncEntityDebugString(update); | 657 << SyncerProtoUtil::SyncEntityDebugString(update); |
| 656 return VERIFY_SKIP; | 658 return VERIFY_SKIP; |
| 657 } | 659 } |
| 658 } | 660 } |
| 659 } | 661 } |
| 660 return VERIFY_SUCCESS; | 662 return VERIFY_SUCCESS; |
| 661 } | 663 } |
| 662 | 664 |
| 663 // Assumes we have an existing entry; verify an update that seems to be | 665 // Assumes we have an existing entry; verify an update that seems to be |
| 664 // expressing an 'undelete' | 666 // expressing an 'undelete' |
| 665 VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, | 667 VerifyResult VerifyUndelete(syncable::WriteTransaction* trans, |
| 666 const SyncEntity& update, | 668 const sync_pb::SyncEntity& update, |
| 667 syncable::MutableEntry* target) { | 669 syncable::MutableEntry* target) { |
| 668 // TODO(nick): We hit this path for items deleted items that the server | 670 // TODO(nick): We hit this path for items deleted items that the server |
| 669 // tells us to re-create; only deleted items with positive base versions | 671 // tells us to re-create; only deleted items with positive base versions |
| 670 // will hit this path. However, it's not clear how such an undeletion | 672 // will hit this path. However, it's not clear how such an undeletion |
| 671 // would actually succeed on the server; in the protocol, a base | 673 // would actually succeed on the server; in the protocol, a base |
| 672 // version of 0 is required to undelete an object. This codepath | 674 // version of 0 is required to undelete an object. This codepath |
| 673 // should be deprecated in favor of client-tag style undeletion | 675 // should be deprecated in favor of client-tag style undeletion |
| 674 // (where items go to version 0 when they're deleted), or else | 676 // (where items go to version 0 when they're deleted), or else |
| 675 // removed entirely (if this type of undeletion is indeed impossible). | 677 // removed entirely (if this type of undeletion is indeed impossible). |
| 676 CHECK(target->good()); | 678 CHECK(target->good()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 690 if (update.version() < target->Get(SERVER_VERSION)) { | 692 if (update.version() < target->Get(SERVER_VERSION)) { |
| 691 LOG(WARNING) << "Update older than current server version for " | 693 LOG(WARNING) << "Update older than current server version for " |
| 692 << *target << " Update:" | 694 << *target << " Update:" |
| 693 << SyncerProtoUtil::SyncEntityDebugString(update); | 695 << SyncerProtoUtil::SyncEntityDebugString(update); |
| 694 return VERIFY_SUCCESS; // Expected in new sync protocol. | 696 return VERIFY_SUCCESS; // Expected in new sync protocol. |
| 695 } | 697 } |
| 696 return VERIFY_UNDECIDED; | 698 return VERIFY_UNDECIDED; |
| 697 } | 699 } |
| 698 | 700 |
| 699 } // namespace syncer | 701 } // namespace syncer |
| OLD | NEW |