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

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

Issue 9453036: [Sync] Remove --create-mobile-bookmarks-folder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to head Created 8 years, 9 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 (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"
11 #include "base/hash_tables.h" 11 #include "base/hash_tables.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/bookmarks/bookmark_model.h" 15 #include "chrome/browser/bookmarks/bookmark_model.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/sync/api/sync_error.h" 17 #include "chrome/browser/sync/api/sync_error.h"
18 #include "chrome/browser/sync/glue/bookmark_change_processor.h" 18 #include "chrome/browser/sync/glue/bookmark_change_processor.h"
19 #include "chrome/browser/sync/internal_api/read_node.h" 19 #include "chrome/browser/sync/internal_api/read_node.h"
20 #include "chrome/browser/sync/internal_api/read_transaction.h" 20 #include "chrome/browser/sync/internal_api/read_transaction.h"
21 #include "chrome/browser/sync/internal_api/write_node.h" 21 #include "chrome/browser/sync/internal_api/write_node.h"
22 #include "chrome/browser/sync/internal_api/write_transaction.h" 22 #include "chrome/browser/sync/internal_api/write_transaction.h"
23 #include "chrome/browser/sync/util/cryptographer.h" 23 #include "chrome/browser/sync/util/cryptographer.h"
24 #include "chrome/common/chrome_switches.h"
25 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
26 25
27 using content::BrowserThread; 26 using content::BrowserThread;
28 27
29 namespace browser_sync { 28 namespace browser_sync {
30 29
31 // The sync protocol identifies top-level entities by means of well-known tags, 30 // The sync protocol identifies top-level entities by means of well-known tags,
32 // which should not be confused with titles. Each tag corresponds to a 31 // which should not be confused with titles. Each tag corresponds to a
33 // singleton instance of a particular top-level node in a user's share; the 32 // singleton instance of a particular top-level node in a user's share; the
34 // tags are consistent across users. The tags allow us to locate the specific 33 // tags are consistent across users. The tags allow us to locate the specific
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 179 }
181 180
182 const BookmarkNode* BookmarkNodeIdIndex::Find(int64 id) const { 181 const BookmarkNode* BookmarkNodeIdIndex::Find(int64 id) const {
183 BookmarkIdMap::const_iterator iter = node_index_.find(id); 182 BookmarkIdMap::const_iterator iter = node_index_.find(id);
184 return iter == node_index_.end() ? NULL : iter->second; 183 return iter == node_index_.end() ? NULL : iter->second;
185 } 184 }
186 185
187 BookmarkModelAssociator::BookmarkModelAssociator( 186 BookmarkModelAssociator::BookmarkModelAssociator(
188 BookmarkModel* bookmark_model, 187 BookmarkModel* bookmark_model,
189 sync_api::UserShare* user_share, 188 sync_api::UserShare* user_share,
190 DataTypeErrorHandler* unrecoverable_error_handler) 189 DataTypeErrorHandler* unrecoverable_error_handler,
190 bool expect_mobile_bookmarks_folder)
191 : bookmark_model_(bookmark_model), 191 : bookmark_model_(bookmark_model),
192 user_share_(user_share), 192 user_share_(user_share),
193 unrecoverable_error_handler_(unrecoverable_error_handler), 193 unrecoverable_error_handler_(unrecoverable_error_handler),
194 expect_mobile_bookmarks_folder_(expect_mobile_bookmarks_folder),
194 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 195 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
195 number_of_new_sync_nodes_created_at_association_(0) { 196 number_of_new_sync_nodes_created_at_association_(0) {
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
197 DCHECK(bookmark_model_); 198 DCHECK(bookmark_model_);
198 DCHECK(user_share_); 199 DCHECK(user_share_);
199 DCHECK(unrecoverable_error_handler_); 200 DCHECK(unrecoverable_error_handler_);
200 } 201 }
201 202
202 BookmarkModelAssociator::~BookmarkModelAssociator() { 203 BookmarkModelAssociator::~BookmarkModelAssociator() {
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 error->Reset(FROM_HERE, kServerError, model_type()); 393 error->Reset(FROM_HERE, kServerError, model_type());
393 return false; 394 return false;
394 } 395 }
395 if (!AssociateTaggedPermanentNode(bookmark_model_->bookmark_bar_node(), 396 if (!AssociateTaggedPermanentNode(bookmark_model_->bookmark_bar_node(),
396 kBookmarkBarTag)) { 397 kBookmarkBarTag)) {
397 error->Reset(FROM_HERE, kServerError, model_type()); 398 error->Reset(FROM_HERE, kServerError, model_type());
398 return false; 399 return false;
399 } 400 }
400 if (!AssociateTaggedPermanentNode(bookmark_model_->mobile_node(), 401 if (!AssociateTaggedPermanentNode(bookmark_model_->mobile_node(),
401 kMobileBookmarksTag) && 402 kMobileBookmarksTag) &&
402 // The mobile folder only need exist if kCreateMobileBookmarksFolder is 403 expect_mobile_bookmarks_folder_) {
403 // set.
404 CommandLine::ForCurrentProcess()->HasSwitch(
405 switches::kCreateMobileBookmarksFolder)) {
406 error->Reset(FROM_HERE, kServerError, model_type()); 404 error->Reset(FROM_HERE, kServerError, model_type());
407 return false; 405 return false;
408 } 406 }
407
409 int64 bookmark_bar_sync_id = GetSyncIdFromChromeId( 408 int64 bookmark_bar_sync_id = GetSyncIdFromChromeId(
410 bookmark_model_->bookmark_bar_node()->id()); 409 bookmark_model_->bookmark_bar_node()->id());
411 DCHECK_NE(bookmark_bar_sync_id, sync_api::kInvalidId); 410 DCHECK_NE(bookmark_bar_sync_id, sync_api::kInvalidId);
412 int64 other_bookmarks_sync_id = GetSyncIdFromChromeId( 411 int64 other_bookmarks_sync_id = GetSyncIdFromChromeId(
413 bookmark_model_->other_node()->id()); 412 bookmark_model_->other_node()->id());
414 DCHECK_NE(other_bookmarks_sync_id, sync_api::kInvalidId); 413 DCHECK_NE(other_bookmarks_sync_id, sync_api::kInvalidId);
415 int64 mobile_bookmarks_sync_id = GetSyncIdFromChromeId( 414 int64 mobile_bookmarks_sync_id = GetSyncIdFromChromeId(
416 bookmark_model_->mobile_node()->id()); 415 bookmark_model_->mobile_node()->id());
417 if (CommandLine::ForCurrentProcess()->HasSwitch( 416 if (expect_mobile_bookmarks_folder_) {
418 switches::kCreateMobileBookmarksFolder)) {
419 DCHECK_NE(sync_api::kInvalidId, mobile_bookmarks_sync_id); 417 DCHECK_NE(sync_api::kInvalidId, mobile_bookmarks_sync_id);
420 } 418 }
421 419
422 std::stack<int64> dfs_stack; 420 std::stack<int64> dfs_stack;
423 if (mobile_bookmarks_sync_id != sync_api::kInvalidId) 421 if (mobile_bookmarks_sync_id != sync_api::kInvalidId)
424 dfs_stack.push(mobile_bookmarks_sync_id); 422 dfs_stack.push(mobile_bookmarks_sync_id);
425 dfs_stack.push(other_bookmarks_sync_id); 423 dfs_stack.push(other_bookmarks_sync_id);
426 dfs_stack.push(bookmark_bar_sync_id); 424 dfs_stack.push(bookmark_bar_sync_id);
427 425
428 sync_api::WriteTransaction trans(FROM_HERE, user_share_); 426 sync_api::WriteTransaction trans(FROM_HERE, user_share_);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 // We should always be able to find the permanent nodes. 562 // We should always be able to find the permanent nodes.
565 return false; 563 return false;
566 } 564 }
567 int64 other_bookmarks_id; 565 int64 other_bookmarks_id;
568 if (!GetSyncIdForTaggedNode(kOtherBookmarksTag, &other_bookmarks_id)) { 566 if (!GetSyncIdForTaggedNode(kOtherBookmarksTag, &other_bookmarks_id)) {
569 // We should always be able to find the permanent nodes. 567 // We should always be able to find the permanent nodes.
570 return false; 568 return false;
571 } 569 }
572 int64 mobile_bookmarks_id = -1; 570 int64 mobile_bookmarks_id = -1;
573 if (!GetSyncIdForTaggedNode(kMobileBookmarksTag, &mobile_bookmarks_id) && 571 if (!GetSyncIdForTaggedNode(kMobileBookmarksTag, &mobile_bookmarks_id) &&
574 CommandLine::ForCurrentProcess()->HasSwitch( 572 expect_mobile_bookmarks_folder_) {
575 switches::kCreateMobileBookmarksFolder)) {
576 return false; 573 return false;
577 } 574 }
578 575
579 // Build a bookmark node ID index since we are going to repeatedly search for 576 // Build a bookmark node ID index since we are going to repeatedly search for
580 // bookmark nodes by their IDs. 577 // bookmark nodes by their IDs.
581 BookmarkNodeIdIndex id_index; 578 BookmarkNodeIdIndex id_index;
582 id_index.AddAll(bookmark_model_->bookmark_bar_node()); 579 id_index.AddAll(bookmark_model_->bookmark_bar_node());
583 id_index.AddAll(bookmark_model_->other_node()); 580 id_index.AddAll(bookmark_model_->other_node());
584 id_index.AddAll(bookmark_model_->mobile_node()); 581 id_index.AddAll(bookmark_model_->mobile_node());
585 582
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 bool BookmarkModelAssociator::CryptoReadyIfNecessary() { 642 bool BookmarkModelAssociator::CryptoReadyIfNecessary() {
646 // We only access the cryptographer while holding a transaction. 643 // We only access the cryptographer while holding a transaction.
647 sync_api::ReadTransaction trans(FROM_HERE, user_share_); 644 sync_api::ReadTransaction trans(FROM_HERE, user_share_);
648 const syncable::ModelTypeSet encrypted_types = 645 const syncable::ModelTypeSet encrypted_types =
649 sync_api::GetEncryptedTypes(&trans); 646 sync_api::GetEncryptedTypes(&trans);
650 return !encrypted_types.Has(syncable::BOOKMARKS) || 647 return !encrypted_types.Has(syncable::BOOKMARKS) ||
651 trans.GetCryptographer()->is_ready(); 648 trans.GetCryptographer()->is_ready();
652 } 649 }
653 650
654 } // namespace browser_sync 651 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/bookmark_model_associator.h ('k') | chrome/browser/sync/profile_sync_components_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698