OLD | NEW |
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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 if (bookmark->is_url()) { | 324 if (bookmark->is_url()) { |
325 if (bookmark->url() != sync_node->GetURL()) | 325 if (bookmark->url() != sync_node->GetURL()) |
326 return false; | 326 return false; |
327 } | 327 } |
328 // Don't compare favicons here, because they are not really | 328 // Don't compare favicons here, because they are not really |
329 // user-updated and we don't have versioning information -- a site changing | 329 // user-updated and we don't have versioning information -- a site changing |
330 // its favicon shouldn't result in a bookmark mismatch. | 330 // its favicon shouldn't result in a bookmark mismatch. |
331 return true; | 331 return true; |
332 } | 332 } |
333 | 333 |
334 syncer::SyncError BookmarkModelAssociator::AssociateTaggedPermanentNode( | 334 bool BookmarkModelAssociator::AssociateTaggedPermanentNode( |
335 const BookmarkNode* permanent_node, const std::string&tag) { | 335 const BookmarkNode* permanent_node, const std::string&tag) { |
336 // Do nothing if |permanent_node| is already initialized and associated. | 336 // Do nothing if |permanent_node| is already initialized and associated. |
337 int64 sync_id = GetSyncIdFromChromeId(permanent_node->id()); | 337 int64 sync_id = GetSyncIdFromChromeId(permanent_node->id()); |
338 if (sync_id != syncer::kInvalidId) | 338 if (sync_id != syncer::kInvalidId) |
339 return syncer::SyncError(); | 339 return true; |
340 if (!GetSyncIdForTaggedNode(tag, &sync_id)) | 340 if (!GetSyncIdForTaggedNode(tag, &sync_id)) |
341 return unrecoverable_error_handler_->CreateAndUploadError( | 341 return false; |
342 FROM_HERE, | |
343 "Permanent node not found", | |
344 model_type()); | |
345 | 342 |
346 Associate(permanent_node, sync_id); | 343 Associate(permanent_node, sync_id); |
347 return syncer::SyncError(); | 344 return true; |
348 } | 345 } |
349 | 346 |
350 bool BookmarkModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, | 347 bool BookmarkModelAssociator::GetSyncIdForTaggedNode(const std::string& tag, |
351 int64* sync_id) { | 348 int64* sync_id) { |
352 syncer::ReadTransaction trans(FROM_HERE, user_share_); | 349 syncer::ReadTransaction trans(FROM_HERE, user_share_); |
353 syncer::ReadNode sync_node(&trans); | 350 syncer::ReadNode sync_node(&trans); |
354 if (sync_node.InitByTagLookup(tag.c_str()) != syncer::BaseNode::INIT_OK) | 351 if (sync_node.InitByTagLookup(tag.c_str()) != syncer::BaseNode::INIT_OK) |
355 return false; | 352 return false; |
356 *sync_id = sync_node.GetId(); | 353 *sync_id = sync_node.GetId(); |
357 return true; | 354 return true; |
(...skipping 25 matching lines...) Expand all Loading... |
383 // corresponding sync node. | 380 // corresponding sync node. |
384 // * When all children sync nodes are done, add the extra children bookmark | 381 // * When all children sync nodes are done, add the extra children bookmark |
385 // nodes to the sync parent node. | 382 // nodes to the sync parent node. |
386 // | 383 // |
387 // This algorithm will do a good job of merging when folder names are a good | 384 // This algorithm will do a good job of merging when folder names are a good |
388 // indicator of the two folders being the same. It will handle reordering and | 385 // indicator of the two folders being the same. It will handle reordering and |
389 // new node addition very well (without creating duplicates). | 386 // new node addition very well (without creating duplicates). |
390 // This algorithm will not do well if the folder name has changes but the | 387 // This algorithm will not do well if the folder name has changes but the |
391 // children under them are all the same. | 388 // children under them are all the same. |
392 | 389 |
393 syncer::SyncError error; | |
394 DCHECK(bookmark_model_->IsLoaded()); | 390 DCHECK(bookmark_model_->IsLoaded()); |
395 | 391 |
396 // To prime our association, we associate the top-level nodes, Bookmark Bar | 392 // To prime our association, we associate the top-level nodes, Bookmark Bar |
397 // and Other Bookmarks. | 393 // and Other Bookmarks. |
398 error = AssociateTaggedPermanentNode(bookmark_model_->other_node(), | 394 if (!AssociateTaggedPermanentNode(bookmark_model_->other_node(), |
399 kOtherBookmarksTag); | 395 kOtherBookmarksTag)) { |
400 if (error.IsSet()) | 396 return unrecoverable_error_handler_->CreateAndUploadError( |
401 return error; | 397 FROM_HERE, |
| 398 "Other bookmarks node not found", |
| 399 model_type()); |
| 400 } |
402 | 401 |
403 error = AssociateTaggedPermanentNode(bookmark_model_->bookmark_bar_node(), | 402 if (!AssociateTaggedPermanentNode(bookmark_model_->bookmark_bar_node(), |
404 kBookmarkBarTag); | 403 kBookmarkBarTag)) { |
405 if (error.IsSet()) | 404 return unrecoverable_error_handler_->CreateAndUploadError( |
406 return error; | 405 FROM_HERE, |
| 406 "Bookmark bar node not found", |
| 407 model_type()); |
| 408 } |
407 | 409 |
408 error = AssociateTaggedPermanentNode(bookmark_model_->mobile_node(), | 410 if (!AssociateTaggedPermanentNode(bookmark_model_->mobile_node(), |
409 kMobileBookmarksTag); | 411 kMobileBookmarksTag) && |
410 if (error.IsSet() && expect_mobile_bookmarks_folder_) | 412 expect_mobile_bookmarks_folder_) { |
411 return error; | 413 return unrecoverable_error_handler_->CreateAndUploadError( |
412 error = syncer::SyncError(); | 414 FROM_HERE, |
| 415 "Mobile bookmarks node not found", |
| 416 model_type()); |
| 417 } |
413 | 418 |
414 int64 bookmark_bar_sync_id = GetSyncIdFromChromeId( | 419 int64 bookmark_bar_sync_id = GetSyncIdFromChromeId( |
415 bookmark_model_->bookmark_bar_node()->id()); | 420 bookmark_model_->bookmark_bar_node()->id()); |
416 DCHECK_NE(bookmark_bar_sync_id, syncer::kInvalidId); | 421 DCHECK_NE(bookmark_bar_sync_id, syncer::kInvalidId); |
417 int64 other_bookmarks_sync_id = GetSyncIdFromChromeId( | 422 int64 other_bookmarks_sync_id = GetSyncIdFromChromeId( |
418 bookmark_model_->other_node()->id()); | 423 bookmark_model_->other_node()->id()); |
419 DCHECK_NE(other_bookmarks_sync_id, syncer::kInvalidId); | 424 DCHECK_NE(other_bookmarks_sync_id, syncer::kInvalidId); |
420 int64 mobile_bookmarks_sync_id = GetSyncIdFromChromeId( | 425 int64 mobile_bookmarks_sync_id = GetSyncIdFromChromeId( |
421 bookmark_model_->mobile_node()->id()); | 426 bookmark_model_->mobile_node()->id()); |
422 if (expect_mobile_bookmarks_folder_) { | 427 if (expect_mobile_bookmarks_folder_) { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 bool BookmarkModelAssociator::CryptoReadyIfNecessary() { | 664 bool BookmarkModelAssociator::CryptoReadyIfNecessary() { |
660 // We only access the cryptographer while holding a transaction. | 665 // We only access the cryptographer while holding a transaction. |
661 syncer::ReadTransaction trans(FROM_HERE, user_share_); | 666 syncer::ReadTransaction trans(FROM_HERE, user_share_); |
662 const syncer::ModelTypeSet encrypted_types = | 667 const syncer::ModelTypeSet encrypted_types = |
663 syncer::GetEncryptedTypes(&trans); | 668 syncer::GetEncryptedTypes(&trans); |
664 return !encrypted_types.Has(syncer::BOOKMARKS) || | 669 return !encrypted_types.Has(syncer::BOOKMARKS) || |
665 trans.GetCryptographer()->is_ready(); | 670 trans.GetCryptographer()->is_ready(); |
666 } | 671 } |
667 | 672 |
668 } // namespace browser_sync | 673 } // namespace browser_sync |
OLD | NEW |