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 #include "ui/gfx/favicon_size.h" |
13 | 14 |
14 FaviconService::FaviconService(Profile* profile) : profile_(profile) { | 15 FaviconService::FaviconService(Profile* profile) : profile_(profile) { |
15 } | 16 } |
16 | 17 |
17 FaviconService::Handle FaviconService::GetFavicon( | 18 FaviconService::Handle FaviconService::GetFavicon( |
18 const GURL& icon_url, | 19 const GURL& icon_url, |
19 history::IconType icon_type, | 20 history::IconType icon_type, |
20 CancelableRequestConsumerBase* consumer, | 21 CancelableRequestConsumerBase* consumer, |
21 const FaviconDataCallback& callback) { | 22 const FaviconDataCallback& callback) { |
22 GetFaviconRequest* request = new GetFaviconRequest(callback); | 23 GetFaviconRequest* request = new GetFaviconRequest(callback); |
23 AddRequest(request, consumer); | 24 AddRequest(request, consumer); |
24 HistoryService* hs = | 25 HistoryService* hs = |
25 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 26 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
26 if (hs) | 27 if (hs) |
27 hs->GetFavicon(request, icon_url, icon_type); | 28 hs->GetFavicon(request, icon_url, |
| 29 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), icon_type); |
28 else | 30 else |
29 ForwardEmptyResultAsync(request); | 31 ForwardEmptyResultAsync(request); |
30 return request->handle(); | 32 return request->handle(); |
31 } | 33 } |
32 | 34 |
33 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( | 35 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( |
34 const GURL& page_url, | 36 const GURL& page_url, |
35 const GURL& icon_url, | 37 const GURL& icon_url, |
36 history::IconType icon_type, | 38 history::IconType icon_type, |
37 CancelableRequestConsumerBase* consumer, | 39 CancelableRequestConsumerBase* consumer, |
38 const FaviconDataCallback& callback) { | 40 const FaviconDataCallback& callback) { |
39 GetFaviconRequest* request = new GetFaviconRequest(callback); | 41 GetFaviconRequest* request = new GetFaviconRequest(callback); |
40 AddRequest(request, consumer); | 42 AddRequest(request, consumer); |
41 HistoryService* hs = | 43 HistoryService* hs = |
42 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 44 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
43 if (hs) | 45 if (hs) { |
44 hs->UpdateFaviconMappingAndFetch(request, page_url, icon_url, icon_type); | 46 gfx::Size default_icon_size = |
45 else | 47 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); |
| 48 hs->UpdateFaviconMappingAndFetch(request, page_url, icon_url, |
| 49 default_icon_size, icon_type); |
| 50 } else { |
46 ForwardEmptyResultAsync(request); | 51 ForwardEmptyResultAsync(request); |
| 52 } |
47 return request->handle(); | 53 return request->handle(); |
48 } | 54 } |
49 | 55 |
50 FaviconService::Handle FaviconService::GetFaviconForURL( | 56 FaviconService::Handle FaviconService::GetFaviconForURL( |
51 const GURL& page_url, | 57 const GURL& page_url, |
52 int icon_types, | 58 int icon_types, |
53 CancelableRequestConsumerBase* consumer, | 59 CancelableRequestConsumerBase* consumer, |
54 const FaviconDataCallback& callback) { | 60 const FaviconDataCallback& callback) { |
55 GetFaviconRequest* request = new GetFaviconRequest(callback); | 61 GetFaviconRequest* request = new GetFaviconRequest(callback); |
56 AddRequest(request, consumer); | 62 AddRequest(request, consumer); |
57 FaviconService::Handle handle = request->handle(); | 63 FaviconService::Handle handle = request->handle(); |
58 if (page_url.SchemeIs(chrome::kChromeUIScheme) || | 64 if (page_url.SchemeIs(chrome::kChromeUIScheme) || |
59 page_url.SchemeIs(chrome::kExtensionScheme)) { | 65 page_url.SchemeIs(chrome::kExtensionScheme)) { |
60 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL( | 66 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL( |
61 profile_, request, page_url); | 67 profile_, request, page_url); |
62 } else { | 68 } else { |
63 HistoryService* hs = HistoryServiceFactory::GetForProfile( | 69 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
64 profile_, Profile::EXPLICIT_ACCESS); | 70 profile_, Profile::EXPLICIT_ACCESS); |
65 if (hs) | 71 if (hs) { |
66 hs->GetFaviconForURL(request, page_url, icon_types); | 72 gfx::Size default_icon_size(gfx::kFaviconSize, gfx::kFaviconSize); |
67 else | 73 hs->GetFaviconForURL(request, page_url, default_icon_size, icon_types); |
| 74 } else { |
68 ForwardEmptyResultAsync(request); | 75 ForwardEmptyResultAsync(request); |
| 76 } |
69 } | 77 } |
70 return handle; | 78 return handle; |
71 } | 79 } |
72 | 80 |
73 // Requests the favicon for |favicon_id|. The |consumer| is notified when the | 81 // Requests the favicon for |favicon_id|. The |consumer| is notified when the |
74 // bits have been fetched. | 82 // bits have been fetched. |
75 FaviconService::Handle FaviconService::GetFaviconForID( | 83 FaviconService::Handle FaviconService::GetFaviconForID( |
76 history::FaviconID favicon_id, | 84 history::FaviconID favicon_id, |
77 CancelableRequestConsumerBase* consumer, | 85 CancelableRequestConsumerBase* consumer, |
78 const FaviconDataCallback& callback) { | 86 const FaviconDataCallback& callback) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 if (hs) | 120 if (hs) |
113 hs->SetImportedFavicons(favicon_usage); | 121 hs->SetImportedFavicons(favicon_usage); |
114 } | 122 } |
115 | 123 |
116 void FaviconService::SetFavicon(const GURL& page_url, | 124 void FaviconService::SetFavicon(const GURL& page_url, |
117 const GURL& icon_url, | 125 const GURL& icon_url, |
118 const std::vector<unsigned char>& image_data, | 126 const std::vector<unsigned char>& image_data, |
119 history::IconType icon_type) { | 127 history::IconType icon_type) { |
120 HistoryService* hs = | 128 HistoryService* hs = |
121 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 129 HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
122 if (hs) | 130 if (hs) { |
123 hs->SetFavicon(page_url, icon_url, image_data, icon_type); | 131 // This size should correspond to FaviconHandler::preferred_icon_size(). |
| 132 // TODO(pkotwicz): Fix this. |
| 133 gfx::Size preferred_size = (icon_type == history::FAVICON) ? |
| 134 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize) : gfx::Size(); |
| 135 hs->SetFavicon(page_url, icon_url, image_data, preferred_size, icon_type); |
| 136 } |
124 } | 137 } |
125 | 138 |
126 FaviconService::~FaviconService() { | 139 FaviconService::~FaviconService() { |
127 } | 140 } |
128 | 141 |
129 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { | 142 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { |
130 request->ForwardResultAsync(request->handle(), history::FaviconData()); | 143 request->ForwardResultAsync(request->handle(), history::FaviconData()); |
131 } | 144 } |
OLD | NEW |