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> |
11 | 11 |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "chrome/browser/sync/engine/conflict_resolver.h" | 13 #include "chrome/browser/sync/engine/conflict_resolver.h" |
14 #include "chrome/browser/sync/engine/nigori_util.h" | 14 #include "chrome/browser/sync/engine/nigori_util.h" |
15 #include "chrome/browser/sync/engine/syncer_proto_util.h" | 15 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
16 #include "chrome/browser/sync/engine/syncer_types.h" | 16 #include "chrome/browser/sync/engine/syncer_types.h" |
17 #include "chrome/browser/sync/engine/syncproto.h" | 17 #include "chrome/browser/sync/engine/syncproto.h" |
18 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 18 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
19 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 19 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
20 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 20 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
21 #include "chrome/browser/sync/protocol/sync.pb.h" | 21 #include "chrome/browser/sync/protocol/sync.pb.h" |
22 #include "chrome/browser/sync/syncable/directory_manager.h" | 22 #include "chrome/browser/sync/syncable/directory_manager.h" |
23 #include "chrome/browser/sync/syncable/model_type.h" | 23 #include "chrome/browser/sync/syncable/model_type.h" |
24 #include "chrome/browser/sync/syncable/syncable.h" | 24 #include "chrome/browser/sync/syncable/syncable.h" |
25 #include "chrome/browser/sync/syncable/syncable_changes_version.h" | 25 #include "chrome/browser/sync/syncable/syncable_changes_version.h" |
26 #include "chrome/browser/sync/util/time.h" | |
27 | 26 |
28 using syncable::BASE_VERSION; | 27 using syncable::BASE_VERSION; |
29 using syncable::Blob; | 28 using syncable::Blob; |
30 using syncable::CHANGES_VERSION; | 29 using syncable::CHANGES_VERSION; |
31 using syncable::CREATE; | 30 using syncable::CREATE; |
32 using syncable::CREATE_NEW_UPDATE_ITEM; | 31 using syncable::CREATE_NEW_UPDATE_ITEM; |
33 using syncable::CTIME; | 32 using syncable::CTIME; |
34 using syncable::Directory; | 33 using syncable::Directory; |
35 using syncable::Entry; | 34 using syncable::Entry; |
36 using syncable::GET_BY_HANDLE; | 35 using syncable::GET_BY_HANDLE; |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 } | 418 } |
420 target->Put(IS_UNAPPLIED_UPDATE, true); | 419 target->Put(IS_UNAPPLIED_UPDATE, true); |
421 return; | 420 return; |
422 } | 421 } |
423 | 422 |
424 DCHECK(target->Get(ID) == update.id()) | 423 DCHECK(target->Get(ID) == update.id()) |
425 << "ID Changing not supported here"; | 424 << "ID Changing not supported here"; |
426 target->Put(SERVER_PARENT_ID, update.parent_id()); | 425 target->Put(SERVER_PARENT_ID, update.parent_id()); |
427 target->Put(SERVER_NON_UNIQUE_NAME, name); | 426 target->Put(SERVER_NON_UNIQUE_NAME, name); |
428 target->Put(SERVER_VERSION, update.version()); | 427 target->Put(SERVER_VERSION, update.version()); |
429 target->Put(SERVER_CTIME, ProtoTimeToTime(update.ctime())); | 428 target->Put(SERVER_CTIME, |
430 target->Put(SERVER_MTIME, ProtoTimeToTime(update.mtime())); | 429 ServerTimeToClientTime(update.ctime())); |
| 430 target->Put(SERVER_MTIME, |
| 431 ServerTimeToClientTime(update.mtime())); |
431 target->Put(SERVER_IS_DIR, update.IsFolder()); | 432 target->Put(SERVER_IS_DIR, update.IsFolder()); |
432 if (update.has_server_defined_unique_tag()) { | 433 if (update.has_server_defined_unique_tag()) { |
433 const std::string& tag = update.server_defined_unique_tag(); | 434 const std::string& tag = update.server_defined_unique_tag(); |
434 target->Put(UNIQUE_SERVER_TAG, tag); | 435 target->Put(UNIQUE_SERVER_TAG, tag); |
435 } | 436 } |
436 if (update.has_client_defined_unique_tag()) { | 437 if (update.has_client_defined_unique_tag()) { |
437 const std::string& tag = update.client_defined_unique_tag(); | 438 const std::string& tag = update.client_defined_unique_tag(); |
438 target->Put(UNIQUE_CLIENT_TAG, tag); | 439 target->Put(UNIQUE_CLIENT_TAG, tag); |
439 } | 440 } |
440 // Store the datatype-specific part as a protobuf. | 441 // Store the datatype-specific part as a protobuf. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 } | 488 } |
488 | 489 |
489 // Now find the closest up-to-date sibling in the server order. | 490 // Now find the closest up-to-date sibling in the server order. |
490 syncable::Id server_up_to_date_predecessor = | 491 syncable::Id server_up_to_date_predecessor = |
491 entry->ComputePrevIdFromServerPosition(entry->Get(SERVER_PARENT_ID)); | 492 entry->ComputePrevIdFromServerPosition(entry->Get(SERVER_PARENT_ID)); |
492 return server_up_to_date_predecessor == local_up_to_date_predecessor; | 493 return server_up_to_date_predecessor == local_up_to_date_predecessor; |
493 } | 494 } |
494 | 495 |
495 // static | 496 // static |
496 bool SyncerUtil::ServerAndLocalEntriesMatch(syncable::Entry* entry) { | 497 bool SyncerUtil::ServerAndLocalEntriesMatch(syncable::Entry* entry) { |
497 if (entry->Get(CTIME) != entry->Get(SERVER_CTIME)) { | 498 if (!ClientAndServerTimeMatch( |
| 499 entry->Get(CTIME), ClientTimeToServerTime(entry->Get(SERVER_CTIME)))) { |
498 LOG(WARNING) << "Client and server time mismatch"; | 500 LOG(WARNING) << "Client and server time mismatch"; |
499 return false; | 501 return false; |
500 } | 502 } |
501 if (entry->Get(IS_DEL) && entry->Get(SERVER_IS_DEL)) | 503 if (entry->Get(IS_DEL) && entry->Get(SERVER_IS_DEL)) |
502 return true; | 504 return true; |
503 // Name should exactly match here. | 505 // Name should exactly match here. |
504 if (!(entry->Get(NON_UNIQUE_NAME) == entry->Get(SERVER_NON_UNIQUE_NAME))) { | 506 if (!(entry->Get(NON_UNIQUE_NAME) == entry->Get(SERVER_NON_UNIQUE_NAME))) { |
505 LOG(WARNING) << "Unsanitized name mismatch"; | 507 LOG(WARNING) << "Unsanitized name mismatch"; |
506 return false; | 508 return false; |
507 } | 509 } |
(...skipping 13 matching lines...) Expand all Loading... |
521 // TODO(ncarter): This is unfortunately heavyweight. Can we do better? | 523 // TODO(ncarter): This is unfortunately heavyweight. Can we do better? |
522 if (entry->Get(SPECIFICS).SerializeAsString() != | 524 if (entry->Get(SPECIFICS).SerializeAsString() != |
523 entry->Get(SERVER_SPECIFICS).SerializeAsString()) { | 525 entry->Get(SERVER_SPECIFICS).SerializeAsString()) { |
524 LOG(WARNING) << "Specifics mismatch"; | 526 LOG(WARNING) << "Specifics mismatch"; |
525 return false; | 527 return false; |
526 } | 528 } |
527 if (entry->Get(IS_DIR)) | 529 if (entry->Get(IS_DIR)) |
528 return true; | 530 return true; |
529 // For historical reasons, a folder's MTIME changes when its contents change. | 531 // For historical reasons, a folder's MTIME changes when its contents change. |
530 // TODO(ncarter): Remove the special casing of MTIME. | 532 // TODO(ncarter): Remove the special casing of MTIME. |
531 if (entry->Get(MTIME) != entry->Get(SERVER_MTIME)) { | 533 bool time_match = ClientAndServerTimeMatch(entry->Get(MTIME), |
| 534 ClientTimeToServerTime(entry->Get(SERVER_MTIME))); |
| 535 if (!time_match) { |
532 LOG(WARNING) << "Time mismatch"; | 536 LOG(WARNING) << "Time mismatch"; |
533 return false; | |
534 } | 537 } |
535 return true; | 538 return time_match; |
536 } | 539 } |
537 | 540 |
538 // static | 541 // static |
539 void SyncerUtil::SplitServerInformationIntoNewEntry( | 542 void SyncerUtil::SplitServerInformationIntoNewEntry( |
540 syncable::WriteTransaction* trans, | 543 syncable::WriteTransaction* trans, |
541 syncable::MutableEntry* entry) { | 544 syncable::MutableEntry* entry) { |
542 syncable::Id id = entry->Get(ID); | 545 syncable::Id id = entry->Get(ID); |
543 ChangeEntryIDAndUpdateChildren(trans, entry, trans->directory()->NextId()); | 546 ChangeEntryIDAndUpdateChildren(trans, entry, trans->directory()->NextId()); |
544 entry->Put(BASE_VERSION, 0); | 547 entry->Put(BASE_VERSION, 0); |
545 | 548 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 if (update.version() < target->Get(SERVER_VERSION)) { | 829 if (update.version() < target->Get(SERVER_VERSION)) { |
827 LOG(WARNING) << "Update older than current server version for " | 830 LOG(WARNING) << "Update older than current server version for " |
828 << *target << " Update:" | 831 << *target << " Update:" |
829 << SyncerProtoUtil::SyncEntityDebugString(update); | 832 << SyncerProtoUtil::SyncEntityDebugString(update); |
830 return VERIFY_SUCCESS; // Expected in new sync protocol. | 833 return VERIFY_SUCCESS; // Expected in new sync protocol. |
831 } | 834 } |
832 return VERIFY_UNDECIDED; | 835 return VERIFY_UNDECIDED; |
833 } | 836 } |
834 | 837 |
835 } // namespace browser_sync | 838 } // namespace browser_sync |
OLD | NEW |