Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 25 matching lines...) Expand all Loading... | |
| 54 favicon_load_handle_ = 0; | 56 favicon_load_handle_ = 0; |
| 55 type_ = !url_.is_empty() ? URL : BOOKMARK_BAR; | 57 type_ = !url_.is_empty() ? URL : BOOKMARK_BAR; |
| 56 date_added_ = Time::Now(); | 58 date_added_ = Time::Now(); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void BookmarkNode::InvalidateFavicon() { | 61 void BookmarkNode::InvalidateFavicon() { |
| 60 loaded_favicon_ = false; | 62 loaded_favicon_ = false; |
| 61 favicon_ = SkBitmap(); | 63 favicon_ = SkBitmap(); |
| 62 } | 64 } |
| 63 | 65 |
| 66 bool BookmarkNode::IsVisible() const { | |
|
sky
2011/05/17 15:59:08
Don't we want it visible if not empty too?
Yaron
2011/05/17 19:17:33
I discussed this with Srikanth and the plan is to
sky
2011/05/17 20:00:05
If we do that, couldn't that lead to weird states?
Yaron
2011/05/17 21:38:37
I think we'd be ok with some inconsistency with to
Yaron
2011/05/17 21:40:13
Err, it's in bookmark_editor_gtk.cc
| |
| 67 if (type_ != BookmarkNode::SYNCED || | |
| 68 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 69 switches::kEnableSyncedBookmarksFolder)) { | |
| 70 return true; | |
| 71 } | |
| 72 return false; | |
| 73 } | |
| 74 | |
| 64 void BookmarkNode::Reset(const history::StarredEntry& entry) { | 75 void BookmarkNode::Reset(const history::StarredEntry& entry) { |
| 65 DCHECK(entry.type != history::StarredEntry::URL || entry.url == url_); | 76 DCHECK(entry.type != history::StarredEntry::URL || entry.url == url_); |
| 66 | 77 |
| 67 favicon_ = SkBitmap(); | 78 favicon_ = SkBitmap(); |
| 68 switch (entry.type) { | 79 switch (entry.type) { |
| 69 case history::StarredEntry::URL: | 80 case history::StarredEntry::URL: |
| 70 type_ = BookmarkNode::URL; | 81 type_ = BookmarkNode::URL; |
| 71 break; | 82 break; |
| 72 case history::StarredEntry::USER_FOLDER: | 83 case history::StarredEntry::USER_FOLDER: |
| 73 type_ = BookmarkNode::FOLDER; | 84 type_ = BookmarkNode::FOLDER; |
| 74 break; | 85 break; |
| 75 case history::StarredEntry::BOOKMARK_BAR: | 86 case history::StarredEntry::BOOKMARK_BAR: |
| 76 type_ = BookmarkNode::BOOKMARK_BAR; | 87 type_ = BookmarkNode::BOOKMARK_BAR; |
| 77 break; | 88 break; |
| 89 case history::StarredEntry::SYNCED: | |
| 90 type_ = BookmarkNode::SYNCED; | |
| 91 break; | |
| 78 case history::StarredEntry::OTHER: | 92 case history::StarredEntry::OTHER: |
| 79 type_ = BookmarkNode::OTHER_NODE; | 93 type_ = BookmarkNode::OTHER_NODE; |
| 80 break; | 94 break; |
| 81 default: | 95 default: |
| 82 NOTREACHED(); | 96 NOTREACHED(); |
| 83 } | 97 } |
| 84 date_added_ = entry.date_added; | 98 date_added_ = entry.date_added; |
| 85 date_folder_modified_ = entry.date_folder_modified; | 99 date_folder_modified_ = entry.date_folder_modified; |
| 86 set_title(entry.title); | 100 set_title(entry.title); |
| 87 } | 101 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 117 | 131 |
| 118 } // namespace | 132 } // namespace |
| 119 | 133 |
| 120 BookmarkModel::BookmarkModel(Profile* profile) | 134 BookmarkModel::BookmarkModel(Profile* profile) |
| 121 : profile_(profile), | 135 : profile_(profile), |
| 122 loaded_(false), | 136 loaded_(false), |
| 123 file_changed_(false), | 137 file_changed_(false), |
| 124 root_(GURL()), | 138 root_(GURL()), |
| 125 bookmark_bar_node_(NULL), | 139 bookmark_bar_node_(NULL), |
| 126 other_node_(NULL), | 140 other_node_(NULL), |
| 141 synced_node_(NULL), | |
| 127 next_node_id_(1), | 142 next_node_id_(1), |
| 128 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), | 143 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), |
| 129 loaded_signal_(TRUE, FALSE) { | 144 loaded_signal_(TRUE, FALSE) { |
| 130 if (!profile_) { | 145 if (!profile_) { |
| 131 // Profile is null during testing. | 146 // Profile is null during testing. |
| 132 DoneLoading(CreateLoadDetails()); | 147 DoneLoading(CreateLoadDetails()); |
| 133 } | 148 } |
| 134 } | 149 } |
| 135 | 150 |
| 136 BookmarkModel::~BookmarkModel() { | 151 BookmarkModel::~BookmarkModel() { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 } | 267 } |
| 253 | 268 |
| 254 void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { | 269 void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { |
| 255 if (!node) { | 270 if (!node) { |
| 256 NOTREACHED(); | 271 NOTREACHED(); |
| 257 return; | 272 return; |
| 258 } | 273 } |
| 259 if (node->GetTitle() == title) | 274 if (node->GetTitle() == title) |
| 260 return; | 275 return; |
| 261 | 276 |
| 262 if (node == bookmark_bar_node_ || node == other_node_) { | 277 if (node == bookmark_bar_node_ || node == other_node_ || |
|
sky
2011/05/17 15:59:08
is_permanent_node
Yaron
2011/05/17 19:17:33
Done.
| |
| 278 node == synced_node_) { | |
| 263 NOTREACHED(); | 279 NOTREACHED(); |
| 264 return; | 280 return; |
| 265 } | 281 } |
| 266 | 282 |
| 267 // The title index doesn't support changing the title, instead we remove then | 283 // The title index doesn't support changing the title, instead we remove then |
| 268 // add it back. | 284 // add it back. |
| 269 index_->Remove(node); | 285 index_->Remove(node); |
| 270 AsMutable(node)->set_title(title); | 286 AsMutable(node)->set_title(title); |
| 271 index_->Add(node); | 287 index_->Add(node); |
| 272 | 288 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 details->ids_reassigned()) { | 577 details->ids_reassigned()) { |
| 562 // If bookmarks file changed externally, the IDs may have changed | 578 // If bookmarks file changed externally, the IDs may have changed |
| 563 // externally. In that case, the decoder may have reassigned IDs to make | 579 // 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 | 580 // them unique. So when the file has changed externally, we should save the |
| 565 // bookmarks file to persist new IDs. | 581 // bookmarks file to persist new IDs. |
| 566 if (store_.get()) | 582 if (store_.get()) |
| 567 store_->ScheduleSave(); | 583 store_->ScheduleSave(); |
| 568 } | 584 } |
| 569 bookmark_bar_node_ = details->release_bb_node(); | 585 bookmark_bar_node_ = details->release_bb_node(); |
| 570 other_node_ = details->release_other_folder_node(); | 586 other_node_ = details->release_other_folder_node(); |
| 587 synced_node_ = details->release_synced_folder_node(); | |
| 571 index_.reset(details->release_index()); | 588 index_.reset(details->release_index()); |
| 572 | 589 |
| 573 // WARNING: order is important here, various places assume bookmark bar then | 590 // WARNING: order is important here, various places assume bookmark bar then |
| 574 // other node. | 591 // other node. |
| 575 root_.Add(bookmark_bar_node_, 0); | 592 root_.Add(bookmark_bar_node_, 0); |
| 576 root_.Add(other_node_, 1); | 593 root_.Add(other_node_, 1); |
| 594 root_.Add(synced_node_, 2); | |
| 577 | 595 |
| 578 { | 596 { |
| 579 base::AutoLock url_lock(url_lock_); | 597 base::AutoLock url_lock(url_lock_); |
| 580 // Update nodes_ordered_by_url_set_ from the nodes. | 598 // Update nodes_ordered_by_url_set_ from the nodes. |
| 581 PopulateNodesByURL(&root_); | 599 PopulateNodesByURL(&root_); |
| 582 } | 600 } |
| 583 | 601 |
| 584 loaded_ = true; | 602 loaded_ = true; |
| 585 | 603 |
| 586 loaded_signal_.Signal(); | 604 loaded_signal_.Signal(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 entry.type = history::StarredEntry::BOOKMARK_BAR; | 730 entry.type = history::StarredEntry::BOOKMARK_BAR; |
| 713 return CreateRootNodeFromStarredEntry(entry); | 731 return CreateRootNodeFromStarredEntry(entry); |
| 714 } | 732 } |
| 715 | 733 |
| 716 BookmarkNode* BookmarkModel::CreateOtherBookmarksNode() { | 734 BookmarkNode* BookmarkModel::CreateOtherBookmarksNode() { |
| 717 history::StarredEntry entry; | 735 history::StarredEntry entry; |
| 718 entry.type = history::StarredEntry::OTHER; | 736 entry.type = history::StarredEntry::OTHER; |
| 719 return CreateRootNodeFromStarredEntry(entry); | 737 return CreateRootNodeFromStarredEntry(entry); |
| 720 } | 738 } |
| 721 | 739 |
| 740 BookmarkNode* BookmarkModel::CreateSyncedBookmarksNode() { | |
| 741 history::StarredEntry entry; | |
| 742 entry.type = history::StarredEntry::SYNCED; | |
| 743 return CreateRootNodeFromStarredEntry(entry); | |
| 744 } | |
| 745 | |
| 722 BookmarkNode* BookmarkModel::CreateRootNodeFromStarredEntry( | 746 BookmarkNode* BookmarkModel::CreateRootNodeFromStarredEntry( |
| 723 const history::StarredEntry& entry) { | 747 const history::StarredEntry& entry) { |
| 724 DCHECK(entry.type == history::StarredEntry::BOOKMARK_BAR || | 748 DCHECK(entry.type == history::StarredEntry::BOOKMARK_BAR || |
| 725 entry.type == history::StarredEntry::OTHER); | 749 entry.type == history::StarredEntry::OTHER || |
| 750 entry.type == history::StarredEntry::SYNCED); | |
| 726 BookmarkNode* node = new BookmarkNode(generate_next_node_id(), GURL()); | 751 BookmarkNode* node = new BookmarkNode(generate_next_node_id(), GURL()); |
| 727 node->Reset(entry); | 752 node->Reset(entry); |
| 728 if (entry.type == history::StarredEntry::BOOKMARK_BAR) { | 753 if (entry.type == history::StarredEntry::BOOKMARK_BAR) { |
| 729 node->set_title(l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_FOLDER_NAME)); | 754 node->set_title(l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_FOLDER_NAME)); |
| 755 } else if (entry.type == history::StarredEntry::SYNCED) { | |
| 756 node->set_title(l10n_util::GetStringUTF16( | |
| 757 IDS_BOOMARK_BAR_SYNCED_FOLDER_NAME)); | |
| 730 } else { | 758 } else { |
| 731 node->set_title( | 759 node->set_title( |
| 732 l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME)); | 760 l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_FOLDER_NAME)); |
| 733 } | 761 } |
| 734 return node; | 762 return node; |
| 735 } | 763 } |
| 736 | 764 |
| 737 void BookmarkModel::OnFaviconDataAvailable( | 765 void BookmarkModel::OnFaviconDataAvailable( |
| 738 FaviconService::Handle handle, | 766 FaviconService::Handle handle, |
| 739 history::FaviconData favicon) { | 767 history::FaviconData favicon) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 return next_node_id_++; | 847 return next_node_id_++; |
| 820 } | 848 } |
| 821 | 849 |
| 822 void BookmarkModel::SetFileChanged() { | 850 void BookmarkModel::SetFileChanged() { |
| 823 file_changed_ = true; | 851 file_changed_ = true; |
| 824 } | 852 } |
| 825 | 853 |
| 826 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { | 854 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { |
| 827 BookmarkNode* bb_node = CreateBookmarkNode(); | 855 BookmarkNode* bb_node = CreateBookmarkNode(); |
| 828 BookmarkNode* other_folder_node = CreateOtherBookmarksNode(); | 856 BookmarkNode* other_folder_node = CreateOtherBookmarksNode(); |
| 857 BookmarkNode* synced_folder_node = CreateSyncedBookmarksNode(); | |
| 829 return new BookmarkLoadDetails( | 858 return new BookmarkLoadDetails( |
| 830 bb_node, other_folder_node, new BookmarkIndex(profile()), next_node_id_); | 859 bb_node, other_folder_node, synced_folder_node, |
| 860 new BookmarkIndex(profile()), next_node_id_); | |
| 831 } | 861 } |
| OLD | NEW |