Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: chrome/browser/sync/glue/bookmark_model_associator.cc

Issue 15701022: [Sync] Add support for sync Persistence Errors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move bookmark change into separate patch Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(local_merge_result, syncer_merge_result); 367 syncer::SyncError error = CheckModelSyncState(local_merge_result,
368 syncer_merge_result);
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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 } 698 }
696 699
697 bool BookmarkModelAssociator::CryptoReadyIfNecessary() { 700 bool BookmarkModelAssociator::CryptoReadyIfNecessary() {
698 // We only access the cryptographer while holding a transaction. 701 // We only access the cryptographer while holding a transaction.
699 syncer::ReadTransaction trans(FROM_HERE, user_share_); 702 syncer::ReadTransaction trans(FROM_HERE, user_share_);
700 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); 703 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes();
701 return !encrypted_types.Has(syncer::BOOKMARKS) || 704 return !encrypted_types.Has(syncer::BOOKMARKS) ||
702 trans.GetCryptographer()->is_ready(); 705 trans.GetCryptographer()->is_ready();
703 } 706 }
704 707
705 void BookmarkModelAssociator::CheckModelSyncState( 708 syncer::SyncError BookmarkModelAssociator::CheckModelSyncState(
706 syncer::SyncMergeResult* local_merge_result, 709 syncer::SyncMergeResult* local_merge_result,
707 syncer::SyncMergeResult* syncer_merge_result) const { 710 syncer::SyncMergeResult* syncer_merge_result) const {
708 std::string version_str; 711 std::string version_str;
709 if (bookmark_model_->root_node()->GetMetaInfo(kBookmarkTransactionVersionKey, 712 if (bookmark_model_->root_node()->GetMetaInfo(kBookmarkTransactionVersionKey,
710 &version_str)) { 713 &version_str)) {
711 syncer::ReadTransaction trans(FROM_HERE, user_share_); 714 syncer::ReadTransaction trans(FROM_HERE, user_share_);
712 int64 native_version; 715 int64 native_version = syncer::syncable::kInvalidTransactionVersion;
713 if (!base::StringToInt64(version_str, &native_version)) 716 if (!base::StringToInt64(version_str, &native_version))
714 return; 717 return syncer::SyncError();
715 local_merge_result->set_pre_association_version(native_version); 718 local_merge_result->set_pre_association_version(native_version);
716 719
717 int64 sync_version = trans.GetModelVersion(syncer::BOOKMARKS); 720 int64 sync_version = trans.GetModelVersion(syncer::BOOKMARKS);
718 syncer_merge_result->set_pre_association_version(sync_version); 721 syncer_merge_result->set_pre_association_version(sync_version);
719 722
720 if (native_version != sync_version) { 723 if (native_version != sync_version) {
721 UMA_HISTOGRAM_ENUMERATION("Sync.LocalModelOutOfSync", 724 UMA_HISTOGRAM_ENUMERATION("Sync.LocalModelOutOfSync",
722 ModelTypeToHistogramInt(syncer::BOOKMARKS), 725 ModelTypeToHistogramInt(syncer::BOOKMARKS),
723 syncer::MODEL_TYPE_COUNT); 726 syncer::MODEL_TYPE_COUNT);
727
724 // Clear version on bookmark model so that we only report error once. 728 // Clear version on bookmark model so that we only report error once.
725 bookmark_model_->DeleteNodeMetaInfo(bookmark_model_->root_node(), 729 bookmark_model_->DeleteNodeMetaInfo(bookmark_model_->root_node(),
726 kBookmarkTransactionVersionKey); 730 kBookmarkTransactionVersionKey);
731
732 // If the native version is higher, there was a sync persistence failure,
733 // and we need to delay association until after a GetUpdates.
734 if (sync_version < native_version) {
735 DVLOG(1) << "Native version (" << native_version << ") does not match "
736 << "sync version (" << sync_version << ").";
737 // TODO(zea): return a persistence error here.
738 }
727 } 739 }
728 } 740 }
741 return syncer::SyncError();
729 } 742 }
730 743
731 } // namespace browser_sync 744 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bookmark_model_associator.h ('k') | chrome/browser/sync/glue/data_type_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698