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

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

Issue 11341048: Populate versions on individual nodes in sync model and native bookmark model. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 (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 "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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 void BookmarkModelAssociator::PersistAssociations() { 520 void BookmarkModelAssociator::PersistAssociations() {
521 // If there are no dirty associations we have nothing to do. We handle this 521 // If there are no dirty associations we have nothing to do. We handle this
522 // explicity instead of letting the for loop do it to avoid creating a write 522 // explicity instead of letting the for loop do it to avoid creating a write
523 // transaction in this case. 523 // transaction in this case.
524 if (dirty_associations_sync_ids_.empty()) { 524 if (dirty_associations_sync_ids_.empty()) {
525 DCHECK(id_map_.empty()); 525 DCHECK(id_map_.empty());
526 DCHECK(id_map_inverse_.empty()); 526 DCHECK(id_map_inverse_.empty());
527 return; 527 return;
528 } 528 }
529 529
530 syncer::WriteTransaction trans(FROM_HERE, user_share_); 530 int64 new_version = -1;
531 DirtyAssociationsSyncIds::iterator iter; 531 std::vector<const BookmarkNode*> bnodes;
532 for (iter = dirty_associations_sync_ids_.begin(); 532 {
533 iter != dirty_associations_sync_ids_.end(); 533 syncer::WriteTransaction trans(FROM_HERE, user_share_, &new_version);
534 ++iter) { 534 DirtyAssociationsSyncIds::iterator iter;
535 int64 sync_id = *iter; 535 for (iter = dirty_associations_sync_ids_.begin();
536 syncer::WriteNode sync_node(&trans); 536 iter != dirty_associations_sync_ids_.end();
537 if (sync_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) { 537 ++iter) {
538 unrecoverable_error_handler_->OnSingleDatatypeUnrecoverableError( 538 int64 sync_id = *iter;
539 FROM_HERE, 539 syncer::WriteNode sync_node(&trans);
540 "Could not lookup bookmark node for ID persistence."); 540 if (sync_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) {
541 return; 541 unrecoverable_error_handler_->OnSingleDatatypeUnrecoverableError(
542 FROM_HERE,
543 "Could not lookup bookmark node for ID persistence.");
544 return;
545 }
546 const BookmarkNode* node = GetChromeNodeFromSyncId(sync_id);
547 if (node && sync_node.GetExternalId() != node->id()) {
548 sync_node.SetExternalId(node->id());
549 bnodes.push_back(node);
550 }
542 } 551 }
543 const BookmarkNode* node = GetChromeNodeFromSyncId(sync_id); 552 dirty_associations_sync_ids_.clear();
544 if (node)
545 sync_node.SetExternalId(node->id());
546 else
547 NOTREACHED();
548 } 553 }
549 dirty_associations_sync_ids_.clear(); 554
555 if (new_version > 0) {
556 bookmark_model_->SetNodeMetaInfo(bookmark_model_->root_node(),
557 kBookmarkTransactionVersionKey,
558 base::Int64ToString(new_version));
559 for (uint32 i = 0; i < bnodes.size(); ++i) {
tim (not reviewing) 2012/11/08 17:38:49 Prefer size_t, although I think this could all be
haitaol1 2012/11/08 19:06:53 Done.
560 bookmark_model_->SetNodeMetaInfo(bnodes[i],
561 kBookmarkTransactionVersionKey,
562 base::Int64ToString(new_version));
563 }
564 }
550 } 565 }
551 566
552 bool BookmarkModelAssociator::CryptoReadyIfNecessary() { 567 bool BookmarkModelAssociator::CryptoReadyIfNecessary() {
553 // We only access the cryptographer while holding a transaction. 568 // We only access the cryptographer while holding a transaction.
554 syncer::ReadTransaction trans(FROM_HERE, user_share_); 569 syncer::ReadTransaction trans(FROM_HERE, user_share_);
555 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes(); 570 const syncer::ModelTypeSet encrypted_types = trans.GetEncryptedTypes();
556 return !encrypted_types.Has(syncer::BOOKMARKS) || 571 return !encrypted_types.Has(syncer::BOOKMARKS) ||
557 trans.GetCryptographer()->is_ready(); 572 trans.GetCryptographer()->is_ready();
558 } 573 }
559 574
560 void BookmarkModelAssociator::CheckModelSyncState() const { 575 void BookmarkModelAssociator::CheckModelSyncState() const {
561 std::string version_str; 576 std::string version_str;
562 if (bookmark_model_->root_node()->GetMetaInfo(kBookmarkTransactionVersionKey, 577 if (bookmark_model_->root_node()->GetMetaInfo(kBookmarkTransactionVersionKey,
563 &version_str)) { 578 &version_str)) {
564 syncer::ReadTransaction trans(FROM_HERE, user_share_); 579 syncer::ReadTransaction trans(FROM_HERE, user_share_);
565 int64 native_version; 580 int64 native_version;
566 if (base::StringToInt64(version_str, &native_version) && 581 if (base::StringToInt64(version_str, &native_version) &&
567 native_version != trans.GetModelVersion(syncer::BOOKMARKS)) { 582 native_version != trans.GetModelVersion(syncer::BOOKMARKS)) {
568 UMA_HISTOGRAM_ENUMERATION("Sync.LocalModelOutOfSync", 583 UMA_HISTOGRAM_ENUMERATION("Sync.LocalModelOutOfSync",
569 syncer::BOOKMARKS, syncer::MODEL_TYPE_COUNT); 584 syncer::BOOKMARKS, syncer::MODEL_TYPE_COUNT);
570 // Clear version on bookmark model so that we only report error once. 585 // Clear version on bookmark model so that we only report error once.
571 bookmark_model_->DeleteNodeMetaInfo(bookmark_model_->root_node(), 586 bookmark_model_->DeleteNodeMetaInfo(bookmark_model_->root_node(),
572 kBookmarkTransactionVersionKey); 587 kBookmarkTransactionVersionKey);
573 } 588 }
574 } 589 }
575 } 590 }
576 591
577 } // namespace browser_sync 592 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698