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

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

Issue 6931018: Initial implementation of "Synced Bookmarks" folder. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Merge Created 9 years, 7 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) 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"
11 #include "base/command_line.h"
11 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "chrome/browser/bookmarks/bookmark_index.h" 14 #include "chrome/browser/bookmarks/bookmark_index.h"
14 #include "chrome/browser/bookmarks/bookmark_storage.h" 15 #include "chrome/browser/bookmarks/bookmark_storage.h"
15 #include "chrome/browser/bookmarks/bookmark_utils.h" 16 #include "chrome/browser/bookmarks/bookmark_utils.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/history/history_notifications.h" 18 #include "chrome/browser/history/history_notifications.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_switches.h"
19 #include "content/common/notification_service.h" 21 #include "content/common/notification_service.h"
20 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
21 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/l10n/l10n_util_collator.h" 24 #include "ui/base/l10n/l10n_util_collator.h"
23 #include "ui/gfx/codec/png_codec.h" 25 #include "ui/gfx/codec/png_codec.h"
24 26
25 using base::Time; 27 using base::Time;
26 28
27 namespace { 29 namespace {
28 30
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 switch (entry.type) { 70 switch (entry.type) {
69 case history::StarredEntry::URL: 71 case history::StarredEntry::URL:
70 type_ = BookmarkNode::URL; 72 type_ = BookmarkNode::URL;
71 break; 73 break;
72 case history::StarredEntry::USER_FOLDER: 74 case history::StarredEntry::USER_FOLDER:
73 type_ = BookmarkNode::FOLDER; 75 type_ = BookmarkNode::FOLDER;
74 break; 76 break;
75 case history::StarredEntry::BOOKMARK_BAR: 77 case history::StarredEntry::BOOKMARK_BAR:
76 type_ = BookmarkNode::BOOKMARK_BAR; 78 type_ = BookmarkNode::BOOKMARK_BAR;
77 break; 79 break;
80 case history::StarredEntry::SYNCED:
81 type_ = BookmarkNode::SYNCED;
82 break;
78 case history::StarredEntry::OTHER: 83 case history::StarredEntry::OTHER:
79 type_ = BookmarkNode::OTHER_NODE; 84 type_ = BookmarkNode::OTHER_NODE;
80 break; 85 break;
81 default: 86 default:
82 NOTREACHED(); 87 NOTREACHED();
83 } 88 }
84 date_added_ = entry.date_added; 89 date_added_ = entry.date_added;
85 date_folder_modified_ = entry.date_folder_modified; 90 date_folder_modified_ = entry.date_folder_modified;
86 set_title(entry.title); 91 set_title(entry.title);
87 } 92 }
(...skipping 29 matching lines...) Expand all
117 122
118 } // namespace 123 } // namespace
119 124
120 BookmarkModel::BookmarkModel(Profile* profile) 125 BookmarkModel::BookmarkModel(Profile* profile)
121 : profile_(profile), 126 : profile_(profile),
122 loaded_(false), 127 loaded_(false),
123 file_changed_(false), 128 file_changed_(false),
124 root_(GURL()), 129 root_(GURL()),
125 bookmark_bar_node_(NULL), 130 bookmark_bar_node_(NULL),
126 other_node_(NULL), 131 other_node_(NULL),
132 synced_node_(NULL),
127 next_node_id_(1), 133 next_node_id_(1),
128 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), 134 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY),
129 loaded_signal_(TRUE, FALSE) { 135 loaded_signal_(TRUE, FALSE) {
130 if (!profile_) { 136 if (!profile_) {
131 // Profile is null during testing. 137 // Profile is null during testing.
132 DoneLoading(CreateLoadDetails()); 138 DoneLoading(CreateLoadDetails());
133 } 139 }
134 } 140 }
135 141
136 BookmarkModel::~BookmarkModel() { 142 BookmarkModel::~BookmarkModel() {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 258 }
253 259
254 void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { 260 void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) {
255 if (!node) { 261 if (!node) {
256 NOTREACHED(); 262 NOTREACHED();
257 return; 263 return;
258 } 264 }
259 if (node->GetTitle() == title) 265 if (node->GetTitle() == title)
260 return; 266 return;
261 267
262 if (node == bookmark_bar_node_ || node == other_node_) { 268 if (node == bookmark_bar_node_ || node == other_node_ ||
269 node == synced_node_) {
263 NOTREACHED(); 270 NOTREACHED();
264 return; 271 return;
265 } 272 }
266 273
267 // The title index doesn't support changing the title, instead we remove then 274 // The title index doesn't support changing the title, instead we remove then
268 // add it back. 275 // add it back.
269 index_->Remove(node); 276 index_->Remove(node);
270 AsMutable(node)->set_title(title); 277 AsMutable(node)->set_title(title);
271 index_->Add(node); 278 index_->Add(node);
272 279
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 details->ids_reassigned()) { 568 details->ids_reassigned()) {
562 // If bookmarks file changed externally, the IDs may have changed 569 // If bookmarks file changed externally, the IDs may have changed
563 // externally. In that case, the decoder may have reassigned IDs to make 570 // externally. In that case, the decoder may have reassigned IDs to make
564 // them unique. So when the file has changed externally, we should save the 571 // them unique. So when the file has changed externally, we should save the
565 // bookmarks file to persist new IDs. 572 // bookmarks file to persist new IDs.
566 if (store_.get()) 573 if (store_.get())
567 store_->ScheduleSave(); 574 store_->ScheduleSave();
568 } 575 }
569 bookmark_bar_node_ = details->release_bb_node(); 576 bookmark_bar_node_ = details->release_bb_node();
570 other_node_ = details->release_other_folder_node(); 577 other_node_ = details->release_other_folder_node();
578 synced_node_ = details->release_synced_folder_node();
571 index_.reset(details->release_index()); 579 index_.reset(details->release_index());
572 580
573 // WARNING: order is important here, various places assume bookmark bar then 581 // WARNING: order is important here, various places assume bookmark bar then
574 // other node. 582 // other node.
575 root_.Add(bookmark_bar_node_, 0); 583 root_.Add(bookmark_bar_node_, 0);
576 root_.Add(other_node_, 1); 584 root_.Add(other_node_, 1);
585 if (CommandLine::ForCurrentProcess()->HasSwitch(
586 switches::kEnableSyncedBookmarksFolder)) {
587 root_.Add(synced_node_, 2);
588 }
577 589
578 { 590 {
579 base::AutoLock url_lock(url_lock_); 591 base::AutoLock url_lock(url_lock_);
580 // Update nodes_ordered_by_url_set_ from the nodes. 592 // Update nodes_ordered_by_url_set_ from the nodes.
581 PopulateNodesByURL(&root_); 593 PopulateNodesByURL(&root_);
582 } 594 }
583 595
584 loaded_ = true; 596 loaded_ = true;
585 597
586 loaded_signal_.Signal(); 598 loaded_signal_.Signal();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 entry.type = history::StarredEntry::BOOKMARK_BAR; 724 entry.type = history::StarredEntry::BOOKMARK_BAR;
713 return CreateRootNodeFromStarredEntry(entry); 725 return CreateRootNodeFromStarredEntry(entry);
714 } 726 }
715 727
716 BookmarkNode* BookmarkModel::CreateOtherBookmarksNode() { 728 BookmarkNode* BookmarkModel::CreateOtherBookmarksNode() {
717 history::StarredEntry entry; 729 history::StarredEntry entry;
718 entry.type = history::StarredEntry::OTHER; 730 entry.type = history::StarredEntry::OTHER;
719 return CreateRootNodeFromStarredEntry(entry); 731 return CreateRootNodeFromStarredEntry(entry);
720 } 732 }
721 733
734 BookmarkNode* BookmarkModel::CreateSyncedBookmarksNode() {
735 history::StarredEntry entry;
736 entry.type = history::StarredEntry::SYNCED;
737 return CreateRootNodeFromStarredEntry(entry);
738 }
739
722 BookmarkNode* BookmarkModel::CreateRootNodeFromStarredEntry( 740 BookmarkNode* BookmarkModel::CreateRootNodeFromStarredEntry(
723 const history::StarredEntry& entry) { 741 const history::StarredEntry& entry) {
724 DCHECK(entry.type == history::StarredEntry::BOOKMARK_BAR || 742 DCHECK(entry.type == history::StarredEntry::BOOKMARK_BAR ||
725 entry.type == history::StarredEntry::OTHER); 743 entry.type == history::StarredEntry::OTHER ||
744 entry.type == history::StarredEntry::SYNCED);
726 BookmarkNode* node = new BookmarkNode(generate_next_node_id(), GURL()); 745 BookmarkNode* node = new BookmarkNode(generate_next_node_id(), GURL());
727 node->Reset(entry); 746 node->Reset(entry);
728 if (entry.type == history::StarredEntry::BOOKMARK_BAR) { 747 if (entry.type == history::StarredEntry::BOOKMARK_BAR) {
729 node->set_title(l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_FOLDER_NAME)); 748 node->set_title(l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_FOLDER_NAME));
749 } else if (entry.type == history::StarredEntry::SYNCED) {
750 node->set_title(l10n_util::GetStringUTF16(
751 IDS_BOOMARK_BAR_SYNCED_FOLDER_NAME));
730 } else { 752 } else {
731 node->set_title( 753 node->set_title(
732 l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME)); 754 l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME));
733 } 755 }
734 return node; 756 return node;
735 } 757 }
736 758
737 void BookmarkModel::OnFaviconDataAvailable( 759 void BookmarkModel::OnFaviconDataAvailable(
738 FaviconService::Handle handle, 760 FaviconService::Handle handle,
739 history::FaviconData favicon) { 761 history::FaviconData favicon) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 return next_node_id_++; 841 return next_node_id_++;
820 } 842 }
821 843
822 void BookmarkModel::SetFileChanged() { 844 void BookmarkModel::SetFileChanged() {
823 file_changed_ = true; 845 file_changed_ = true;
824 } 846 }
825 847
826 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { 848 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() {
827 BookmarkNode* bb_node = CreateBookmarkNode(); 849 BookmarkNode* bb_node = CreateBookmarkNode();
828 BookmarkNode* other_folder_node = CreateOtherBookmarksNode(); 850 BookmarkNode* other_folder_node = CreateOtherBookmarksNode();
851 BookmarkNode* synced_folder_node = CreateSyncedBookmarksNode();
829 return new BookmarkLoadDetails( 852 return new BookmarkLoadDetails(
830 bb_node, other_folder_node, new BookmarkIndex(profile()), next_node_id_); 853 bb_node, other_folder_node, synced_folder_node,
854 new BookmarkIndex(profile()), next_node_id_);
831 } 855 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model.h ('k') | chrome/browser/bookmarks/bookmark_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698