diff options
author | yfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 22:07:17 +0000 |
---|---|---|
committer | yfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-26 22:07:17 +0000 |
commit | 6892e2e416250521ed0778206da0093388b99300 (patch) | |
tree | 84d80407cbfa15cec3214d6d2822e74143a79ce6 /chrome/browser/bookmarks/bookmark_model.cc | |
parent | 46fe10d6c3cc0433626007f93c2b7784a2889ada (diff) | |
download | chromium_src-6892e2e416250521ed0778206da0093388b99300.zip chromium_src-6892e2e416250521ed0778206da0093388b99300.tar.gz chromium_src-6892e2e416250521ed0778206da0093388b99300.tar.bz2 |
Revert "Revert 84829 - Initial implementation of "Synced Bookmarks" folder."
Second attempt to land this change. Fixes memory leak (82186),
deleted bookmarks (82273) and crash on add bookmarks in windows (82349).
Original desscription:
Mostly ensures that sycned bookmarks are correctly treated as an immutable
folder. Some of the UI-bits maybe incomplete. For example, if
enable-synced-bookmarks-folder is set, then synced bookmarks will appear in the
bookmark manager page and some components of the UI but it's not on the bookmark
bar or anything like that. This change also ensures that the synced bookmark
folder matches a sync folder if one is available.
BUG=
TEST=test bookmark addition/moving around in combination with sync
Review URL: http://codereview.chromium.org/7012005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86902 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks/bookmark_model.cc')
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.cc | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index a48ecdf..7f74bc9 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -8,6 +8,7 @@ #include <functional> #include "base/callback.h" +#include "base/command_line.h" #include "base/memory/scoped_vector.h" #include "build/build_config.h" #include "chrome/browser/bookmarks/bookmark_index.h" @@ -16,6 +17,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/history/history_notifications.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/common/chrome_switches.h" #include "content/common/notification_service.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" @@ -61,6 +63,18 @@ void BookmarkNode::InvalidateFavicon() { favicon_ = SkBitmap(); } +bool BookmarkNode::IsVisible() const { + // The synced bookmark folder is invisible if the flag isn't set and there are + // no bookmarks under it. + if (type_ != BookmarkNode::SYNCED || + CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableSyncedBookmarksFolder) || + child_count() > 0) { + return true; + } + return false; +} + void BookmarkNode::Reset(const history::StarredEntry& entry) { DCHECK(entry.type != history::StarredEntry::URL || entry.url == url_); @@ -75,6 +89,9 @@ void BookmarkNode::Reset(const history::StarredEntry& entry) { case history::StarredEntry::BOOKMARK_BAR: type_ = BookmarkNode::BOOKMARK_BAR; break; + case history::StarredEntry::SYNCED: + type_ = BookmarkNode::SYNCED; + break; case history::StarredEntry::OTHER: type_ = BookmarkNode::OTHER_NODE; break; @@ -124,6 +141,7 @@ BookmarkModel::BookmarkModel(Profile* profile) root_(GURL()), bookmark_bar_node_(NULL), other_node_(NULL), + synced_node_(NULL), next_node_id_(1), observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), loaded_signal_(TRUE, FALSE) { @@ -259,7 +277,7 @@ void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { if (node->GetTitle() == title) return; - if (node == bookmark_bar_node_ || node == other_node_) { + if (is_permanent_node(node)) { NOTREACHED(); return; } @@ -568,12 +586,14 @@ void BookmarkModel::DoneLoading( } bookmark_bar_node_ = details->release_bb_node(); other_node_ = details->release_other_folder_node(); + synced_node_ = details->release_synced_folder_node(); index_.reset(details->release_index()); // WARNING: order is important here, various places assume bookmark bar then // other node. root_.Add(bookmark_bar_node_, 0); root_.Add(other_node_, 1); + root_.Add(synced_node_, 2); { base::AutoLock url_lock(url_lock_); @@ -719,14 +739,24 @@ BookmarkNode* BookmarkModel::CreateOtherBookmarksNode() { return CreateRootNodeFromStarredEntry(entry); } +BookmarkNode* BookmarkModel::CreateSyncedBookmarksNode() { + history::StarredEntry entry; + entry.type = history::StarredEntry::SYNCED; + return CreateRootNodeFromStarredEntry(entry); +} + BookmarkNode* BookmarkModel::CreateRootNodeFromStarredEntry( const history::StarredEntry& entry) { DCHECK(entry.type == history::StarredEntry::BOOKMARK_BAR || - entry.type == history::StarredEntry::OTHER); + entry.type == history::StarredEntry::OTHER || + entry.type == history::StarredEntry::SYNCED); BookmarkNode* node = new BookmarkNode(generate_next_node_id(), GURL()); node->Reset(entry); if (entry.type == history::StarredEntry::BOOKMARK_BAR) { node->set_title(l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_FOLDER_NAME)); + } else if (entry.type == history::StarredEntry::SYNCED) { + node->set_title(l10n_util::GetStringUTF16( + IDS_BOOMARK_BAR_SYNCED_FOLDER_NAME)); } else { node->set_title( l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME)); @@ -826,6 +856,8 @@ void BookmarkModel::SetFileChanged() { BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { BookmarkNode* bb_node = CreateBookmarkNode(); BookmarkNode* other_folder_node = CreateOtherBookmarksNode(); + BookmarkNode* synced_folder_node = CreateSyncedBookmarksNode(); return new BookmarkLoadDetails( - bb_node, other_folder_node, new BookmarkIndex(profile()), next_node_id_); + bb_node, other_folder_node, synced_folder_node, + new BookmarkIndex(profile()), next_node_id_); } |