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

Side by Side Diff: components/sync_bookmarks/bookmark_model_associator.cc

Issue 2289143003: [Sync] Convert DTCs to be not RefCounted and NonThreadSafe. (Closed)
Patch Set: Rebase. Created 4 years, 3 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
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 "components/sync_bookmarks/bookmark_model_associator.h" 5 #include "components/sync_bookmarks/bookmark_model_associator.h"
6 6
7 #include <memory> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/format_macros.h" 12 #include "base/format_macros.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 303
304 void BookmarkModelAssociator::Context::MarkForVersionUpdate( 304 void BookmarkModelAssociator::Context::MarkForVersionUpdate(
305 const bookmarks::BookmarkNode* node) { 305 const bookmarks::BookmarkNode* node) {
306 bookmarks_for_version_update_.push_back(node); 306 bookmarks_for_version_update_.push_back(node);
307 } 307 }
308 308
309 BookmarkModelAssociator::BookmarkModelAssociator( 309 BookmarkModelAssociator::BookmarkModelAssociator(
310 BookmarkModel* bookmark_model, 310 BookmarkModel* bookmark_model,
311 sync_driver::SyncClient* sync_client, 311 sync_driver::SyncClient* sync_client,
312 syncer::UserShare* user_share, 312 syncer::UserShare* user_share,
313 syncer::DataTypeErrorHandler* unrecoverable_error_handler, 313 std::unique_ptr<syncer::DataTypeErrorHandler> unrecoverable_error_handler,
314 bool expect_mobile_bookmarks_folder) 314 bool expect_mobile_bookmarks_folder)
315 : bookmark_model_(bookmark_model), 315 : bookmark_model_(bookmark_model),
316 sync_client_(sync_client), 316 sync_client_(sync_client),
317 user_share_(user_share), 317 user_share_(user_share),
318 unrecoverable_error_handler_(unrecoverable_error_handler), 318 unrecoverable_error_handler_(std::move(unrecoverable_error_handler)),
319 expect_mobile_bookmarks_folder_(expect_mobile_bookmarks_folder), 319 expect_mobile_bookmarks_folder_(expect_mobile_bookmarks_folder),
320 weak_factory_(this) { 320 weak_factory_(this) {
321 DCHECK(bookmark_model_); 321 DCHECK(bookmark_model_);
322 DCHECK(user_share_); 322 DCHECK(user_share_);
323 DCHECK(unrecoverable_error_handler_); 323 DCHECK(unrecoverable_error_handler_);
324 } 324 }
325 325
326 BookmarkModelAssociator::~BookmarkModelAssociator() { 326 BookmarkModelAssociator::~BookmarkModelAssociator() {
327 DCHECK(thread_checker_.CalledOnValidThread()); 327 DCHECK(thread_checker_.CalledOnValidThread());
328 } 328 }
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 } 722 }
723 723
724 // At this point all the children nodes of the parent sync node have 724 // At this point all the children nodes of the parent sync node have
725 // corresponding children in the parent bookmark node and they are all in 725 // corresponding children in the parent bookmark node and they are all in
726 // the right positions: from 0 to index - 1. 726 // the right positions: from 0 to index - 1.
727 // So the children starting from index in the parent bookmark node are the 727 // So the children starting from index in the parent bookmark node are the
728 // ones that are not present in the parent sync node. So create them. 728 // ones that are not present in the parent sync node. So create them.
729 for (int i = index; i < parent_node->child_count(); ++i) { 729 for (int i = index; i < parent_node->child_count(); ++i) {
730 int64_t sync_child_id = BookmarkChangeProcessor::CreateSyncNode( 730 int64_t sync_child_id = BookmarkChangeProcessor::CreateSyncNode(
731 parent_node, bookmark_model_, i, trans, this, 731 parent_node, bookmark_model_, i, trans, this,
732 unrecoverable_error_handler_); 732 unrecoverable_error_handler_.get());
733 if (syncer::kInvalidId == sync_child_id) { 733 if (syncer::kInvalidId == sync_child_id) {
734 return unrecoverable_error_handler_->CreateAndUploadError( 734 return unrecoverable_error_handler_->CreateAndUploadError(
735 FROM_HERE, "Failed to create sync node.", model_type()); 735 FROM_HERE, "Failed to create sync node.", model_type());
736 } 736 }
737 737
738 context->IncrementSyncItemsAdded(); 738 context->IncrementSyncItemsAdded();
739 const BookmarkNode* child_node = parent_node->GetChild(i); 739 const BookmarkNode* child_node = parent_node->GetChild(i);
740 context->MarkForVersionUpdate(child_node); 740 context->MarkForVersionUpdate(child_node);
741 if (child_node->is_folder()) 741 if (child_node->is_folder())
742 context->PushNode(sync_child_id); 742 context->PushNode(sync_child_id);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 } 784 }
785 785
786 int BookmarkModelAssociator::RemoveSyncNodeHierarchy( 786 int BookmarkModelAssociator::RemoveSyncNodeHierarchy(
787 syncer::WriteTransaction* trans, 787 syncer::WriteTransaction* trans,
788 int64_t sync_id) { 788 int64_t sync_id) {
789 syncer::WriteNode sync_node(trans); 789 syncer::WriteNode sync_node(trans);
790 if (sync_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) { 790 if (sync_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) {
791 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR, 791 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
792 "Could not lookup bookmark node for ID deletion.", 792 "Could not lookup bookmark node for ID deletion.",
793 syncer::BOOKMARKS); 793 syncer::BOOKMARKS);
794 unrecoverable_error_handler_->OnSingleDataTypeUnrecoverableError(error); 794 unrecoverable_error_handler_->OnUnrecoverableError(error);
795 return 0; 795 return 0;
796 } 796 }
797 797
798 return BookmarkChangeProcessor::RemoveSyncNodeHierarchy(trans, &sync_node, 798 return BookmarkChangeProcessor::RemoveSyncNodeHierarchy(trans, &sync_node,
799 this); 799 this);
800 } 800 }
801 801
802 struct FolderInfo { 802 struct FolderInfo {
803 FolderInfo(const BookmarkNode* f, const BookmarkNode* p, int64_t id) 803 FolderInfo(const BookmarkNode* f, const BookmarkNode* p, int64_t id)
804 : folder(f), parent(p), sync_id(id) {} 804 : folder(f), parent(p), sync_id(id) {}
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 iter != dirty_associations_sync_ids_.end(); 939 iter != dirty_associations_sync_ids_.end();
940 ++iter) { 940 ++iter) {
941 int64_t sync_id = *iter; 941 int64_t sync_id = *iter;
942 syncer::WriteNode sync_node(&trans); 942 syncer::WriteNode sync_node(&trans);
943 if (sync_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) { 943 if (sync_node.InitByIdLookup(sync_id) != syncer::BaseNode::INIT_OK) {
944 syncer::SyncError error( 944 syncer::SyncError error(
945 FROM_HERE, 945 FROM_HERE,
946 syncer::SyncError::DATATYPE_ERROR, 946 syncer::SyncError::DATATYPE_ERROR,
947 "Could not lookup bookmark node for ID persistence.", 947 "Could not lookup bookmark node for ID persistence.",
948 syncer::BOOKMARKS); 948 syncer::BOOKMARKS);
949 unrecoverable_error_handler_->OnSingleDataTypeUnrecoverableError(error); 949 unrecoverable_error_handler_->OnUnrecoverableError(error);
950 return; 950 return;
951 } 951 }
952 const BookmarkNode* node = GetChromeNodeFromSyncId(sync_id); 952 const BookmarkNode* node = GetChromeNodeFromSyncId(sync_id);
953 if (node && sync_node.GetExternalId() != node->id()) { 953 if (node && sync_node.GetExternalId() != node->id()) {
954 sync_node.SetExternalId(node->id()); 954 sync_node.SetExternalId(node->id());
955 bnodes.push_back(node); 955 bnodes.push_back(node);
956 } 956 }
957 } 957 }
958 dirty_associations_sync_ids_.clear(); 958 dirty_associations_sync_ids_.clear();
959 } 959 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 syncer::BOOKMARKS); 1009 syncer::BOOKMARKS);
1010 } else { 1010 } else {
1011 context->set_native_model_sync_state(BEHIND); 1011 context->set_native_model_sync_state(BEHIND);
1012 } 1012 }
1013 } 1013 }
1014 } 1014 }
1015 return syncer::SyncError(); 1015 return syncer::SyncError();
1016 } 1016 }
1017 1017
1018 } // namespace browser_sync 1018 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync_bookmarks/bookmark_model_associator.h ('k') | components/sync_sessions/session_data_type_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698