| OLD | NEW |
| 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 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 bookmarks->push_back(bookmark); | 486 bookmarks->push_back(bookmark); |
| 487 } | 487 } |
| 488 last_url = url; | 488 last_url = url; |
| 489 } | 489 } |
| 490 } | 490 } |
| 491 | 491 |
| 492 void BookmarkModel::BlockTillLoaded() { | 492 void BookmarkModel::BlockTillLoaded() { |
| 493 loaded_signal_.Wait(); | 493 loaded_signal_.Wait(); |
| 494 } | 494 } |
| 495 | 495 |
| 496 const BookmarkNode* BookmarkModel::GetNodeByID(int64 id) const { | |
| 497 // TODO(sky): TreeNode needs a method that visits all nodes using a predicate. | |
| 498 return GetNodeByID(&root_, id); | |
| 499 } | |
| 500 | |
| 501 const BookmarkNode* BookmarkModel::AddFolder(const BookmarkNode* parent, | 496 const BookmarkNode* BookmarkModel::AddFolder(const BookmarkNode* parent, |
| 502 int index, | 497 int index, |
| 503 const base::string16& title) { | 498 const base::string16& title) { |
| 504 if (!loaded_ || is_root_node(parent) || !IsValidIndex(parent, index, true)) { | 499 if (!loaded_ || is_root_node(parent) || !IsValidIndex(parent, index, true)) { |
| 505 // Can't add to the root. | 500 // Can't add to the root. |
| 506 NOTREACHED(); | 501 NOTREACHED(); |
| 507 return NULL; | 502 return NULL; |
| 508 } | 503 } |
| 509 | 504 |
| 510 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), GURL()); | 505 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), GURL()); |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 store_->ScheduleSave(); | 805 store_->ScheduleSave(); |
| 811 | 806 |
| 812 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, | 807 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, |
| 813 BookmarkNodeAdded(this, parent, index)); | 808 BookmarkNodeAdded(this, parent, index)); |
| 814 | 809 |
| 815 index_->Add(node); | 810 index_->Add(node); |
| 816 | 811 |
| 817 return node; | 812 return node; |
| 818 } | 813 } |
| 819 | 814 |
| 820 const BookmarkNode* BookmarkModel::GetNodeByID(const BookmarkNode* node, | |
| 821 int64 id) const { | |
| 822 if (node->id() == id) | |
| 823 return node; | |
| 824 | |
| 825 for (int i = 0, child_count = node->child_count(); i < child_count; ++i) { | |
| 826 const BookmarkNode* result = GetNodeByID(node->GetChild(i), id); | |
| 827 if (result) | |
| 828 return result; | |
| 829 } | |
| 830 return NULL; | |
| 831 } | |
| 832 | |
| 833 bool BookmarkModel::IsValidIndex(const BookmarkNode* parent, | 815 bool BookmarkModel::IsValidIndex(const BookmarkNode* parent, |
| 834 int index, | 816 int index, |
| 835 bool allow_end) { | 817 bool allow_end) { |
| 836 return (parent && parent->is_folder() && | 818 return (parent && parent->is_folder() && |
| 837 (index >= 0 && (index < parent->child_count() || | 819 (index >= 0 && (index < parent->child_count() || |
| 838 (allow_end && index == parent->child_count())))); | 820 (allow_end && index == parent->child_count())))); |
| 839 } | 821 } |
| 840 | 822 |
| 841 BookmarkPermanentNode* BookmarkModel::CreatePermanentNode( | 823 BookmarkPermanentNode* BookmarkModel::CreatePermanentNode( |
| 842 BookmarkNode::Type type) { | 824 BookmarkNode::Type type) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 BookmarkPermanentNode* bb_node = | 942 BookmarkPermanentNode* bb_node = |
| 961 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 943 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
| 962 BookmarkPermanentNode* other_node = | 944 BookmarkPermanentNode* other_node = |
| 963 CreatePermanentNode(BookmarkNode::OTHER_NODE); | 945 CreatePermanentNode(BookmarkNode::OTHER_NODE); |
| 964 BookmarkPermanentNode* mobile_node = | 946 BookmarkPermanentNode* mobile_node = |
| 965 CreatePermanentNode(BookmarkNode::MOBILE); | 947 CreatePermanentNode(BookmarkNode::MOBILE); |
| 966 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, | 948 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, |
| 967 new BookmarkIndex(profile_), | 949 new BookmarkIndex(profile_), |
| 968 next_node_id_); | 950 next_node_id_); |
| 969 } | 951 } |
| OLD | NEW |