OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/sync/glue/bookmark_model_associator.h" | 5 #include "chrome/browser/sync/glue/bookmark_model_associator.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 syncer::ReadNode sync_node(&trans); | 357 syncer::ReadNode sync_node(&trans); |
358 if (sync_node.InitByTagLookup(tag.c_str()) != syncer::BaseNode::INIT_OK) | 358 if (sync_node.InitByTagLookup(tag.c_str()) != syncer::BaseNode::INIT_OK) |
359 return false; | 359 return false; |
360 *sync_id = sync_node.GetId(); | 360 *sync_id = sync_node.GetId(); |
361 return true; | 361 return true; |
362 } | 362 } |
363 | 363 |
364 syncer::SyncError BookmarkModelAssociator::AssociateModels( | 364 syncer::SyncError BookmarkModelAssociator::AssociateModels( |
365 syncer::SyncMergeResult* local_merge_result, | 365 syncer::SyncMergeResult* local_merge_result, |
366 syncer::SyncMergeResult* syncer_merge_result) { | 366 syncer::SyncMergeResult* syncer_merge_result) { |
367 CheckModelSyncState(); | 367 syncer::SyncError error; |
| 368 error = CheckModelSyncState(); |
| 369 if (error.IsSet()) |
| 370 return error; |
368 | 371 |
369 scoped_ptr<ScopedAssociationUpdater> association_updater( | 372 scoped_ptr<ScopedAssociationUpdater> association_updater( |
370 new ScopedAssociationUpdater(bookmark_model_)); | 373 new ScopedAssociationUpdater(bookmark_model_)); |
371 DisassociateModels(); | 374 DisassociateModels(); |
372 | 375 |
373 return BuildAssociations(local_merge_result, syncer_merge_result); | 376 return BuildAssociations(local_merge_result, syncer_merge_result); |
374 } | 377 } |
375 | 378 |
376 syncer::SyncError BookmarkModelAssociator::BuildAssociations( | 379 syncer::SyncError BookmarkModelAssociator::BuildAssociations( |
377 syncer::SyncMergeResult* local_merge_result, | 380 syncer::SyncMergeResult* local_merge_result, |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 } | 697 } |
695 | 698 |
696 bool BookmarkModelAssociator::CryptoReadyIfNecessary() { | 699 bool BookmarkModelAssociator::CryptoReadyIfNecessary() { |
697 // We only access the cryptographer while holding a transaction. | 700 // We only access the cryptographer while holding a transaction. |
698 syncer::ReadTransaction trans(FROM_HERE, user_share_); | 701 syncer::ReadTransaction trans(FROM_HERE, user_share_); |
699 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); | 702 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); |
700 return !encrypted_types.Has(syncer::BOOKMARKS) || | 703 return !encrypted_types.Has(syncer::BOOKMARKS) || |
701 trans.GetCryptographer()->is_ready(); | 704 trans.GetCryptographer()->is_ready(); |
702 } | 705 } |
703 | 706 |
704 void BookmarkModelAssociator::CheckModelSyncState() const { | 707 syncer::SyncError BookmarkModelAssociator::CheckModelSyncState() const { |
705 std::string version_str; | 708 std::string version_str; |
706 if (bookmark_model_->root_node()->GetMetaInfo(kBookmarkTransactionVersionKey, | 709 if (bookmark_model_->root_node()->GetMetaInfo(kBookmarkTransactionVersionKey, |
707 &version_str)) { | 710 &version_str)) { |
708 syncer::ReadTransaction trans(FROM_HERE, user_share_); | 711 syncer::ReadTransaction trans(FROM_HERE, user_share_); |
709 int64 native_version; | 712 int64 native_version = syncer::syncable::kInvalidTransactionVersion; |
| 713 int64 sync_version = trans.GetModelVersion(syncer::BOOKMARKS); |
710 if (base::StringToInt64(version_str, &native_version) && | 714 if (base::StringToInt64(version_str, &native_version) && |
711 native_version != trans.GetModelVersion(syncer::BOOKMARKS)) { | 715 native_version != sync_version) { |
712 UMA_HISTOGRAM_ENUMERATION("Sync.LocalModelOutOfSync", | 716 UMA_HISTOGRAM_ENUMERATION("Sync.LocalModelOutOfSync", |
713 ModelTypeToHistogramInt(syncer::BOOKMARKS), | 717 ModelTypeToHistogramInt(syncer::BOOKMARKS), |
714 syncer::MODEL_TYPE_COUNT); | 718 syncer::MODEL_TYPE_COUNT); |
| 719 |
715 // Clear version on bookmark model so that we only report error once. | 720 // Clear version on bookmark model so that we only report error once. |
716 bookmark_model_->DeleteNodeMetaInfo(bookmark_model_->root_node(), | 721 bookmark_model_->DeleteNodeMetaInfo(bookmark_model_->root_node(), |
717 kBookmarkTransactionVersionKey); | 722 kBookmarkTransactionVersionKey); |
| 723 |
| 724 // If the native version is higher, there was a sync persistence failure, |
| 725 // and we need to delay association until after a GetUpdates. |
| 726 if (sync_version < native_version) { |
| 727 DVLOG(1) << "Native version (" << native_version << ") does not match " |
| 728 << "sync version (" << sync_version << ")."; |
| 729 return syncer::SyncError(FROM_HERE, |
| 730 syncer::SyncError::PERSISTENCE_ERROR, |
| 731 syncer::BOOKMARKS); |
| 732 } |
718 } | 733 } |
719 } | 734 } |
| 735 return syncer::SyncError(); |
720 } | 736 } |
721 | 737 |
722 } // namespace browser_sync | 738 } // namespace browser_sync |
OLD | NEW |