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/bookmarks/bookmark_model.cc

Issue 20521005: BookmarkModel::ReorderChildren to take const BookmarkNodes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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
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/bookmarks/bookmark_model.h" 5 #include "chrome/browser/bookmarks/bookmark_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 668
669 if (store_.get()) 669 if (store_.get())
670 store_->ScheduleSave(); 670 store_->ScheduleSave();
671 671
672 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, 672 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
673 BookmarkNodeChildrenReordered(this, parent)); 673 BookmarkNodeChildrenReordered(this, parent));
674 } 674 }
675 675
676 void BookmarkModel::ReorderChildren( 676 void BookmarkModel::ReorderChildren(
677 const BookmarkNode* parent, 677 const BookmarkNode* parent,
678 const std::vector<BookmarkNode*>& ordered_nodes) { 678 const std::vector<const BookmarkNode*>& ordered_nodes) {
679 // Ensure that all children in |parent| are in |ordered_nodes|. 679 // Ensure that all children in |parent| are in |ordered_nodes|.
680 DCHECK_EQ(static_cast<size_t>(parent->child_count()), ordered_nodes.size()); 680 DCHECK_EQ(static_cast<size_t>(parent->child_count()), ordered_nodes.size());
681 for (size_t i = 0; i < ordered_nodes.size(); ++i) 681 for (size_t i = 0; i < ordered_nodes.size(); ++i)
682 DCHECK_EQ(parent, ordered_nodes[i]->parent()); 682 DCHECK_EQ(parent, ordered_nodes[i]->parent());
683 683
684 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, 684 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
685 OnWillReorderBookmarkNode(this, parent)); 685 OnWillReorderBookmarkNode(this, parent));
686 686
687 AsMutable(parent)->SetChildren(ordered_nodes); 687 // SetChildren requires non-const nodes so |ordered_nodes| is reconstructed.
688 std::vector<BookmarkNode*> nodes;
689 nodes.reserve(ordered_nodes.size());
690 for (size_t i = 0; i < ordered_nodes.size(); ++i)
691 nodes.push_back(AsMutable(ordered_nodes[i]));
692
693 AsMutable(parent)->SetChildren(nodes);
sky 2013/08/05 14:53:52 Can you use a const_cast here on ordered_nodes?
Tom Cassiotis 2013/08/05 19:34:49 const_cast is not able to be used here because the
sky 2013/08/05 20:07:45 I think reinterpret_cast is fine here.
688 694
689 if (store_.get()) 695 if (store_.get())
690 store_->ScheduleSave(); 696 store_->ScheduleSave();
691 697
692 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, 698 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
693 BookmarkNodeChildrenReordered(this, parent)); 699 BookmarkNodeChildrenReordered(this, parent));
694 } 700 }
695 701
696 void BookmarkModel::SetDateFolderModified(const BookmarkNode* parent, 702 void BookmarkModel::SetDateFolderModified(const BookmarkNode* parent,
697 const Time time) { 703 const Time time) {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 BookmarkPermanentNode* bb_node = 1054 BookmarkPermanentNode* bb_node =
1049 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); 1055 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR);
1050 BookmarkPermanentNode* other_node = 1056 BookmarkPermanentNode* other_node =
1051 CreatePermanentNode(BookmarkNode::OTHER_NODE); 1057 CreatePermanentNode(BookmarkNode::OTHER_NODE);
1052 BookmarkPermanentNode* mobile_node = 1058 BookmarkPermanentNode* mobile_node =
1053 CreatePermanentNode(BookmarkNode::MOBILE); 1059 CreatePermanentNode(BookmarkNode::MOBILE);
1054 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, 1060 return new BookmarkLoadDetails(bb_node, other_node, mobile_node,
1055 new BookmarkIndex(profile_), 1061 new BookmarkIndex(profile_),
1056 next_node_id_); 1062 next_node_id_);
1057 } 1063 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model.h ('k') | chrome/browser/bookmarks/bookmark_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698