OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 10 #include "base/bind.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/history/history_notifications.h" | 22 #include "chrome/browser/history/history_notifications.h" |
23 #include "chrome/browser/history/history_service_factory.h" | 23 #include "chrome/browser/history/history_service_factory.h" |
24 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
28 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
31 #include "ui/base/l10n/l10n_util_collator.h" | 31 #include "ui/base/l10n/l10n_util_collator.h" |
| 32 #include "ui/gfx/favicon_size.h" |
32 #include "ui/gfx/image/image_util.h" | 33 #include "ui/gfx/image/image_util.h" |
33 | 34 |
34 using base::Time; | 35 using base::Time; |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 // Helper to get a mutable bookmark node. | 39 // Helper to get a mutable bookmark node. |
39 BookmarkNode* AsMutable(const BookmarkNode* node) { | 40 BookmarkNode* AsMutable(const BookmarkNode* node) { |
40 return const_cast<BookmarkNode*>(node); | 41 return const_cast<BookmarkNode*>(node); |
41 } | 42 } |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 title_id = IDS_BOOKMARK_BAR_FOLDER_NAME; | 771 title_id = IDS_BOOKMARK_BAR_FOLDER_NAME; |
771 break; | 772 break; |
772 } | 773 } |
773 node->SetTitle(l10n_util::GetStringUTF16(title_id)); | 774 node->SetTitle(l10n_util::GetStringUTF16(title_id)); |
774 node->set_type(type); | 775 node->set_type(type); |
775 return node; | 776 return node; |
776 } | 777 } |
777 | 778 |
778 void BookmarkModel::OnFaviconDataAvailable( | 779 void BookmarkModel::OnFaviconDataAvailable( |
779 FaviconService::Handle handle, | 780 FaviconService::Handle handle, |
780 history::FaviconData favicon) { | 781 const history::FaviconImageResult& image_result) { |
781 BookmarkNode* node = | 782 BookmarkNode* node = |
782 load_consumer_.GetClientData( | 783 load_consumer_.GetClientData( |
783 FaviconServiceFactory::GetForProfile( | 784 FaviconServiceFactory::GetForProfile( |
784 profile_, Profile::EXPLICIT_ACCESS), handle); | 785 profile_, Profile::EXPLICIT_ACCESS), handle); |
785 DCHECK(node); | 786 DCHECK(node); |
786 node->set_favicon_load_handle(0); | 787 node->set_favicon_load_handle(0); |
787 if (favicon.is_valid()) { | 788 if (!image_result.image.IsEmpty()) { |
788 scoped_ptr<gfx::Image> favicon_image( | 789 node->set_favicon(image_result.image); |
789 gfx::ImageFromPNGEncodedData(favicon.image_data->front(), | 790 FaviconLoaded(node); |
790 favicon.image_data->size())); | |
791 if (favicon_image.get()) { | |
792 node->set_favicon(*favicon_image.get()); | |
793 FaviconLoaded(node); | |
794 } | |
795 } | 791 } |
796 } | 792 } |
797 | 793 |
798 void BookmarkModel::LoadFavicon(BookmarkNode* node) { | 794 void BookmarkModel::LoadFavicon(BookmarkNode* node) { |
799 if (node->is_folder()) | 795 if (node->is_folder()) |
800 return; | 796 return; |
801 | 797 |
802 DCHECK(node->url().is_valid()); | 798 DCHECK(node->url().is_valid()); |
803 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 799 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
804 profile_, Profile::EXPLICIT_ACCESS); | 800 profile_, Profile::EXPLICIT_ACCESS); |
805 if (!favicon_service) | 801 if (!favicon_service) |
806 return; | 802 return; |
807 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 803 FaviconService::Handle handle = favicon_service->GetFaviconImageForURL( |
808 profile_, node->url(), history::FAVICON, &load_consumer_, | 804 profile_, node->url(), history::FAVICON, gfx::kFaviconSize, |
| 805 &load_consumer_, |
809 base::Bind(&BookmarkModel::OnFaviconDataAvailable, | 806 base::Bind(&BookmarkModel::OnFaviconDataAvailable, |
810 base::Unretained(this))); | 807 base::Unretained(this))); |
811 load_consumer_.SetClientData(favicon_service, handle, node); | 808 load_consumer_.SetClientData(favicon_service, handle, node); |
812 node->set_favicon_load_handle(handle); | 809 node->set_favicon_load_handle(handle); |
813 } | 810 } |
814 | 811 |
815 void BookmarkModel::FaviconLoaded(const BookmarkNode* node) { | 812 void BookmarkModel::FaviconLoaded(const BookmarkNode* node) { |
816 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, | 813 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, |
817 BookmarkNodeFaviconChanged(this, node)); | 814 BookmarkNodeFaviconChanged(this, node)); |
818 } | 815 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { | 869 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { |
873 BookmarkPermanentNode* bb_node = | 870 BookmarkPermanentNode* bb_node = |
874 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 871 CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
875 BookmarkPermanentNode* other_node = | 872 BookmarkPermanentNode* other_node = |
876 CreatePermanentNode(BookmarkNode::OTHER_NODE); | 873 CreatePermanentNode(BookmarkNode::OTHER_NODE); |
877 BookmarkPermanentNode* mobile_node = | 874 BookmarkPermanentNode* mobile_node = |
878 CreatePermanentNode(BookmarkNode::MOBILE); | 875 CreatePermanentNode(BookmarkNode::MOBILE); |
879 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, | 876 return new BookmarkLoadDetails(bb_node, other_node, mobile_node, |
880 new BookmarkIndex(profile_), next_node_id_); | 877 new BookmarkIndex(profile_), next_node_id_); |
881 } | 878 } |
OLD | NEW |