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

Side by Side Diff: components/sync_bookmarks/bookmark_model_associator.cc

Issue 1454983004: Bookmark permanent nodes' visibility is embedder's business. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « components/sync_bookmarks/bookmark_model_associator.h ('k') | 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 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 "components/sync_bookmarks/bookmark_model_associator.h" 5 #include "components/sync_bookmarks/bookmark_model_associator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 weak_factory_(this) { 364 weak_factory_(this) {
365 DCHECK(bookmark_model_); 365 DCHECK(bookmark_model_);
366 DCHECK(user_share_); 366 DCHECK(user_share_);
367 DCHECK(unrecoverable_error_handler_); 367 DCHECK(unrecoverable_error_handler_);
368 } 368 }
369 369
370 BookmarkModelAssociator::~BookmarkModelAssociator() { 370 BookmarkModelAssociator::~BookmarkModelAssociator() {
371 DCHECK(thread_checker_.CalledOnValidThread()); 371 DCHECK(thread_checker_.CalledOnValidThread());
372 } 372 }
373 373
374 void BookmarkModelAssociator::UpdatePermanentNodeVisibility() {
375 DCHECK(thread_checker_.CalledOnValidThread());
376 DCHECK(bookmark_model_->loaded());
377
378 BookmarkNode::Type bookmark_node_types[] = {
379 BookmarkNode::BOOKMARK_BAR,
380 BookmarkNode::OTHER_NODE,
381 BookmarkNode::MOBILE,
382 };
383 for (size_t i = 0; i < arraysize(bookmark_node_types); ++i) {
384 int64 id = bookmark_model_->PermanentNode(bookmark_node_types[i])->id();
385 bookmark_model_->SetPermanentNodeVisible(
386 bookmark_node_types[i],
387 id_map_.find(id) != id_map_.end());
388 }
389
390 // Note: the root node may have additional extra nodes. Currently their
391 // visibility is not affected by sync.
392 }
393
394 syncer::SyncError BookmarkModelAssociator::DisassociateModels() { 374 syncer::SyncError BookmarkModelAssociator::DisassociateModels() {
395 id_map_.clear(); 375 id_map_.clear();
396 id_map_inverse_.clear(); 376 id_map_inverse_.clear();
397 dirty_associations_sync_ids_.clear(); 377 dirty_associations_sync_ids_.clear();
398 return syncer::SyncError(); 378 return syncer::SyncError();
399 } 379 }
400 380
401 int64 BookmarkModelAssociator::GetSyncIdFromChromeId(const int64& node_id) { 381 int64 BookmarkModelAssociator::GetSyncIdFromChromeId(const int64& node_id) {
402 BookmarkIdToSyncIdMap::const_iterator iter = id_map_.find(node_id); 382 BookmarkIdToSyncIdMap::const_iterator iter = id_map_.find(node_id);
403 return iter == id_map_.end() ? syncer::kInvalidId : iter->second; 383 return iter == id_map_.end() ? syncer::kInvalidId : iter->second;
(...skipping 26 matching lines...) Expand all
430 DCHECK(id_map_.find(node_id) == id_map_.end()); 410 DCHECK(id_map_.find(node_id) == id_map_.end());
431 DCHECK(id_map_inverse_.find(sync_id) == id_map_inverse_.end()); 411 DCHECK(id_map_inverse_.find(sync_id) == id_map_inverse_.end());
432 id_map_[node_id] = sync_id; 412 id_map_[node_id] = sync_id;
433 id_map_inverse_[sync_id] = node; 413 id_map_inverse_[sync_id] = node;
434 } 414 }
435 415
436 void BookmarkModelAssociator::Associate(const BookmarkNode* node, 416 void BookmarkModelAssociator::Associate(const BookmarkNode* node,
437 const syncer::BaseNode& sync_node) { 417 const syncer::BaseNode& sync_node) {
438 AddAssociation(node, sync_node.GetId()); 418 AddAssociation(node, sync_node.GetId());
439 419
440 // TODO(stanisc): crbug.com/456876: consider not doing this on every single
noyau (Ping after 24h) 2015/11/18 16:49:15 Please add this bug number to the bug description
441 // association.
442 UpdatePermanentNodeVisibility();
443
444 // The same check exists in PersistAssociations. However it is better to 420 // The same check exists in PersistAssociations. However it is better to
445 // do the check earlier to avoid the cost of decrypting nodes again 421 // do the check earlier to avoid the cost of decrypting nodes again
446 // in PersistAssociations. 422 // in PersistAssociations.
447 if (node->id() != sync_node.GetExternalId()) { 423 if (node->id() != sync_node.GetExternalId()) {
448 dirty_associations_sync_ids_.insert(sync_node.GetId()); 424 dirty_associations_sync_ids_.insert(sync_node.GetId());
449 PostPersistAssociationsTask(); 425 PostPersistAssociationsTask();
450 } 426 }
451 } 427 }
452 428
453 void BookmarkModelAssociator::Disassociate(int64 sync_id) { 429 void BookmarkModelAssociator::Disassociate(int64 sync_id) {
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 syncer::BOOKMARKS); 1162 syncer::BOOKMARKS);
1187 } else { 1163 } else {
1188 context->set_native_model_sync_state(BEHIND); 1164 context->set_native_model_sync_state(BEHIND);
1189 } 1165 }
1190 } 1166 }
1191 } 1167 }
1192 return syncer::SyncError(); 1168 return syncer::SyncError();
1193 } 1169 }
1194 1170
1195 } // namespace browser_sync 1171 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/sync_bookmarks/bookmark_model_associator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698