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

Side by Side Diff: trunk/src/chrome/browser/sync/glue/bookmark_change_processor.cc

Issue 465113002: Revert 288557 "[Sync] Use OnSingleDataTypeUnrecoverableError for..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 4 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_change_processor.h" 5 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
6 6
7 #include <map> 7 #include <map>
8 #include <stack> 8 #include <stack>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 void BookmarkChangeProcessor::RemoveSyncNodeHierarchy( 114 void BookmarkChangeProcessor::RemoveSyncNodeHierarchy(
115 const BookmarkNode* topmost) { 115 const BookmarkNode* topmost) {
116 int64 new_version = 116 int64 new_version =
117 syncer::syncable::kInvalidTransactionVersion; 117 syncer::syncable::kInvalidTransactionVersion;
118 { 118 {
119 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); 119 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version);
120 syncer::WriteNode topmost_sync_node(&trans); 120 syncer::WriteNode topmost_sync_node(&trans);
121 if (!model_associator_->InitSyncNodeFromChromeId(topmost->id(), 121 if (!model_associator_->InitSyncNodeFromChromeId(topmost->id(),
122 &topmost_sync_node)) { 122 &topmost_sync_node)) {
123 syncer::SyncError error(FROM_HERE, 123 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
124 syncer::SyncError::DATATYPE_ERROR, 124 std::string());
125 "Failed to init sync node from chrome node",
126 syncer::BOOKMARKS);
127 error_handler()->OnSingleDataTypeUnrecoverableError(error);
128 return; 125 return;
129 } 126 }
130 // Check that |topmost| has been unlinked. 127 // Check that |topmost| has been unlinked.
131 DCHECK(topmost->is_root()); 128 DCHECK(topmost->is_root());
132 RemoveAllChildNodes(&trans, topmost->id()); 129 RemoveAllChildNodes(&trans, topmost->id());
133 // Remove the node itself. 130 // Remove the node itself.
134 RemoveOneSyncNode(&topmost_sync_node); 131 RemoveOneSyncNode(&topmost_sync_node);
135 } 132 }
136 133
137 // Don't need to update versions of deleted nodes. 134 // Don't need to update versions of deleted nodes.
(...skipping 21 matching lines...) Expand all
159 // Don't need to update versions of deleted nodes. 156 // Don't need to update versions of deleted nodes.
160 UpdateTransactionVersion(new_version, bookmark_model_, 157 UpdateTransactionVersion(new_version, bookmark_model_,
161 std::vector<const BookmarkNode*>()); 158 std::vector<const BookmarkNode*>());
162 } 159 }
163 160
164 void BookmarkChangeProcessor::RemoveAllChildNodes( 161 void BookmarkChangeProcessor::RemoveAllChildNodes(
165 syncer::WriteTransaction* trans, const int64& topmost_node_id) { 162 syncer::WriteTransaction* trans, const int64& topmost_node_id) {
166 syncer::WriteNode topmost_node(trans); 163 syncer::WriteNode topmost_node(trans);
167 if (!model_associator_->InitSyncNodeFromChromeId(topmost_node_id, 164 if (!model_associator_->InitSyncNodeFromChromeId(topmost_node_id,
168 &topmost_node)) { 165 &topmost_node)) {
169 syncer::SyncError error(FROM_HERE, 166 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
170 syncer::SyncError::DATATYPE_ERROR, 167 std::string());
171 "Failed to init sync node from chrome node",
172 syncer::BOOKMARKS);
173 error_handler()->OnSingleDataTypeUnrecoverableError(error);
174 return; 168 return;
175 } 169 }
176 const int64 topmost_sync_id = topmost_node.GetId(); 170 const int64 topmost_sync_id = topmost_node.GetId();
177 171
178 // Do a DFS and delete all the child sync nodes, use sync id instead of 172 // Do a DFS and delete all the child sync nodes, use sync id instead of
179 // bookmark node ids since the bookmark nodes may already be deleted. 173 // bookmark node ids since the bookmark nodes may already be deleted.
180 // The equivalent recursive version of this iterative DFS: 174 // The equivalent recursive version of this iterative DFS:
181 // remove_all_children(node_id, topmost_node_id): 175 // remove_all_children(node_id, topmost_node_id):
182 // node.initByIdLookup(node_id) 176 // node.initByIdLookup(node_id)
183 // while(node.GetFirstChildId() != syncer::kInvalidId) 177 // while(node.GetFirstChildId() != syncer::kInvalidId)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 BookmarkModelAssociator* associator, 265 BookmarkModelAssociator* associator,
272 sync_driver::DataTypeErrorHandler* error_handler) { 266 sync_driver::DataTypeErrorHandler* error_handler) {
273 const BookmarkNode* child = parent->GetChild(index); 267 const BookmarkNode* child = parent->GetChild(index);
274 DCHECK(child); 268 DCHECK(child);
275 269
276 // Create a WriteNode container to hold the new node. 270 // Create a WriteNode container to hold the new node.
277 syncer::WriteNode sync_child(trans); 271 syncer::WriteNode sync_child(trans);
278 272
279 // Actually create the node with the appropriate initial position. 273 // Actually create the node with the appropriate initial position.
280 if (!PlaceSyncNode(CREATE, parent, index, trans, &sync_child, associator)) { 274 if (!PlaceSyncNode(CREATE, parent, index, trans, &sync_child, associator)) {
281 syncer::SyncError error(FROM_HERE, 275 error_handler->OnSingleDatatypeUnrecoverableError(FROM_HERE,
282 syncer::SyncError::DATATYPE_ERROR, 276 "Sync node creation failed; recovery unlikely");
283 "Failed ot creat sync node.",
284 syncer::BOOKMARKS);
285 error_handler->OnSingleDataTypeUnrecoverableError(error);
286 return syncer::kInvalidId; 277 return syncer::kInvalidId;
287 } 278 }
288 279
289 UpdateSyncNodeProperties(child, model, &sync_child); 280 UpdateSyncNodeProperties(child, model, &sync_child);
290 281
291 // Associate the ID from the sync domain with the bookmark node, so that we 282 // Associate the ID from the sync domain with the bookmark node, so that we
292 // can refer back to this item later. 283 // can refer back to this item later.
293 associator->Associate(child, sync_child.GetId()); 284 associator->Associate(child, sync_child.GetId());
294 285
295 return sync_child.GetId(); 286 return sync_child.GetId();
(...skipping 27 matching lines...) Expand all
323 // Static. 314 // Static.
324 int64 BookmarkChangeProcessor::UpdateSyncNode( 315 int64 BookmarkChangeProcessor::UpdateSyncNode(
325 const BookmarkNode* node, 316 const BookmarkNode* node,
326 BookmarkModel* model, 317 BookmarkModel* model,
327 syncer::WriteTransaction* trans, 318 syncer::WriteTransaction* trans,
328 BookmarkModelAssociator* associator, 319 BookmarkModelAssociator* associator,
329 sync_driver::DataTypeErrorHandler* error_handler) { 320 sync_driver::DataTypeErrorHandler* error_handler) {
330 // Lookup the sync node that's associated with |node|. 321 // Lookup the sync node that's associated with |node|.
331 syncer::WriteNode sync_node(trans); 322 syncer::WriteNode sync_node(trans);
332 if (!associator->InitSyncNodeFromChromeId(node->id(), &sync_node)) { 323 if (!associator->InitSyncNodeFromChromeId(node->id(), &sync_node)) {
333 syncer::SyncError error(FROM_HERE, 324 error_handler->OnSingleDatatypeUnrecoverableError(
334 syncer::SyncError::DATATYPE_ERROR, 325 FROM_HERE, "Could not load bookmark node on update.");
335 "Failed to init sync node from chrome node",
336 syncer::BOOKMARKS);
337 error_handler->OnSingleDataTypeUnrecoverableError(error);
338 return syncer::kInvalidId; 326 return syncer::kInvalidId;
339 } 327 }
340 UpdateSyncNodeProperties(node, model, &sync_node); 328 UpdateSyncNodeProperties(node, model, &sync_node);
341 DCHECK_EQ(sync_node.GetIsFolder(), node->is_folder()); 329 DCHECK_EQ(sync_node.GetIsFolder(), node->is_folder());
342 DCHECK_EQ(associator->GetChromeNodeFromSyncId(sync_node.GetParentId()), 330 DCHECK_EQ(associator->GetChromeNodeFromSyncId(sync_node.GetParentId()),
343 node->parent()); 331 node->parent());
344 DCHECK_EQ(node->parent()->GetIndexOf(node), sync_node.GetPositionIndex()); 332 DCHECK_EQ(node->parent()->GetIndexOf(node), sync_node.GetPositionIndex());
345 return sync_node.GetId(); 333 return sync_node.GetId();
346 } 334 }
347 335
(...skipping 13 matching lines...) Expand all
361 } 349 }
362 350
363 int64 new_version = syncer::syncable::kInvalidTransactionVersion; 351 int64 new_version = syncer::syncable::kInvalidTransactionVersion;
364 { 352 {
365 // Acquire a scoped write lock via a transaction. 353 // Acquire a scoped write lock via a transaction.
366 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version); 354 syncer::WriteTransaction trans(FROM_HERE, share_handle(), &new_version);
367 355
368 // Lookup the sync node that's associated with |child|. 356 // Lookup the sync node that's associated with |child|.
369 syncer::WriteNode sync_node(&trans); 357 syncer::WriteNode sync_node(&trans);
370 if (!model_associator_->InitSyncNodeFromChromeId(child->id(), &sync_node)) { 358 if (!model_associator_->InitSyncNodeFromChromeId(child->id(), &sync_node)) {
371 syncer::SyncError error(FROM_HERE, 359 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
372 syncer::SyncError::DATATYPE_ERROR, 360 std::string());
373 "Failed to init sync node from chrome node",
374 syncer::BOOKMARKS);
375 error_handler()->OnSingleDataTypeUnrecoverableError(error);
376 return; 361 return;
377 } 362 }
378 363
379 if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node, 364 if (!PlaceSyncNode(MOVE, new_parent, new_index, &trans, &sync_node,
380 model_associator_)) { 365 model_associator_)) {
381 syncer::SyncError error(FROM_HERE, 366 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
382 syncer::SyncError::DATATYPE_ERROR, 367 std::string());
383 "Failed to place sync node",
384 syncer::BOOKMARKS);
385 error_handler()->OnSingleDataTypeUnrecoverableError(error);
386 return; 368 return;
387 } 369 }
388 } 370 }
389 371
390 UpdateTransactionVersion(new_version, model, 372 UpdateTransactionVersion(new_version, model,
391 std::vector<const BookmarkNode*>(1, child)); 373 std::vector<const BookmarkNode*>(1, child));
392 } 374 }
393 375
394 void BookmarkChangeProcessor::BookmarkNodeFaviconChanged( 376 void BookmarkChangeProcessor::BookmarkNodeFaviconChanged(
395 BookmarkModel* model, 377 BookmarkModel* model,
(...skipping 11 matching lines...) Expand all
407 389
408 // The given node's children got reordered. We need to reorder all the 390 // The given node's children got reordered. We need to reorder all the
409 // children of the corresponding sync node. 391 // children of the corresponding sync node.
410 for (int i = 0; i < node->child_count(); ++i) { 392 for (int i = 0; i < node->child_count(); ++i) {
411 const BookmarkNode* child = node->GetChild(i); 393 const BookmarkNode* child = node->GetChild(i);
412 children.push_back(child); 394 children.push_back(child);
413 395
414 syncer::WriteNode sync_child(&trans); 396 syncer::WriteNode sync_child(&trans);
415 if (!model_associator_->InitSyncNodeFromChromeId(child->id(), 397 if (!model_associator_->InitSyncNodeFromChromeId(child->id(),
416 &sync_child)) { 398 &sync_child)) {
417 syncer::SyncError error(FROM_HERE, 399 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
418 syncer::SyncError::DATATYPE_ERROR, 400 std::string());
419 "Failed to init sync node from chrome node",
420 syncer::BOOKMARKS);
421 error_handler()->OnSingleDataTypeUnrecoverableError(error);
422 return; 401 return;
423 } 402 }
424 DCHECK_EQ(sync_child.GetParentId(), 403 DCHECK_EQ(sync_child.GetParentId(),
425 model_associator_->GetSyncIdFromChromeId(node->id())); 404 model_associator_->GetSyncIdFromChromeId(node->id()));
426 405
427 if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child, 406 if (!PlaceSyncNode(MOVE, node, i, &trans, &sync_child,
428 model_associator_)) { 407 model_associator_)) {
429 syncer::SyncError error(FROM_HERE, 408 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
430 syncer::SyncError::DATATYPE_ERROR, 409 std::string());
431 "Failed to place sync node",
432 syncer::BOOKMARKS);
433 error_handler()->OnSingleDataTypeUnrecoverableError(error);
434 return; 410 return;
435 } 411 }
436 } 412 }
437 } 413 }
438 414
439 // TODO(haitaol): Filter out children that didn't actually change. 415 // TODO(haitaol): Filter out children that didn't actually change.
440 UpdateTransactionVersion(new_version, model, children); 416 UpdateTransactionVersion(new_version, model, children);
441 } 417 }
442 418
443 // static 419 // static
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 continue; 521 continue;
546 522
547 // Children of a deleted node should not be deleted; they may be 523 // Children of a deleted node should not be deleted; they may be
548 // reparented by a later change record. Move them to a temporary place. 524 // reparented by a later change record. Move them to a temporary place.
549 if (!dst->empty()) { 525 if (!dst->empty()) {
550 if (!foster_parent) { 526 if (!foster_parent) {
551 foster_parent = model->AddFolder(model->other_node(), 527 foster_parent = model->AddFolder(model->other_node(),
552 model->other_node()->child_count(), 528 model->other_node()->child_count(),
553 base::string16()); 529 base::string16());
554 if (!foster_parent) { 530 if (!foster_parent) {
555 syncer::SyncError error(FROM_HERE, 531 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
556 syncer::SyncError::DATATYPE_ERROR, 532 "Failed to create foster parent.");
557 "Failed to create foster parent",
558 syncer::BOOKMARKS);
559 error_handler()->OnSingleDataTypeUnrecoverableError(error);
560 return; 533 return;
561 } 534 }
562 } 535 }
563 for (int i = dst->child_count() - 1; i >= 0; --i) { 536 for (int i = dst->child_count() - 1; i >= 0; --i) {
564 model->Move(dst->GetChild(i), foster_parent, 537 model->Move(dst->GetChild(i), foster_parent,
565 foster_parent->child_count()); 538 foster_parent->child_count());
566 } 539 }
567 } 540 }
568 DCHECK_EQ(dst->child_count(), 0) << "Node being deleted has children"; 541 DCHECK_EQ(dst->child_count(), 0) << "Node being deleted has children";
569 542
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // This is a newly created Synced Bookmarks node. Associate it. 579 // This is a newly created Synced Bookmarks node. Associate it.
607 model_associator_->Associate(model->mobile_node(), it->id); 580 model_associator_->Associate(model->mobile_node(), it->id);
608 continue; 581 continue;
609 } 582 }
610 583
611 DCHECK_NE(it->action, ChangeRecord::ACTION_DELETE) 584 DCHECK_NE(it->action, ChangeRecord::ACTION_DELETE)
612 << "We should have passed all deletes by this point."; 585 << "We should have passed all deletes by this point.";
613 586
614 syncer::ReadNode src(trans); 587 syncer::ReadNode src(trans);
615 if (src.InitByIdLookup(it->id) != syncer::BaseNode::INIT_OK) { 588 if (src.InitByIdLookup(it->id) != syncer::BaseNode::INIT_OK) {
616 syncer::SyncError error(FROM_HERE, 589 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
617 syncer::SyncError::DATATYPE_ERROR, 590 "ApplyModelChanges was passed a bad ID");
618 "Failed to load sync node",
619 syncer::BOOKMARKS);
620 error_handler()->OnSingleDataTypeUnrecoverableError(error);
621 return; 591 return;
622 } 592 }
623 593
624 const BookmarkNode* parent = 594 const BookmarkNode* parent =
625 model_associator_->GetChromeNodeFromSyncId(src.GetParentId()); 595 model_associator_->GetChromeNodeFromSyncId(src.GetParentId());
626 if (!parent) { 596 if (!parent) {
627 LOG(ERROR) << "Could not find parent of node being added/updated." 597 LOG(ERROR) << "Could not find parent of node being added/updated."
628 << " Node title: " << src.GetTitle() 598 << " Node title: " << src.GetTitle()
629 << ", parent id = " << src.GetParentId(); 599 << ", parent id = " << src.GetParentId();
630 continue; 600 continue;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 sync_pb::BookmarkSpecifics updated_specifics( 838 sync_pb::BookmarkSpecifics updated_specifics(
869 sync_node->GetBookmarkSpecifics()); 839 sync_node->GetBookmarkSpecifics());
870 updated_specifics.set_favicon(favicon_bytes->front(), 840 updated_specifics.set_favicon(favicon_bytes->front(),
871 favicon_bytes->size()); 841 favicon_bytes->size());
872 updated_specifics.set_icon_url(bookmark_node->icon_url().spec()); 842 updated_specifics.set_icon_url(bookmark_node->icon_url().spec());
873 sync_node->SetBookmarkSpecifics(updated_specifics); 843 sync_node->SetBookmarkSpecifics(updated_specifics);
874 } 844 }
875 } 845 }
876 846
877 } // namespace browser_sync 847 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698