| 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/favicon/favicon_service.h" | 5 #include "chrome/browser/favicon/favicon_service.h" |
| 6 | 6 |
| 7 #include "chrome/browser/history/history.h" | 7 #include "chrome/browser/history/history.h" |
| 8 #include "chrome/browser/history/history_backend.h" | 8 #include "chrome/browser/history/history_backend.h" |
| 9 #include "chrome/browser/history/history_service_factory.h" | 9 #include "chrome/browser/history/history_service_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 11 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 | 13 |
| 14 FaviconService::FaviconService(Profile* profile) : profile_(profile) { | 14 FaviconService::FaviconService(Profile* profile) : profile_(profile) { |
| 15 } | 15 } |
| 16 | 16 |
| 17 FaviconService::Handle FaviconService::GetFavicon( | 17 FaviconService::Handle FaviconService::GetFavicon( |
| 18 const GURL& icon_url, | 18 const GURL& icon_url, |
| 19 history::IconType icon_type, | 19 history::IconType icon_type, |
| 20 CancelableRequestConsumerBase* consumer, | 20 CancelableRequestConsumerBase* consumer, |
| 21 const FaviconDataCallback& callback) { | 21 const FaviconDataCallback& callback) { |
| 22 GetFaviconRequest* request = new GetFaviconRequest(callback); | 22 GetFaviconRequest* request = new GetFaviconRequest(callback); |
| 23 AddRequest(request, consumer); | 23 AddRequest(request, consumer); |
| 24 HistoryService* hs = | 24 HistoryService* hs = |
| 25 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 25 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 26 if (hs) | 26 if (hs) { |
| 27 hs->GetFavicon(request, icon_url, icon_type); | 27 // There should only ever be a single favicon per page URL and |
| 28 else | 28 // history::IconType so the returned FaviconData should only have a |
| 29 // single bitmap and the passed in |desired_dip_size| and |
| 30 // |desired_scale_factors| shouldn't matter. |
| 31 std::vector<GURL> icon_urls; |
| 32 icon_urls.push_back(icon_url); |
| 33 hs->GetFavicon(request, icon_urls, icon_type, gfx::Size(), |
| 34 ui::GetSupportedScaleFactors()); |
| 35 } else { |
| 29 ForwardEmptyResultAsync(request); | 36 ForwardEmptyResultAsync(request); |
| 37 } |
| 30 return request->handle(); | 38 return request->handle(); |
| 31 } | 39 } |
| 32 | 40 |
| 33 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( | 41 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( |
| 34 const GURL& page_url, | 42 const GURL& page_url, |
| 35 const GURL& icon_url, | 43 const GURL& icon_url, |
| 36 history::IconType icon_type, | 44 history::IconType icon_type, |
| 37 CancelableRequestConsumerBase* consumer, | 45 CancelableRequestConsumerBase* consumer, |
| 38 const FaviconDataCallback& callback) { | 46 const FaviconDataCallback& callback) { |
| 39 GetFaviconRequest* request = new GetFaviconRequest(callback); | 47 GetFaviconRequest* request = new GetFaviconRequest(callback); |
| 40 AddRequest(request, consumer); | 48 AddRequest(request, consumer); |
| 41 HistoryService* hs = | 49 HistoryService* hs = |
| 42 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 50 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 43 if (hs) | 51 if (hs) { |
| 44 hs->UpdateFaviconMappingAndFetch(request, page_url, icon_url, icon_type); | 52 // There should only ever be a single favicon per page URL and |
| 45 else | 53 // history::IconType so the returned FaviconData should only have a |
| 54 // single bitmap and the passed in |desired_dip_size| and |
| 55 // |desired_scale_factors| shouldn't matter. |
| 56 std::vector<GURL> icon_urls; |
| 57 icon_urls.push_back(icon_url); |
| 58 hs->UpdateFaviconMappingsAndFetch(request, page_url, icon_urls, icon_type, |
| 59 gfx::Size(), ui::GetSupportedScaleFactors()); |
| 60 } else { |
| 46 ForwardEmptyResultAsync(request); | 61 ForwardEmptyResultAsync(request); |
| 62 } |
| 47 return request->handle(); | 63 return request->handle(); |
| 48 } | 64 } |
| 49 | 65 |
| 50 FaviconService::Handle FaviconService::GetFaviconForURL( | 66 FaviconService::Handle FaviconService::GetFaviconForURL( |
| 51 const GURL& page_url, | 67 const GURL& page_url, |
| 52 int icon_types, | 68 int icon_types, |
| 53 CancelableRequestConsumerBase* consumer, | 69 CancelableRequestConsumerBase* consumer, |
| 54 const FaviconDataCallback& callback) { | 70 const FaviconDataCallback& callback) { |
| 55 GetFaviconRequest* request = new GetFaviconRequest(callback); | 71 GetFaviconRequest* request = new GetFaviconRequest(callback); |
| 56 AddRequest(request, consumer); | 72 AddRequest(request, consumer); |
| 57 FaviconService::Handle handle = request->handle(); | 73 FaviconService::Handle handle = request->handle(); |
| 58 if (page_url.SchemeIs(chrome::kChromeUIScheme) || | 74 if (page_url.SchemeIs(chrome::kChromeUIScheme) || |
| 59 page_url.SchemeIs(chrome::kExtensionScheme)) { | 75 page_url.SchemeIs(chrome::kExtensionScheme)) { |
| 60 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL( | 76 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL( |
| 61 profile_, request, page_url); | 77 profile_, request, page_url); |
| 62 } else { | 78 } else { |
| 63 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 79 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 64 profile_, Profile::EXPLICIT_ACCESS); | 80 profile_, Profile::EXPLICIT_ACCESS); |
| 65 if (hs) | 81 if (hs) { |
| 66 hs->GetFaviconForURL(request, page_url, icon_types); | 82 // There should only ever be a single favicon per page URL for icon type |
| 67 else | 83 // FAVICON so the returned FaviconData should have a single element and |
| 84 // the passed in |desired_dip_size| and |desired_scale_factors| shouldn't |
| 85 // matter. |
| 86 hs->GetFaviconForURL(request, page_url, icon_types, gfx::Size(), |
| 87 ui::GetSupportedScaleFactors()); |
| 88 } else { |
| 68 ForwardEmptyResultAsync(request); | 89 ForwardEmptyResultAsync(request); |
| 90 } |
| 69 } | 91 } |
| 70 return handle; | 92 return handle; |
| 71 } | 93 } |
| 72 | 94 |
| 73 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { | 95 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { |
| 74 HistoryService* hs = | 96 HistoryService* hs = |
| 75 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 97 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 76 if (hs) | 98 if (hs) |
| 77 hs->SetFaviconOutOfDateForPage(page_url); | 99 hs->SetFaviconsOutOfDateForPage(page_url); |
| 78 } | 100 } |
| 79 | 101 |
| 80 void FaviconService::CloneFavicon(const GURL& old_page_url, | 102 void FaviconService::CloneFavicon(const GURL& old_page_url, |
| 81 const GURL& new_page_url) { | 103 const GURL& new_page_url) { |
| 82 HistoryService* hs = | 104 HistoryService* hs = |
| 83 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 105 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 84 if (hs) | 106 if (hs) |
| 85 hs->CloneFavicon(old_page_url, new_page_url); | 107 hs->CloneFavicons(old_page_url, new_page_url); |
| 86 } | 108 } |
| 87 | 109 |
| 88 void FaviconService::SetImportedFavicons( | 110 void FaviconService::SetImportedFavicons( |
| 89 const std::vector<history::ImportedFaviconUsage>& favicon_usage) { | 111 const std::vector<history::ImportedFaviconUsage>& favicon_usage) { |
| 90 HistoryService* hs = | 112 HistoryService* hs = |
| 91 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 113 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 92 if (hs) | 114 if (hs) |
| 93 hs->SetImportedFavicons(favicon_usage); | 115 hs->SetImportedFavicons(favicon_usage); |
| 94 } | 116 } |
| 95 | 117 |
| 96 void FaviconService::SetFavicon(const GURL& page_url, | 118 void FaviconService::SetFavicon(const GURL& page_url, |
| 97 const GURL& icon_url, | 119 const GURL& icon_url, |
| 98 const std::vector<unsigned char>& image_data, | 120 const std::vector<unsigned char>& image_data, |
| 99 history::IconType icon_type) { | 121 history::IconType icon_type) { |
| 100 HistoryService* hs = | 122 HistoryService* hs = |
| 101 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 123 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 102 if (hs) | 124 if (hs) { |
| 103 hs->SetFavicon(page_url, icon_url, image_data, icon_type); | 125 // TODO(pkotwicz): Pass in real pixel size to SetFavicons. |
| 126 history::FaviconBitmapData favicon_bitmap_data; |
| 127 favicon_bitmap_data.bitmap_data = scoped_refptr<base::RefCountedMemory>( |
| 128 new base::RefCountedBytes(image_data)); |
| 129 favicon_bitmap_data.pixel_size = gfx::Size(); |
| 130 std::vector<history::FaviconBitmapData> favicon_bitmaps; |
| 131 favicon_bitmaps.push_back(favicon_bitmap_data); |
| 132 history::IconURLSizesMap icon_url_sizes; |
| 133 icon_url_sizes[icon_url].push_back(gfx::Size()); |
| 134 hs->SetFavicons(page_url, icon_url, icon_type, favicon_bitmaps, |
| 135 icon_url_sizes); |
| 136 } |
| 104 } | 137 } |
| 105 | 138 |
| 106 FaviconService::~FaviconService() { | 139 FaviconService::~FaviconService() { |
| 107 } | 140 } |
| 108 | 141 |
| 109 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { | 142 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { |
| 110 request->ForwardResultAsync(request->handle(), history::FaviconData(), | 143 request->ForwardResultAsync(request->handle(), history::FaviconData(), |
| 111 std::vector<GURL>()); | 144 std::vector<GURL>()); |
| 112 } | 145 } |
| OLD | NEW |