Chromium Code Reviews| Index: chrome/browser/bookmarks/bookmark_model.cc |
| diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc |
| index b372855a4e25060f7ff65a2bdbb71d83609f642f..f37ce580c2be4f8523eb0bce07bf03face077f1e 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" |
| @@ -75,6 +77,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 +129,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) { |
| @@ -142,6 +148,12 @@ BookmarkModel::~BookmarkModel() { |
| // so that it doesn't try and invoke a method back on us again. |
| store_->BookmarkModelDeleted(); |
| } |
| + // If the switch wasn't set, then synced_node_ hasn't been added to the model |
| + // and we must delete it. |
| + if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableSyncedBookmarksFolder)) { |
| + delete synced_node_; |
| + } |
| } |
| void BookmarkModel::Load() { |
| @@ -259,7 +271,8 @@ void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { |
| if (node->GetTitle() == title) |
| return; |
| - if (node == bookmark_bar_node_ || node == other_node_) { |
| + if (node == bookmark_bar_node_ || node == other_node_ || |
| + node == synced_node_) { |
| NOTREACHED(); |
| return; |
| } |
| @@ -568,12 +581,20 @@ 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); |
| + // TODO(yfriedman): If this switch is removed, update the desctructor to avoid |
| + // double-delete of synced_node_; |
| + |
| + if (CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableSyncedBookmarksFolder)) { |
| + root_.Add(synced_node_, 2); |
|
sky
2011/05/12 16:29:13
How come we don't always add the node to the model
Yaron
2011/05/12 18:19:23
Because that caused it to show in the UI. Perhaps
|
| + } |
| { |
| base::AutoLock url_lock(url_lock_); |
| @@ -719,14 +740,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 +857,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_); |
| } |