OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 if (!AssociateTaggedPermanentNode(bookmark_model_->other_node(), | 361 if (!AssociateTaggedPermanentNode(bookmark_model_->other_node(), |
362 kOtherBookmarksTag)) { | 362 kOtherBookmarksTag)) { |
363 error->Reset(FROM_HERE, kServerError, model_type()); | 363 error->Reset(FROM_HERE, kServerError, model_type()); |
364 return false; | 364 return false; |
365 } | 365 } |
366 if (!AssociateTaggedPermanentNode(bookmark_model_->bookmark_bar_node(), | 366 if (!AssociateTaggedPermanentNode(bookmark_model_->bookmark_bar_node(), |
367 kBookmarkBarTag)) { | 367 kBookmarkBarTag)) { |
368 error->Reset(FROM_HERE, kServerError, model_type()); | 368 error->Reset(FROM_HERE, kServerError, model_type()); |
369 return false; | 369 return false; |
370 } | 370 } |
371 if (!AssociateTaggedPermanentNode(bookmark_model_->mobile_node(), | 371 // The mobile folder isn't always present on the backend, so we don't fail if |
372 kMobileBookmarksTag)) { | 372 // it doesn't exist. |
373 error->Reset(FROM_HERE, kServerError, model_type()); | 373 ignore_result(AssociateTaggedPermanentNode(bookmark_model_->mobile_node(), |
374 return false; | 374 kMobileBookmarksTag)); |
375 } | |
376 int64 bookmark_bar_sync_id = GetSyncIdFromChromeId( | 375 int64 bookmark_bar_sync_id = GetSyncIdFromChromeId( |
377 bookmark_model_->bookmark_bar_node()->id()); | 376 bookmark_model_->bookmark_bar_node()->id()); |
378 DCHECK_NE(bookmark_bar_sync_id, sync_api::kInvalidId); | 377 DCHECK_NE(bookmark_bar_sync_id, sync_api::kInvalidId); |
379 int64 other_bookmarks_sync_id = GetSyncIdFromChromeId( | 378 int64 other_bookmarks_sync_id = GetSyncIdFromChromeId( |
380 bookmark_model_->other_node()->id()); | 379 bookmark_model_->other_node()->id()); |
381 DCHECK_NE(other_bookmarks_sync_id, sync_api::kInvalidId); | 380 DCHECK_NE(other_bookmarks_sync_id, sync_api::kInvalidId); |
382 int64 mobile_bookmarks_sync_id = GetSyncIdFromChromeId( | 381 int64 mobile_bookmarks_sync_id = GetSyncIdFromChromeId( |
383 bookmark_model_->mobile_node()->id()); | 382 bookmark_model_->mobile_node()->id()); |
384 DCHECK_NE(mobile_bookmarks_sync_id, sync_api::kInvalidId); | |
385 | 383 |
386 std::stack<int64> dfs_stack; | 384 std::stack<int64> dfs_stack; |
387 if (mobile_bookmarks_sync_id != sync_api::kInvalidId) | 385 if (mobile_bookmarks_sync_id != sync_api::kInvalidId) |
388 dfs_stack.push(mobile_bookmarks_sync_id); | 386 dfs_stack.push(mobile_bookmarks_sync_id); |
389 dfs_stack.push(other_bookmarks_sync_id); | 387 dfs_stack.push(other_bookmarks_sync_id); |
390 dfs_stack.push(bookmark_bar_sync_id); | 388 dfs_stack.push(bookmark_bar_sync_id); |
391 | 389 |
392 sync_api::WriteTransaction trans(FROM_HERE, user_share_); | 390 sync_api::WriteTransaction trans(FROM_HERE, user_share_); |
393 | 391 |
394 while (!dfs_stack.empty()) { | 392 while (!dfs_stack.empty()) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 if (!GetSyncIdForTaggedNode(kBookmarkBarTag, &bookmark_bar_id)) { | 516 if (!GetSyncIdForTaggedNode(kBookmarkBarTag, &bookmark_bar_id)) { |
519 // We should always be able to find the permanent nodes. | 517 // We should always be able to find the permanent nodes. |
520 return false; | 518 return false; |
521 } | 519 } |
522 int64 other_bookmarks_id; | 520 int64 other_bookmarks_id; |
523 if (!GetSyncIdForTaggedNode(kOtherBookmarksTag, &other_bookmarks_id)) { | 521 if (!GetSyncIdForTaggedNode(kOtherBookmarksTag, &other_bookmarks_id)) { |
524 // We should always be able to find the permanent nodes. | 522 // We should always be able to find the permanent nodes. |
525 return false; | 523 return false; |
526 } | 524 } |
527 int64 mobile_bookmarks_id = -1; | 525 int64 mobile_bookmarks_id = -1; |
528 if (!GetSyncIdForTaggedNode(kMobileBookmarksTag, &mobile_bookmarks_id)) { | 526 // Can't fail here as the mobile folder may not exist. |
529 // We should always be able to find the permanent nodes. | 527 ignore_result( |
530 return false; | 528 GetSyncIdForTaggedNode(kMobileBookmarksTag, &mobile_bookmarks_id)); |
531 } | |
532 | 529 |
533 // Build a bookmark node ID index since we are going to repeatedly search for | 530 // Build a bookmark node ID index since we are going to repeatedly search for |
534 // bookmark nodes by their IDs. | 531 // bookmark nodes by their IDs. |
535 BookmarkNodeIdIndex id_index; | 532 BookmarkNodeIdIndex id_index; |
536 id_index.AddAll(bookmark_model_->bookmark_bar_node()); | 533 id_index.AddAll(bookmark_model_->bookmark_bar_node()); |
537 id_index.AddAll(bookmark_model_->other_node()); | 534 id_index.AddAll(bookmark_model_->other_node()); |
538 id_index.AddAll(bookmark_model_->mobile_node()); | 535 id_index.AddAll(bookmark_model_->mobile_node()); |
539 | 536 |
540 std::stack<int64> dfs_stack; | 537 std::stack<int64> dfs_stack; |
541 dfs_stack.push(mobile_bookmarks_id); | 538 if (mobile_bookmarks_id != -1) |
| 539 dfs_stack.push(mobile_bookmarks_id); |
542 dfs_stack.push(other_bookmarks_id); | 540 dfs_stack.push(other_bookmarks_id); |
543 dfs_stack.push(bookmark_bar_id); | 541 dfs_stack.push(bookmark_bar_id); |
544 | 542 |
545 sync_api::ReadTransaction trans(FROM_HERE, user_share_); | 543 sync_api::ReadTransaction trans(FROM_HERE, user_share_); |
546 | 544 |
547 // Count total number of nodes in sync model so that we can compare that | 545 // Count total number of nodes in sync model so that we can compare that |
548 // with the total number of nodes in the bookmark model. | 546 // with the total number of nodes in the bookmark model. |
549 size_t sync_node_count = 0; | 547 size_t sync_node_count = 0; |
550 while (!dfs_stack.empty()) { | 548 while (!dfs_stack.empty()) { |
551 int64 parent_id = dfs_stack.top(); | 549 int64 parent_id = dfs_stack.top(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 bool BookmarkModelAssociator::CryptoReadyIfNecessary() { | 596 bool BookmarkModelAssociator::CryptoReadyIfNecessary() { |
599 // We only access the cryptographer while holding a transaction. | 597 // We only access the cryptographer while holding a transaction. |
600 sync_api::ReadTransaction trans(FROM_HERE, user_share_); | 598 sync_api::ReadTransaction trans(FROM_HERE, user_share_); |
601 const syncable::ModelTypeSet& encrypted_types = | 599 const syncable::ModelTypeSet& encrypted_types = |
602 sync_api::GetEncryptedTypes(&trans); | 600 sync_api::GetEncryptedTypes(&trans); |
603 return encrypted_types.count(syncable::BOOKMARKS) == 0 || | 601 return encrypted_types.count(syncable::BOOKMARKS) == 0 || |
604 trans.GetCryptographer()->is_ready(); | 602 trans.GetCryptographer()->is_ready(); |
605 } | 603 } |
606 | 604 |
607 } // namespace browser_sync | 605 } // namespace browser_sync |
OLD | NEW |