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

Side by Side Diff: chrome/browser/bookmarks/bookmark_model.cc

Issue 12550006: Mac: Add a shortcut to open the Apps page from the bookmark bar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed failing sync-related tests. Created 7 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/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
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
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 index_.reset(details->release_index()); 729 index_.reset(details->release_index());
726 730
727 // WARNING: order is important here, various places assume the order is 731 // WARNING: order is important here, various places assume the order is
728 // constant. 732 // constant.
729 root_.Add(bookmark_bar_node_, 0); 733 root_.Add(bookmark_bar_node_, 0);
730 root_.Add(other_node_, 1); 734 root_.Add(other_node_, 1);
731 root_.Add(mobile_node_, 2); 735 root_.Add(mobile_node_, 2);
732 736
733 root_.set_meta_info_str(details->model_meta_info()); 737 root_.set_meta_info_str(details->model_meta_info());
734 738
739 // The apps node does not hold any bookmarks, so it is not obtained from
740 // |details|. We need it because it is used to render the "Apps" menu item,
741 // but we are careful not to add it to |root_| otherwise it causes problems
742 // with sync.
743 apps_node_.reset(CreatePermanentNode(BookmarkNode::APPS_NODE));
744
735 { 745 {
736 base::AutoLock url_lock(url_lock_); 746 base::AutoLock url_lock(url_lock_);
737 // Update nodes_ordered_by_url_set_ from the nodes. 747 // Update nodes_ordered_by_url_set_ from the nodes.
738 PopulateNodesByURL(&root_); 748 PopulateNodesByURL(&root_);
739 } 749 }
740 750
741 loaded_ = true; 751 loaded_ = true;
742 752
743 loaded_signal_.Signal(); 753 loaded_signal_.Signal();
744 754
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 bool allow_end) { 839 bool allow_end) {
830 return (parent && parent->is_folder() && 840 return (parent && parent->is_folder() &&
831 (index >= 0 && (index < parent->child_count() || 841 (index >= 0 && (index < parent->child_count() ||
832 (allow_end && index == parent->child_count())))); 842 (allow_end && index == parent->child_count()))));
833 } 843 }
834 844
835 BookmarkPermanentNode* BookmarkModel::CreatePermanentNode( 845 BookmarkPermanentNode* BookmarkModel::CreatePermanentNode(
836 BookmarkNode::Type type) { 846 BookmarkNode::Type type) {
837 DCHECK(type == BookmarkNode::BOOKMARK_BAR || 847 DCHECK(type == BookmarkNode::BOOKMARK_BAR ||
838 type == BookmarkNode::OTHER_NODE || 848 type == BookmarkNode::OTHER_NODE ||
839 type == BookmarkNode::MOBILE); 849 type == BookmarkNode::MOBILE ||
850 type == BookmarkNode::APPS_NODE);
840 BookmarkPermanentNode* node = 851 BookmarkPermanentNode* node =
841 new BookmarkPermanentNode(generate_next_node_id()); 852 new BookmarkPermanentNode(generate_next_node_id());
842 if (type == BookmarkNode::MOBILE) 853 if (type == BookmarkNode::MOBILE)
843 node->set_visible(false); // Mobile node is initially hidden. 854 node->set_visible(false); // Mobile node is initially hidden.
844 855
845 int title_id; 856 int title_id;
846 switch (type) { 857 switch (type) {
847 case BookmarkNode::BOOKMARK_BAR: 858 case BookmarkNode::BOOKMARK_BAR:
848 title_id = IDS_BOOKMARK_BAR_FOLDER_NAME; 859 title_id = IDS_BOOKMARK_BAR_FOLDER_NAME;
849 break; 860 break;
850 case BookmarkNode::OTHER_NODE: 861 case BookmarkNode::OTHER_NODE:
851 title_id = IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME; 862 title_id = IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME;
852 break; 863 break;
853 case BookmarkNode::MOBILE: 864 case BookmarkNode::MOBILE:
854 title_id = IDS_BOOKMARK_BAR_MOBILE_FOLDER_NAME; 865 title_id = IDS_BOOKMARK_BAR_MOBILE_FOLDER_NAME;
855 break; 866 break;
867 case BookmarkNode::APPS_NODE:
868 title_id = IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME;
869 break;
856 default: 870 default:
857 NOTREACHED(); 871 NOTREACHED();
858 title_id = IDS_BOOKMARK_BAR_FOLDER_NAME; 872 title_id = IDS_BOOKMARK_BAR_FOLDER_NAME;
859 break; 873 break;
860 } 874 }
861 node->SetTitle(l10n_util::GetStringUTF16(title_id)); 875 node->SetTitle(l10n_util::GetStringUTF16(title_id));
862 node->set_type(type); 876 node->set_type(type);
863 return node; 877 return node;
864 } 878 }
865 879
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 BookmarkPermanentNode* bb_node = 968 BookmarkPermanentNode* bb_node =
955 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); 969 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR);
956 BookmarkPermanentNode* other_node = 970 BookmarkPermanentNode* other_node =
957 CreatePermanentNode(BookmarkNode::OTHER_NODE); 971 CreatePermanentNode(BookmarkNode::OTHER_NODE);
958 BookmarkPermanentNode* mobile_node = 972 BookmarkPermanentNode* mobile_node =
959 CreatePermanentNode(BookmarkNode::MOBILE); 973 CreatePermanentNode(BookmarkNode::MOBILE);
960 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, 974 return new BookmarkLoadDetails(bb_node, other_node, mobile_node,
961 new BookmarkIndex(profile_), 975 new BookmarkIndex(profile_),
962 next_node_id_); 976 next_node_id_);
963 } 977 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698