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

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: "Post-review changes." 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 if (type() != BookmarkNode::SYNCED ||
sky 2011/10/18 01:55:45 nit: turn this into the return statement.
91 CommandLine::ForCurrentProcess()->HasSwitch(
92 switches::kEnableSyncedBookmarksFolder) || !empty()) {
93 return true;
94 }
95 return false;
96 }
97
82 // BookmarkModel -------------------------------------------------------------- 98 // BookmarkModel --------------------------------------------------------------
83 99
84 namespace { 100 namespace {
85 101
86 // Comparator used when sorting bookmarks. Folders are sorted first, then 102 // Comparator used when sorting bookmarks. Folders are sorted first, then
87 // bookmarks. 103 // bookmarks.
88 class SortComparator : public std::binary_function<const BookmarkNode*, 104 class SortComparator : public std::binary_function<const BookmarkNode*,
89 const BookmarkNode*, 105 const BookmarkNode*,
90 bool> { 106 bool> {
91 public: 107 public:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 store_->LoadBookmarks(CreateLoadDetails()); 181 store_->LoadBookmarks(CreateLoadDetails());
166 } 182 }
167 183
168 bool BookmarkModel::IsLoaded() const { 184 bool BookmarkModel::IsLoaded() const {
169 return loaded_; 185 return loaded_;
170 } 186 }
171 187
172 const BookmarkNode* BookmarkModel::GetParentForNewNodes() { 188 const BookmarkNode* BookmarkModel::GetParentForNewNodes() {
173 std::vector<const BookmarkNode*> nodes = 189 std::vector<const BookmarkNode*> nodes =
174 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1); 190 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1);
175 return nodes.empty() ? bookmark_bar_node_ : nodes[0]; 191 DCHECK(!nodes.empty()); // This list is always padded with default folders.
192 return nodes[0];
176 } 193 }
177 194
178 void BookmarkModel::AddObserver(BookmarkModelObserver* observer) { 195 void BookmarkModel::AddObserver(BookmarkModelObserver* observer) {
179 observers_.AddObserver(observer); 196 observers_.AddObserver(observer);
180 } 197 }
181 198
182 void BookmarkModel::RemoveObserver(BookmarkModelObserver* observer) { 199 void BookmarkModel::RemoveObserver(BookmarkModelObserver* observer) {
183 observers_.RemoveObserver(observer); 200 observers_.RemoveObserver(observer);
184 } 201 }
185 202
(...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 576 // them unique. So when the file has changed externally, we should save the
560 // bookmarks file to persist new IDs. 577 // bookmarks file to persist new IDs.
561 if (store_.get()) 578 if (store_.get())
562 store_->ScheduleSave(); 579 store_->ScheduleSave();
563 } 580 }
564 bookmark_bar_node_ = details->release_bb_node(); 581 bookmark_bar_node_ = details->release_bb_node();
565 other_node_ = details->release_other_folder_node(); 582 other_node_ = details->release_other_folder_node();
566 synced_node_ = details->release_synced_folder_node(); 583 synced_node_ = details->release_synced_folder_node();
567 index_.reset(details->release_index()); 584 index_.reset(details->release_index());
568 585
569 // WARNING: order is important here, various places assume bookmark bar then 586 // WARNING: order is important here, various places assume the order is
570 // other node. 587 // constant.
571 root_.Add(bookmark_bar_node_, 0); 588 root_.Add(bookmark_bar_node_, 0);
572 root_.Add(other_node_, 1); 589 root_.Add(other_node_, 1);
573 root_.Add(synced_node_, 2); 590 root_.Add(synced_node_, 2);
574 591
575 { 592 {
576 base::AutoLock url_lock(url_lock_); 593 base::AutoLock url_lock(url_lock_);
577 // Update nodes_ordered_by_url_set_ from the nodes. 594 // Update nodes_ordered_by_url_set_ from the nodes.
578 PopulateNodesByURL(&root_); 595 PopulateNodesByURL(&root_);
579 } 596 }
580 597
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 bool allow_end) { 705 bool allow_end) {
689 return (parent && parent->is_folder() && 706 return (parent && parent->is_folder() &&
690 (index >= 0 && (index < parent->child_count() || 707 (index >= 0 && (index < parent->child_count() ||
691 (allow_end && index == parent->child_count())))); 708 (allow_end && index == parent->child_count()))));
692 } 709 }
693 710
694 BookmarkNode* BookmarkModel::CreatePermanentNode(BookmarkNode::Type type) { 711 BookmarkNode* BookmarkModel::CreatePermanentNode(BookmarkNode::Type type) {
695 DCHECK(type == BookmarkNode::BOOKMARK_BAR || 712 DCHECK(type == BookmarkNode::BOOKMARK_BAR ||
696 type == BookmarkNode::OTHER_NODE || 713 type == BookmarkNode::OTHER_NODE ||
697 type == BookmarkNode::SYNCED); 714 type == BookmarkNode::SYNCED);
698 BookmarkNode* node = new BookmarkNode(generate_next_node_id(), GURL()); 715 BookmarkPermanentNode* node = new BookmarkPermanentNode(
716 generate_next_node_id(), GURL(), profile_);
699 node->set_type(type); 717 node->set_type(type);
700 if (type == BookmarkNode::BOOKMARK_BAR) { 718 if (type == BookmarkNode::BOOKMARK_BAR) {
701 node->set_title(l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_FOLDER_NAME)); 719 node->set_title(l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_FOLDER_NAME));
702 } else if (type == BookmarkNode::OTHER_NODE) { 720 } else if (type == BookmarkNode::OTHER_NODE) {
703 node->set_title( 721 node->set_title(
704 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME)); 722 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_OTHER_FOLDER_NAME));
705 } else { 723 } else {
706 node->set_title( 724 node->set_title(
707 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_SYNCED_FOLDER_NAME)); 725 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_SYNCED_FOLDER_NAME));
708 } 726 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 file_changed_ = true; 821 file_changed_ = true;
804 } 822 }
805 823
806 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { 824 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() {
807 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); 825 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR);
808 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); 826 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE);
809 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); 827 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED);
810 return new BookmarkLoadDetails(bb_node, other_node, synced_node, 828 return new BookmarkLoadDetails(bb_node, other_node, synced_node,
811 new BookmarkIndex(profile_), next_node_id_); 829 new BookmarkIndex(profile_), next_node_id_);
812 } 830 }
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