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

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

Issue 8273041: Permanent folders changes (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Nit fixing. Created 9 years, 2 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
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model.h ('k') | chrome/browser/bookmarks/bookmark_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/callback.h" 10 #include "base/callback.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 BookmarkNode::BookmarkNode(int64 id, const GURL& url) 50 BookmarkNode::BookmarkNode(int64 id, const GURL& url)
51 : url_(url) { 51 : url_(url) {
52 Initialize(id); 52 Initialize(id);
53 } 53 }
54 54
55 BookmarkNode::~BookmarkNode() { 55 BookmarkNode::~BookmarkNode() {
56 } 56 }
57 57
58 bool BookmarkNode::IsVisible() const { 58 bool BookmarkNode::IsVisible() const {
59 // The synced bookmark folder is invisible if the flag isn't set and there are 59 return true;
60 // no bookmarks under it.
61 if (type_ != BookmarkNode::SYNCED ||
62 CommandLine::ForCurrentProcess()->HasSwitch(
63 switches::kEnableSyncedBookmarksFolder) || !empty()) {
64 return true;
65 }
66 return false;
67 } 60 }
68 61
69 void BookmarkNode::Initialize(int64 id) { 62 void BookmarkNode::Initialize(int64 id) {
70 id_ = id; 63 id_ = id;
71 type_ = url_.is_empty() ? FOLDER : URL; 64 type_ = url_.is_empty() ? FOLDER : URL;
72 date_added_ = Time::Now(); 65 date_added_ = Time::Now();
73 is_favicon_loaded_ = false; 66 is_favicon_loaded_ = false;
74 favicon_load_handle_ = 0; 67 favicon_load_handle_ = 0;
75 } 68 }
76 69
77 void BookmarkNode::InvalidateFavicon() { 70 void BookmarkNode::InvalidateFavicon() {
78 favicon_ = SkBitmap(); 71 favicon_ = SkBitmap();
79 is_favicon_loaded_ = false; 72 is_favicon_loaded_ = false;
80 } 73 }
81 74
75 // BookmarkPermanentNode ------------------------------------------------------
76
77 BookmarkPermanentNode::BookmarkPermanentNode(int64 id,
78 const GURL& url,
79 Profile* profile)
80 : BookmarkNode(id, url),
81 profile_(profile) {
82 }
83
84 BookmarkPermanentNode::~BookmarkPermanentNode() {
85 }
86
87 bool BookmarkPermanentNode::IsVisible() const {
88 // The synced bookmark folder is invisible if the flag isn't set and there are
89 // no bookmarks under it.
90 return type() != BookmarkNode::SYNCED ||
91 CommandLine::ForCurrentProcess()->HasSwitch(
92 switches::kEnableSyncedBookmarksFolder) ||
93 !empty();
94 }
95
82 // BookmarkModel -------------------------------------------------------------- 96 // BookmarkModel --------------------------------------------------------------
83 97
84 namespace { 98 namespace {
85 99
86 // Comparator used when sorting bookmarks. Folders are sorted first, then 100 // Comparator used when sorting bookmarks. Folders are sorted first, then
87 // bookmarks. 101 // bookmarks.
88 class SortComparator : public std::binary_function<const BookmarkNode*, 102 class SortComparator : public std::binary_function<const BookmarkNode*,
89 const BookmarkNode*, 103 const BookmarkNode*,
90 bool> { 104 bool> {
91 public: 105 public:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 store_->LoadBookmarks(CreateLoadDetails()); 179 store_->LoadBookmarks(CreateLoadDetails());
166 } 180 }
167 181
168 bool BookmarkModel::IsLoaded() const { 182 bool BookmarkModel::IsLoaded() const {
169 return loaded_; 183 return loaded_;
170 } 184 }
171 185
172 const BookmarkNode* BookmarkModel::GetParentForNewNodes() { 186 const BookmarkNode* BookmarkModel::GetParentForNewNodes() {
173 std::vector<const BookmarkNode*> nodes = 187 std::vector<const BookmarkNode*> nodes =
174 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1); 188 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1);
175 return nodes.empty() ? bookmark_bar_node_ : nodes[0]; 189 DCHECK(!nodes.empty()); // This list is always padded with default folders.
190 return nodes[0];
176 } 191 }
177 192
178 void BookmarkModel::AddObserver(BookmarkModelObserver* observer) { 193 void BookmarkModel::AddObserver(BookmarkModelObserver* observer) {
179 observers_.AddObserver(observer); 194 observers_.AddObserver(observer);
180 } 195 }
181 196
182 void BookmarkModel::RemoveObserver(BookmarkModelObserver* observer) { 197 void BookmarkModel::RemoveObserver(BookmarkModelObserver* observer) {
183 observers_.RemoveObserver(observer); 198 observers_.RemoveObserver(observer);
184 } 199 }
185 200
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 // them unique. So when the file has changed externally, we should save the 574 // them unique. So when the file has changed externally, we should save the
560 // bookmarks file to persist new IDs. 575 // bookmarks file to persist new IDs.
561 if (store_.get()) 576 if (store_.get())
562 store_->ScheduleSave(); 577 store_->ScheduleSave();
563 } 578 }
564 bookmark_bar_node_ = details->release_bb_node(); 579 bookmark_bar_node_ = details->release_bb_node();
565 other_node_ = details->release_other_folder_node(); 580 other_node_ = details->release_other_folder_node();
566 synced_node_ = details->release_synced_folder_node(); 581 synced_node_ = details->release_synced_folder_node();
567 index_.reset(details->release_index()); 582 index_.reset(details->release_index());
568 583
569 // WARNING: order is important here, various places assume bookmark bar then 584 // WARNING: order is important here, various places assume the order is
570 // other node. 585 // constant.
571 root_.Add(bookmark_bar_node_, 0); 586 root_.Add(bookmark_bar_node_, 0);
572 root_.Add(other_node_, 1); 587 root_.Add(other_node_, 1);
573 root_.Add(synced_node_, 2); 588 root_.Add(synced_node_, 2);
574 589
575 { 590 {
576 base::AutoLock url_lock(url_lock_); 591 base::AutoLock url_lock(url_lock_);
577 // Update nodes_ordered_by_url_set_ from the nodes. 592 // Update nodes_ordered_by_url_set_ from the nodes.
578 PopulateNodesByURL(&root_); 593 PopulateNodesByURL(&root_);
579 } 594 }
580 595
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 bool allow_end) { 703 bool allow_end) {
689 return (parent && parent->is_folder() && 704 return (parent && parent->is_folder() &&
690 (index >= 0 && (index < parent->child_count() || 705 (index >= 0 && (index < parent->child_count() ||
691 (allow_end && index == parent->child_count())))); 706 (allow_end && index == parent->child_count()))));
692 } 707 }
693 708
694 BookmarkNode* BookmarkModel::CreatePermanentNode(BookmarkNode::Type type) { 709 BookmarkNode* BookmarkModel::CreatePermanentNode(BookmarkNode::Type type) {
695 DCHECK(type == BookmarkNode::BOOKMARK_BAR || 710 DCHECK(type == BookmarkNode::BOOKMARK_BAR ||
696 type == BookmarkNode::OTHER_NODE || 711 type == BookmarkNode::OTHER_NODE ||
697 type == BookmarkNode::SYNCED); 712 type == BookmarkNode::SYNCED);
698 BookmarkNode* node = new BookmarkNode(generate_next_node_id(), GURL()); 713 BookmarkPermanentNode* node = new BookmarkPermanentNode(
714 generate_next_node_id(), GURL(), profile_);
699 node->set_type(type); 715 node->set_type(type);
700 if (type == BookmarkNode::BOOKMARK_BAR) { 716 if (type == BookmarkNode::BOOKMARK_BAR) {
701 node->set_title(l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_FOLDER_NAME)); 717 node->set_title(l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_FOLDER_NAME));
702 } else if (type == BookmarkNode::OTHER_NODE) { 718 } else if (type == BookmarkNode::OTHER_NODE) {
703 node->set_title( 719 node->set_title(
704 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME)); 720 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME));
705 } else { 721 } else {
706 node->set_title( 722 node->set_title(
707 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_SYNCED_FOLDER_NAME)); 723 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_SYNCED_FOLDER_NAME));
708 } 724 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 file_changed_ = true; 819 file_changed_ = true;
804 } 820 }
805 821
806 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { 822 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() {
807 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); 823 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR);
808 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); 824 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE);
809 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); 825 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED);
810 return new BookmarkLoadDetails(bb_node, other_node, synced_node, 826 return new BookmarkLoadDetails(bb_node, other_node, synced_node,
811 new BookmarkIndex(profile_), next_node_id_); 827 new BookmarkIndex(profile_), next_node_id_);
812 } 828 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model.h ('k') | chrome/browser/bookmarks/bookmark_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698