| 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/command_line.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_index.h" | 14 #include "chrome/browser/bookmarks/bookmark_index.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_storage.h" | 16 #include "chrome/browser/bookmarks/bookmark_storage.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_utils.h" | 17 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/history/history_notifications.h" | 19 #include "chrome/browser/history/history_notifications.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 22 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
| 23 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/l10n/l10n_util_collator.h" | 26 #include "ui/base/l10n/l10n_util_collator.h" |
| 26 #include "ui/gfx/codec/png_codec.h" | 27 #include "ui/gfx/codec/png_codec.h" |
| 27 | 28 |
| 28 using base::Time; | 29 using base::Time; |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 void BookmarkModel::Load() { | 138 void BookmarkModel::Load() { |
| 138 if (store_.get()) { | 139 if (store_.get()) { |
| 139 // If the store is non-null, it means Load was already invoked. Load should | 140 // If the store is non-null, it means Load was already invoked. Load should |
| 140 // only be invoked once. | 141 // only be invoked once. |
| 141 NOTREACHED(); | 142 NOTREACHED(); |
| 142 return; | 143 return; |
| 143 } | 144 } |
| 144 | 145 |
| 145 // Listen for changes to favicons so that we can update the favicon of the | 146 // Listen for changes to favicons so that we can update the favicon of the |
| 146 // node appropriately. | 147 // node appropriately. |
| 147 registrar_.Add(this, NotificationType::FAVICON_CHANGED, | 148 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED, |
| 148 Source<Profile>(profile_)); | 149 Source<Profile>(profile_)); |
| 149 | 150 |
| 150 // Load the bookmarks. BookmarkStorage notifies us when done. | 151 // Load the bookmarks. BookmarkStorage notifies us when done. |
| 151 store_ = new BookmarkStorage(profile_, this); | 152 store_ = new BookmarkStorage(profile_, this); |
| 152 store_->LoadBookmarks(CreateLoadDetails()); | 153 store_->LoadBookmarks(CreateLoadDetails()); |
| 153 } | 154 } |
| 154 | 155 |
| 155 const BookmarkNode* BookmarkModel::GetParentForNewNodes() { | 156 const BookmarkNode* BookmarkModel::GetParentForNewNodes() { |
| 156 std::vector<const BookmarkNode*> nodes = | 157 std::vector<const BookmarkNode*> nodes = |
| 157 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1); | 158 bookmark_utils::GetMostRecentlyModifiedFolders(this, 1); |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 | 594 |
| 594 loaded_ = true; | 595 loaded_ = true; |
| 595 | 596 |
| 596 loaded_signal_.Signal(); | 597 loaded_signal_.Signal(); |
| 597 | 598 |
| 598 // Notify our direct observers. | 599 // Notify our direct observers. |
| 599 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, Loaded(this)); | 600 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, Loaded(this)); |
| 600 | 601 |
| 601 // And generic notification. | 602 // And generic notification. |
| 602 NotificationService::current()->Notify( | 603 NotificationService::current()->Notify( |
| 603 NotificationType::BOOKMARK_MODEL_LOADED, | 604 chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
| 604 Source<Profile>(profile_), | 605 Source<Profile>(profile_), |
| 605 NotificationService::NoDetails()); | 606 NotificationService::NoDetails()); |
| 606 } | 607 } |
| 607 | 608 |
| 608 void BookmarkModel::RemoveAndDeleteNode(BookmarkNode* delete_me) { | 609 void BookmarkModel::RemoveAndDeleteNode(BookmarkNode* delete_me) { |
| 609 scoped_ptr<BookmarkNode> node(delete_me); | 610 scoped_ptr<BookmarkNode> node(delete_me); |
| 610 | 611 |
| 611 BookmarkNode* parent = AsMutable(node->parent()); | 612 BookmarkNode* parent = AsMutable(node->parent()); |
| 612 DCHECK(parent); | 613 DCHECK(parent); |
| 613 int index = parent->GetIndexOf(node.get()); | 614 int index = parent->GetIndexOf(node.get()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 } | 646 } |
| 646 | 647 |
| 647 if (profile_) { | 648 if (profile_) { |
| 648 HistoryService* history = | 649 HistoryService* history = |
| 649 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 650 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 650 if (history) | 651 if (history) |
| 651 history->URLsNoLongerBookmarked(details.changed_urls); | 652 history->URLsNoLongerBookmarked(details.changed_urls); |
| 652 } | 653 } |
| 653 | 654 |
| 654 NotificationService::current()->Notify( | 655 NotificationService::current()->Notify( |
| 655 NotificationType::URLS_STARRED, | 656 chrome::NOTIFICATION_URLS_STARRED, |
| 656 Source<Profile>(profile_), | 657 Source<Profile>(profile_), |
| 657 Details<history::URLsStarredDetails>(&details)); | 658 Details<history::URLsStarredDetails>(&details)); |
| 658 } | 659 } |
| 659 | 660 |
| 660 BookmarkNode* BookmarkModel::AddNode(BookmarkNode* parent, | 661 BookmarkNode* BookmarkModel::AddNode(BookmarkNode* parent, |
| 661 int index, | 662 int index, |
| 662 BookmarkNode* node, | 663 BookmarkNode* node, |
| 663 bool was_bookmarked) { | 664 bool was_bookmarked) { |
| 664 parent->Add(node, index); | 665 parent->Add(node, index); |
| 665 | 666 |
| 666 if (store_.get()) | 667 if (store_.get()) |
| 667 store_->ScheduleSave(); | 668 store_->ScheduleSave(); |
| 668 | 669 |
| 669 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, | 670 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, |
| 670 BookmarkNodeAdded(this, parent, index)); | 671 BookmarkNodeAdded(this, parent, index)); |
| 671 | 672 |
| 672 index_->Add(node); | 673 index_->Add(node); |
| 673 | 674 |
| 674 if (node->is_url() && !was_bookmarked) { | 675 if (node->is_url() && !was_bookmarked) { |
| 675 history::URLsStarredDetails details(true); | 676 history::URLsStarredDetails details(true); |
| 676 details.changed_urls.insert(node->GetURL()); | 677 details.changed_urls.insert(node->GetURL()); |
| 677 NotificationService::current()->Notify( | 678 NotificationService::current()->Notify( |
| 678 NotificationType::URLS_STARRED, | 679 chrome::NOTIFICATION_URLS_STARRED, |
| 679 Source<Profile>(profile_), | 680 Source<Profile>(profile_), |
| 680 Details<history::URLsStarredDetails>(&details)); | 681 Details<history::URLsStarredDetails>(&details)); |
| 681 } | 682 } |
| 682 return node; | 683 return node; |
| 683 } | 684 } |
| 684 | 685 |
| 685 void BookmarkModel::BlockTillLoaded() { | 686 void BookmarkModel::BlockTillLoaded() { |
| 686 loaded_signal_.Wait(); | 687 loaded_signal_.Wait(); |
| 687 } | 688 } |
| 688 | 689 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 void BookmarkModel::CancelPendingFaviconLoadRequests(BookmarkNode* node) { | 762 void BookmarkModel::CancelPendingFaviconLoadRequests(BookmarkNode* node) { |
| 762 if (node->favicon_load_handle()) { | 763 if (node->favicon_load_handle()) { |
| 763 FaviconService* favicon_service = | 764 FaviconService* favicon_service = |
| 764 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 765 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
| 765 if (favicon_service) | 766 if (favicon_service) |
| 766 favicon_service->CancelRequest(node->favicon_load_handle()); | 767 favicon_service->CancelRequest(node->favicon_load_handle()); |
| 767 node->set_favicon_load_handle(0); | 768 node->set_favicon_load_handle(0); |
| 768 } | 769 } |
| 769 } | 770 } |
| 770 | 771 |
| 771 void BookmarkModel::Observe(NotificationType type, | 772 void BookmarkModel::Observe(int type, |
| 772 const NotificationSource& source, | 773 const NotificationSource& source, |
| 773 const NotificationDetails& details) { | 774 const NotificationDetails& details) { |
| 774 switch (type.value) { | 775 switch (type) { |
| 775 case NotificationType::FAVICON_CHANGED: { | 776 case chrome::NOTIFICATION_FAVICON_CHANGED: { |
| 776 // Prevent the observers from getting confused for multiple favicon loads. | 777 // Prevent the observers from getting confused for multiple favicon loads. |
| 777 Details<history::FaviconChangeDetails> favicon_details(details); | 778 Details<history::FaviconChangeDetails> favicon_details(details); |
| 778 for (std::set<GURL>::const_iterator i = favicon_details->urls.begin(); | 779 for (std::set<GURL>::const_iterator i = favicon_details->urls.begin(); |
| 779 i != favicon_details->urls.end(); ++i) { | 780 i != favicon_details->urls.end(); ++i) { |
| 780 std::vector<const BookmarkNode*> nodes; | 781 std::vector<const BookmarkNode*> nodes; |
| 781 GetNodesByURL(*i, &nodes); | 782 GetNodesByURL(*i, &nodes); |
| 782 for (size_t i = 0; i < nodes.size(); ++i) { | 783 for (size_t i = 0; i < nodes.size(); ++i) { |
| 783 // Got an updated favicon, for a URL, do a new request. | 784 // Got an updated favicon, for a URL, do a new request. |
| 784 BookmarkNode* node = AsMutable(nodes[i]); | 785 BookmarkNode* node = AsMutable(nodes[i]); |
| 785 node->InvalidateFavicon(); | 786 node->InvalidateFavicon(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 814 file_changed_ = true; | 815 file_changed_ = true; |
| 815 } | 816 } |
| 816 | 817 |
| 817 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { | 818 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { |
| 818 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 819 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
| 819 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); | 820 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); |
| 820 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); | 821 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); |
| 821 return new BookmarkLoadDetails(bb_node, other_node, synced_node, | 822 return new BookmarkLoadDetails(bb_node, other_node, synced_node, |
| 822 new BookmarkIndex(profile()), next_node_id_); | 823 new BookmarkIndex(profile()), next_node_id_); |
| 823 } | 824 } |
| OLD | NEW |