| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 196 |
| 197 // BookmarkModel -------------------------------------------------------------- | 197 // BookmarkModel -------------------------------------------------------------- |
| 198 | 198 |
| 199 BookmarkModel::BookmarkModel(Profile* profile) | 199 BookmarkModel::BookmarkModel(Profile* profile) |
| 200 : profile_(profile), | 200 : profile_(profile), |
| 201 loaded_(false), | 201 loaded_(false), |
| 202 root_(GURL()), | 202 root_(GURL()), |
| 203 bookmark_bar_node_(NULL), | 203 bookmark_bar_node_(NULL), |
| 204 other_node_(NULL), | 204 other_node_(NULL), |
| 205 mobile_node_(NULL), | 205 mobile_node_(NULL), |
| 206 apps_node_(NULL), |
| 206 next_node_id_(1), | 207 next_node_id_(1), |
| 207 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), | 208 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), |
| 208 loaded_signal_(true, false), | 209 loaded_signal_(true, false), |
| 209 extensive_changes_(0) { | 210 extensive_changes_(0) { |
| 210 if (!profile_) { | 211 if (!profile_) { |
| 211 // Profile is null during testing. | 212 // Profile is null during testing. |
| 212 DoneLoading(CreateLoadDetails()); | 213 DoneLoading(CreateLoadDetails()); |
| 213 } | 214 } |
| 214 } | 215 } |
| 215 | 216 |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 switch (type) { | 654 switch (type) { |
| 654 case BookmarkNode::BOOKMARK_BAR: | 655 case BookmarkNode::BOOKMARK_BAR: |
| 655 bookmark_bar_node_->set_visible(value); | 656 bookmark_bar_node_->set_visible(value); |
| 656 break; | 657 break; |
| 657 case BookmarkNode::OTHER_NODE: | 658 case BookmarkNode::OTHER_NODE: |
| 658 other_node_->set_visible(value); | 659 other_node_->set_visible(value); |
| 659 break; | 660 break; |
| 660 case BookmarkNode::MOBILE: | 661 case BookmarkNode::MOBILE: |
| 661 mobile_node_->set_visible(value); | 662 mobile_node_->set_visible(value); |
| 662 break; | 663 break; |
| 664 case BookmarkNode::APPS_NODE: |
| 665 apps_node_->set_visible(value); |
| 666 break; |
| 663 default: | 667 default: |
| 664 NOTREACHED(); | 668 NOTREACHED(); |
| 665 } | 669 } |
| 666 } | 670 } |
| 667 | 671 |
| 668 bool BookmarkModel::IsBookmarkedNoLock(const GURL& url) { | 672 bool BookmarkModel::IsBookmarkedNoLock(const GURL& url) { |
| 669 BookmarkNode tmp_node(url); | 673 BookmarkNode tmp_node(url); |
| 670 return (nodes_ordered_by_url_set_.find(&tmp_node) != | 674 return (nodes_ordered_by_url_set_.find(&tmp_node) != |
| 671 nodes_ordered_by_url_set_.end()); | 675 nodes_ordered_by_url_set_.end()); |
| 672 } | 676 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 // them unique. So when the file has changed externally, we should save the | 721 // them unique. So when the file has changed externally, we should save the |
| 718 // bookmarks file to persist new IDs. | 722 // bookmarks file to persist new IDs. |
| 719 if (store_.get()) | 723 if (store_.get()) |
| 720 store_->ScheduleSave(); | 724 store_->ScheduleSave(); |
| 721 } | 725 } |
| 722 bookmark_bar_node_ = details->release_bb_node(); | 726 bookmark_bar_node_ = details->release_bb_node(); |
| 723 other_node_ = details->release_other_folder_node(); | 727 other_node_ = details->release_other_folder_node(); |
| 724 mobile_node_ = details->release_mobile_folder_node(); | 728 mobile_node_ = details->release_mobile_folder_node(); |
| 725 index_.reset(details->release_index()); | 729 index_.reset(details->release_index()); |
| 726 | 730 |
| 731 // The apps node does not hold any data, we create is from scratch every time. |
| 732 apps_node_ = CreatePermanentNode(BookmarkNode::APPS_NODE); |
| 733 |
| 727 // WARNING: order is important here, various places assume the order is | 734 // WARNING: order is important here, various places assume the order is |
| 728 // constant. | 735 // constant. |
| 729 root_.Add(bookmark_bar_node_, 0); | 736 root_.Add(bookmark_bar_node_, 0); |
| 730 root_.Add(other_node_, 1); | 737 root_.Add(other_node_, 1); |
| 731 root_.Add(mobile_node_, 2); | 738 root_.Add(mobile_node_, 2); |
| 739 root_.Add(apps_node_, 3); |
| 732 | 740 |
| 733 root_.set_meta_info_str(details->model_meta_info()); | 741 root_.set_meta_info_str(details->model_meta_info()); |
| 734 | 742 |
| 735 { | 743 { |
| 736 base::AutoLock url_lock(url_lock_); | 744 base::AutoLock url_lock(url_lock_); |
| 737 // Update nodes_ordered_by_url_set_ from the nodes. | 745 // Update nodes_ordered_by_url_set_ from the nodes. |
| 738 PopulateNodesByURL(&root_); | 746 PopulateNodesByURL(&root_); |
| 739 } | 747 } |
| 740 | 748 |
| 741 loaded_ = true; | 749 loaded_ = true; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 bool allow_end) { | 837 bool allow_end) { |
| 830 return (parent && parent->is_folder() && | 838 return (parent && parent->is_folder() && |
| 831 (index >= 0 && (index < parent->child_count() || | 839 (index >= 0 && (index < parent->child_count() || |
| 832 (allow_end && index == parent->child_count())))); | 840 (allow_end && index == parent->child_count())))); |
| 833 } | 841 } |
| 834 | 842 |
| 835 BookmarkPermanentNode* BookmarkModel::CreatePermanentNode( | 843 BookmarkPermanentNode* BookmarkModel::CreatePermanentNode( |
| 836 BookmarkNode::Type type) { | 844 BookmarkNode::Type type) { |
| 837 DCHECK(type == BookmarkNode::BOOKMARK_BAR || | 845 DCHECK(type == BookmarkNode::BOOKMARK_BAR || |
| 838 type == BookmarkNode::OTHER_NODE || | 846 type == BookmarkNode::OTHER_NODE || |
| 839 type == BookmarkNode::MOBILE); | 847 type == BookmarkNode::MOBILE || |
| 848 type == BookmarkNode::APPS_NODE); |
| 840 BookmarkPermanentNode* node = | 849 BookmarkPermanentNode* node = |
| 841 new BookmarkPermanentNode(generate_next_node_id()); | 850 new BookmarkPermanentNode(generate_next_node_id()); |
| 842 if (type == BookmarkNode::MOBILE) | 851 if (type == BookmarkNode::MOBILE) |
| 843 node->set_visible(false); // Mobile node is initially hidden. | 852 node->set_visible(false); // Mobile node is initially hidden. |
| 844 | 853 |
| 845 int title_id; | 854 int title_id; |
| 846 switch (type) { | 855 switch (type) { |
| 847 case BookmarkNode::BOOKMARK_BAR: | 856 case BookmarkNode::BOOKMARK_BAR: |
| 848 title_id = IDS_BOOKMARK_BAR_FOLDER_NAME; | 857 title_id = IDS_BOOKMARK_BAR_FOLDER_NAME; |
| 849 break; | 858 break; |
| 850 case BookmarkNode::OTHER_NODE: | 859 case BookmarkNode::OTHER_NODE: |
| 851 title_id = IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME; | 860 title_id = IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME; |
| 852 break; | 861 break; |
| 853 case BookmarkNode::MOBILE: | 862 case BookmarkNode::MOBILE: |
| 854 title_id = IDS_BOOKMARK_BAR_MOBILE_FOLDER_NAME; | 863 title_id = IDS_BOOKMARK_BAR_MOBILE_FOLDER_NAME; |
| 855 break; | 864 break; |
| 865 case BookmarkNode::APPS_NODE: |
| 866 title_id = IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME; |
| 867 break; |
| 856 default: | 868 default: |
| 857 NOTREACHED(); | 869 NOTREACHED(); |
| 858 title_id = IDS_BOOKMARK_BAR_FOLDER_NAME; | 870 title_id = IDS_BOOKMARK_BAR_FOLDER_NAME; |
| 859 break; | 871 break; |
| 860 } | 872 } |
| 861 node->SetTitle(l10n_util::GetStringUTF16(title_id)); | 873 node->SetTitle(l10n_util::GetStringUTF16(title_id)); |
| 862 node->set_type(type); | 874 node->set_type(type); |
| 863 return node; | 875 return node; |
| 864 } | 876 } |
| 865 | 877 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 BookmarkPermanentNode* bb_node = | 966 BookmarkPermanentNode* bb_node = |
| 955 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 967 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
| 956 BookmarkPermanentNode* other_node = | 968 BookmarkPermanentNode* other_node = |
| 957 CreatePermanentNode(BookmarkNode::OTHER_NODE); | 969 CreatePermanentNode(BookmarkNode::OTHER_NODE); |
| 958 BookmarkPermanentNode* mobile_node = | 970 BookmarkPermanentNode* mobile_node = |
| 959 CreatePermanentNode(BookmarkNode::MOBILE); | 971 CreatePermanentNode(BookmarkNode::MOBILE); |
| 960 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, | 972 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, |
| 961 new BookmarkIndex(profile_), | 973 new BookmarkIndex(profile_), |
| 962 next_node_id_); | 974 next_node_id_); |
| 963 } | 975 } |
| OLD | NEW |