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

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

Issue 8790008: Changes BookmarkModelAssociator not to fail if mobile folder doesn't (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 AssociateTaggedPermanentNode(bookmark_model_->mobile_node(),
akalin 2011/12/03 00:12:20 #include compiler specific and use ignore_result
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
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 GetSyncIdForTaggedNode(kMobileBookmarksTag, &mobile_bookmarks_id);
akalin 2011/12/03 00:12:20 here, too
529 // We should always be able to find the permanent nodes.
530 return false;
531 }
532 527
533 // Build a bookmark node ID index since we are going to repeatedly search for 528 // Build a bookmark node ID index since we are going to repeatedly search for
534 // bookmark nodes by their IDs. 529 // bookmark nodes by their IDs.
535 BookmarkNodeIdIndex id_index; 530 BookmarkNodeIdIndex id_index;
536 id_index.AddAll(bookmark_model_->bookmark_bar_node()); 531 id_index.AddAll(bookmark_model_->bookmark_bar_node());
537 id_index.AddAll(bookmark_model_->other_node()); 532 id_index.AddAll(bookmark_model_->other_node());
538 id_index.AddAll(bookmark_model_->mobile_node()); 533 id_index.AddAll(bookmark_model_->mobile_node());
539 534
540 std::stack<int64> dfs_stack; 535 std::stack<int64> dfs_stack;
541 dfs_stack.push(mobile_bookmarks_id); 536 if (mobile_bookmarks_id != -1)
537 dfs_stack.push(mobile_bookmarks_id);
542 dfs_stack.push(other_bookmarks_id); 538 dfs_stack.push(other_bookmarks_id);
543 dfs_stack.push(bookmark_bar_id); 539 dfs_stack.push(bookmark_bar_id);
544 540
545 sync_api::ReadTransaction trans(FROM_HERE, user_share_); 541 sync_api::ReadTransaction trans(FROM_HERE, user_share_);
546 542
547 // Count total number of nodes in sync model so that we can compare that 543 // 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. 544 // with the total number of nodes in the bookmark model.
549 size_t sync_node_count = 0; 545 size_t sync_node_count = 0;
550 while (!dfs_stack.empty()) { 546 while (!dfs_stack.empty()) {
551 int64 parent_id = dfs_stack.top(); 547 int64 parent_id = dfs_stack.top();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 bool BookmarkModelAssociator::CryptoReadyIfNecessary() { 594 bool BookmarkModelAssociator::CryptoReadyIfNecessary() {
599 // We only access the cryptographer while holding a transaction. 595 // We only access the cryptographer while holding a transaction.
600 sync_api::ReadTransaction trans(FROM_HERE, user_share_); 596 sync_api::ReadTransaction trans(FROM_HERE, user_share_);
601 const syncable::ModelTypeSet& encrypted_types = 597 const syncable::ModelTypeSet& encrypted_types =
602 sync_api::GetEncryptedTypes(&trans); 598 sync_api::GetEncryptedTypes(&trans);
603 return encrypted_types.count(syncable::BOOKMARKS) == 0 || 599 return encrypted_types.count(syncable::BOOKMARKS) == 0 ||
604 trans.GetCryptographer()->is_ready(); 600 trans.GetCryptographer()->is_ready();
605 } 601 }
606 602
607 } // namespace browser_sync 603 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698