| 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> |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // passphrase may not arrive within this GetUpdates, we can't just return | 243 // passphrase may not arrive within this GetUpdates, we can't just return |
| 244 // conflict, else we try to perform normal conflict resolution prematurely or | 244 // conflict, else we try to perform normal conflict resolution prematurely or |
| 245 // the syncer may get stuck. As such, we return CONFLICT_ENCRYPTION, which is | 245 // the syncer may get stuck. As such, we return CONFLICT_ENCRYPTION, which is |
| 246 // treated as an unresolvable conflict. See the description in syncer_types.h. | 246 // treated as an unresolvable conflict. See the description in syncer_types.h. |
| 247 // This prevents any unsynced changes from commiting and postpones conflict | 247 // This prevents any unsynced changes from commiting and postpones conflict |
| 248 // resolution until all data can be decrypted. | 248 // resolution until all data can be decrypted. |
| 249 if (specifics.has_encrypted() && | 249 if (specifics.has_encrypted() && |
| 250 !cryptographer->CanDecrypt(specifics.encrypted())) { | 250 !cryptographer->CanDecrypt(specifics.encrypted())) { |
| 251 // We can't decrypt this node yet. | 251 // We can't decrypt this node yet. |
| 252 DVLOG(1) << "Received an undecryptable " | 252 DVLOG(1) << "Received an undecryptable " |
| 253 << syncable::ModelTypeToString(entry->GetServerModelType()) | 253 << syncer::ModelTypeToString(entry->GetServerModelType()) |
| 254 << " update, returning encryption_conflict."; | 254 << " update, returning encryption_conflict."; |
| 255 return CONFLICT_ENCRYPTION; | 255 return CONFLICT_ENCRYPTION; |
| 256 } else if (specifics.has_password() && | 256 } else if (specifics.has_password() && |
| 257 entry->Get(UNIQUE_SERVER_TAG).empty()) { | 257 entry->Get(UNIQUE_SERVER_TAG).empty()) { |
| 258 // Passwords use their own legacy encryption scheme. | 258 // Passwords use their own legacy encryption scheme. |
| 259 const sync_pb::PasswordSpecifics& password = specifics.password(); | 259 const sync_pb::PasswordSpecifics& password = specifics.password(); |
| 260 if (!cryptographer->CanDecrypt(password.encrypted())) { | 260 if (!cryptographer->CanDecrypt(password.encrypted())) { |
| 261 DVLOG(1) << "Received an undecryptable password update, returning " | 261 DVLOG(1) << "Received an undecryptable password update, returning " |
| 262 << "encryption_conflict."; | 262 << "encryption_conflict."; |
| 263 return CONFLICT_ENCRYPTION; | 263 return CONFLICT_ENCRYPTION; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 295 } |
| 296 | 296 |
| 297 if (entry->Get(IS_UNSYNCED)) { | 297 if (entry->Get(IS_UNSYNCED)) { |
| 298 DVLOG(1) << "Skipping update, returning conflict for: " << id | 298 DVLOG(1) << "Skipping update, returning conflict for: " << id |
| 299 << " ; it's unsynced."; | 299 << " ; it's unsynced."; |
| 300 return CONFLICT_SIMPLE; | 300 return CONFLICT_SIMPLE; |
| 301 } | 301 } |
| 302 | 302 |
| 303 if (specifics.has_encrypted()) { | 303 if (specifics.has_encrypted()) { |
| 304 DVLOG(2) << "Received a decryptable " | 304 DVLOG(2) << "Received a decryptable " |
| 305 << syncable::ModelTypeToString(entry->GetServerModelType()) | 305 << syncer::ModelTypeToString(entry->GetServerModelType()) |
| 306 << " update, applying normally."; | 306 << " update, applying normally."; |
| 307 } else { | 307 } else { |
| 308 DVLOG(2) << "Received an unencrypted " | 308 DVLOG(2) << "Received an unencrypted " |
| 309 << syncable::ModelTypeToString(entry->GetServerModelType()) | 309 << syncer::ModelTypeToString(entry->GetServerModelType()) |
| 310 << " update, applying normally."; | 310 << " update, applying normally."; |
| 311 } | 311 } |
| 312 | 312 |
| 313 UpdateLocalDataFromServerData(trans, entry); | 313 UpdateLocalDataFromServerData(trans, entry); |
| 314 | 314 |
| 315 return SUCCESS; | 315 return SUCCESS; |
| 316 } | 316 } |
| 317 | 317 |
| 318 namespace { | 318 namespace { |
| 319 // Helper to synthesize a new-style sync_pb::EntitySpecifics for use locally, | 319 // Helper to synthesize a new-style sync_pb::EntitySpecifics for use locally, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 if (update.has_server_defined_unique_tag()) { | 379 if (update.has_server_defined_unique_tag()) { |
| 380 const std::string& tag = update.server_defined_unique_tag(); | 380 const std::string& tag = update.server_defined_unique_tag(); |
| 381 target->Put(UNIQUE_SERVER_TAG, tag); | 381 target->Put(UNIQUE_SERVER_TAG, tag); |
| 382 } | 382 } |
| 383 if (update.has_client_defined_unique_tag()) { | 383 if (update.has_client_defined_unique_tag()) { |
| 384 const std::string& tag = update.client_defined_unique_tag(); | 384 const std::string& tag = update.client_defined_unique_tag(); |
| 385 target->Put(UNIQUE_CLIENT_TAG, tag); | 385 target->Put(UNIQUE_CLIENT_TAG, tag); |
| 386 } | 386 } |
| 387 // Store the datatype-specific part as a protobuf. | 387 // Store the datatype-specific part as a protobuf. |
| 388 if (update.has_specifics()) { | 388 if (update.has_specifics()) { |
| 389 DCHECK(update.GetModelType() != syncable::UNSPECIFIED) | 389 DCHECK(update.GetModelType() != syncer::UNSPECIFIED) |
| 390 << "Storing unrecognized datatype in sync database."; | 390 << "Storing unrecognized datatype in sync database."; |
| 391 target->Put(SERVER_SPECIFICS, update.specifics()); | 391 target->Put(SERVER_SPECIFICS, update.specifics()); |
| 392 } else if (update.has_bookmarkdata()) { | 392 } else if (update.has_bookmarkdata()) { |
| 393 // Legacy protocol response for bookmark data. | 393 // Legacy protocol response for bookmark data. |
| 394 const SyncEntity::BookmarkData& bookmark = update.bookmarkdata(); | 394 const SyncEntity::BookmarkData& bookmark = update.bookmarkdata(); |
| 395 UpdateBookmarkSpecifics(update.server_defined_unique_tag(), | 395 UpdateBookmarkSpecifics(update.server_defined_unique_tag(), |
| 396 bookmark.bookmark_url(), | 396 bookmark.bookmark_url(), |
| 397 bookmark.bookmark_favicon(), | 397 bookmark.bookmark_favicon(), |
| 398 target); | 398 target); |
| 399 } | 399 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 } | 588 } |
| 589 | 589 |
| 590 // Assumes we have an existing entry; check here for updates that break | 590 // Assumes we have an existing entry; check here for updates that break |
| 591 // consistency rules. | 591 // consistency rules. |
| 592 VerifyResult VerifyUpdateConsistency( | 592 VerifyResult VerifyUpdateConsistency( |
| 593 syncable::WriteTransaction* trans, | 593 syncable::WriteTransaction* trans, |
| 594 const SyncEntity& update, | 594 const SyncEntity& update, |
| 595 syncable::MutableEntry* target, | 595 syncable::MutableEntry* target, |
| 596 const bool deleted, | 596 const bool deleted, |
| 597 const bool is_directory, | 597 const bool is_directory, |
| 598 syncable::ModelType model_type) { | 598 syncer::ModelType model_type) { |
| 599 | 599 |
| 600 CHECK(target->good()); | 600 CHECK(target->good()); |
| 601 | 601 |
| 602 // If the update is a delete, we don't really need to worry at this stage. | 602 // If the update is a delete, we don't really need to worry at this stage. |
| 603 if (deleted) | 603 if (deleted) |
| 604 return VERIFY_SUCCESS; | 604 return VERIFY_SUCCESS; |
| 605 | 605 |
| 606 if (model_type == syncable::UNSPECIFIED) { | 606 if (model_type == syncer::UNSPECIFIED) { |
| 607 // This update is to an item of a datatype we don't recognize. The server | 607 // 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. | 608 // shouldn't have sent it to us. Throw it on the ground. |
| 609 return VERIFY_SKIP; | 609 return VERIFY_SKIP; |
| 610 } | 610 } |
| 611 | 611 |
| 612 if (target->Get(SERVER_VERSION) > 0) { | 612 if (target->Get(SERVER_VERSION) > 0) { |
| 613 // Then we've had an update for this entry before. | 613 // Then we've had an update for this entry before. |
| 614 if (is_directory != target->Get(SERVER_IS_DIR) || | 614 if (is_directory != target->Get(SERVER_IS_DIR) || |
| 615 model_type != target->GetServerModelType()) { | 615 model_type != target->GetServerModelType()) { |
| 616 if (target->Get(IS_DEL)) { // If we've deleted the item, we don't care. | 616 if (target->Get(IS_DEL)) { // If we've deleted the item, we don't care. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 if (update.version() < target->Get(SERVER_VERSION)) { | 690 if (update.version() < target->Get(SERVER_VERSION)) { |
| 691 LOG(WARNING) << "Update older than current server version for " | 691 LOG(WARNING) << "Update older than current server version for " |
| 692 << *target << " Update:" | 692 << *target << " Update:" |
| 693 << SyncerProtoUtil::SyncEntityDebugString(update); | 693 << SyncerProtoUtil::SyncEntityDebugString(update); |
| 694 return VERIFY_SUCCESS; // Expected in new sync protocol. | 694 return VERIFY_SUCCESS; // Expected in new sync protocol. |
| 695 } | 695 } |
| 696 return VERIFY_UNDECIDED; | 696 return VERIFY_UNDECIDED; |
| 697 } | 697 } |
| 698 | 698 |
| 699 } // namespace syncer | 699 } // namespace syncer |
| OLD | NEW |