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

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

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

Powered by Google App Engine
This is Rietveld 408576698