Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: chrome/browser/favicon/favicon_service.cc

Issue 10802066: Adds support for saving favicon size into history database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes as requested Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/favicon/select_favicon_frames.h" 7 #include "chrome/browser/favicon/select_favicon_frames.h"
8 #include "chrome/browser/history/history.h" 8 #include "chrome/browser/history/history.h"
9 #include "chrome/browser/history/history_backend.h" 9 #include "chrome/browser/history/history_backend.h"
10 #include "chrome/browser/history/history_service_factory.h" 10 #include "chrome/browser/history/history_service_factory.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 "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/codec/png_codec.h" 14 #include "ui/gfx/codec/png_codec.h"
15 #include "ui/gfx/favicon_size.h"
15 #include "ui/gfx/image/image_skia.h" 16 #include "ui/gfx/image/image_skia.h"
16 17
17 FaviconService::FaviconService(HistoryService* history_service) 18 FaviconService::FaviconService(HistoryService* history_service)
18 : history_service_(history_service) { 19 : history_service_(history_service) {
19 } 20 }
20 21
21 FaviconService::Handle FaviconService::GetFaviconImage( 22 FaviconService::Handle FaviconService::GetFaviconImage(
22 const GURL& icon_url, 23 const GURL& icon_url,
23 history::IconType icon_type, 24 history::IconType icon_type,
24 int desired_size_in_dip, 25 int desired_size_in_dip,
25 CancelableRequestConsumerBase* consumer, 26 CancelableRequestConsumerBase* consumer,
26 const FaviconImageCallback& callback) { 27 const FaviconImageCallback& callback) {
27 GetFaviconRequest* request = new GetFaviconRequest(base::Bind( 28 GetFaviconRequest* request = new GetFaviconRequest(base::Bind(
28 &FaviconService::GetFaviconImageCallback, 29 &FaviconService::GetFaviconImageCallback,
29 base::Unretained(this), 30 base::Unretained(this),
30 desired_size_in_dip, 31 desired_size_in_dip,
31 callback)); 32 callback));
32 AddRequest(request, consumer); 33 AddRequest(request, consumer);
33 // TODO(pkotwicz): Pass in desired size and scale factors. 34 if (history_service_) {
34 if (history_service_) 35 std::vector<GURL> icon_urls;
35 history_service_->GetFavicon(request, icon_url, icon_type); 36 icon_urls.push_back(icon_url);
36 else 37 history_service_->GetFavicons(request, icon_urls, icon_type,
38 desired_size_in_dip, ui::GetSupportedScaleFactors());
39 } else {
37 ForwardEmptyResultAsync(request); 40 ForwardEmptyResultAsync(request);
41 }
38 return request->handle(); 42 return request->handle();
39 } 43 }
40 44
41 FaviconService::Handle FaviconService::GetRawFavicon( 45 FaviconService::Handle FaviconService::GetRawFavicon(
42 const GURL& icon_url, 46 const GURL& icon_url,
43 history::IconType icon_type, 47 history::IconType icon_type,
44 int desired_size_in_dip, 48 int desired_size_in_dip,
45 ui::ScaleFactor desired_scale_factor, 49 ui::ScaleFactor desired_scale_factor,
46 CancelableRequestConsumerBase* consumer, 50 CancelableRequestConsumerBase* consumer,
47 const FaviconRawCallback& callback) { 51 const FaviconRawCallback& callback) {
48 GetFaviconRequest* request = new GetFaviconRequest(base::Bind( 52 GetFaviconRequest* request = new GetFaviconRequest(base::Bind(
49 &FaviconService::GetRawFaviconCallback, 53 &FaviconService::GetRawFaviconCallback,
50 base::Unretained(this), 54 base::Unretained(this),
51 desired_size_in_dip, 55 desired_size_in_dip,
52 desired_scale_factor, 56 desired_scale_factor,
53 callback)); 57 callback));
54 AddRequest(request, consumer); 58 AddRequest(request, consumer);
55 // TODO(pkotwicz): Pass in desired size and scale factor. 59 if (history_service_) {
56 if (history_service_) 60 std::vector<GURL> icon_urls;
57 history_service_->GetFavicon(request, icon_url, icon_type); 61 icon_urls.push_back(icon_url);
58 else 62 std::vector<ui::ScaleFactor> desired_scale_factors;
63 desired_scale_factors.push_back(desired_scale_factor);
64 history_service_->GetFavicons(request, icon_urls, icon_type,
65 desired_size_in_dip, desired_scale_factors);
66 } else {
59 ForwardEmptyResultAsync(request); 67 ForwardEmptyResultAsync(request);
68 }
60 return request->handle(); 69 return request->handle();
61 } 70 }
62 71
63 FaviconService::Handle FaviconService::GetFavicon( 72 FaviconService::Handle FaviconService::GetFavicon(
64 const GURL& icon_url, 73 const GURL& icon_url,
65 history::IconType icon_type, 74 history::IconType icon_type,
66 int desired_size_in_dip, 75 int desired_size_in_dip,
67 const std::vector<ui::ScaleFactor>& desired_scale_factors, 76 const std::vector<ui::ScaleFactor>& desired_scale_factors,
68 CancelableRequestConsumerBase* consumer, 77 CancelableRequestConsumerBase* consumer,
69 const FaviconResultsCallback& callback) { 78 const FaviconResultsCallback& callback) {
70 GetFaviconRequest* request = new GetFaviconRequest(callback); 79 GetFaviconRequest* request = new GetFaviconRequest(callback);
71 AddRequest(request, consumer); 80 AddRequest(request, consumer);
72 if (history_service_) 81 if (history_service_) {
73 history_service_->GetFavicon(request, icon_url, icon_type); 82 std::vector<GURL> icon_urls;
74 else 83 icon_urls.push_back(icon_url);
84 history_service_->GetFavicons(request, icon_urls, icon_type,
85 desired_size_in_dip, desired_scale_factors);
86 } else {
75 ForwardEmptyResultAsync(request); 87 ForwardEmptyResultAsync(request);
88 }
76 return request->handle(); 89 return request->handle();
77 } 90 }
78 91
79 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch( 92 FaviconService::Handle FaviconService::UpdateFaviconMappingAndFetch(
80 const GURL& page_url, 93 const GURL& page_url,
81 const GURL& icon_url, 94 const GURL& icon_url,
82 history::IconType icon_type, 95 history::IconType icon_type,
83 CancelableRequestConsumerBase* consumer, 96 CancelableRequestConsumerBase* consumer,
84 const FaviconResultsCallback& callback) { 97 const FaviconResultsCallback& callback) {
85 GetFaviconRequest* request = new GetFaviconRequest(callback); 98 GetFaviconRequest* request = new GetFaviconRequest(callback);
86 AddRequest(request, consumer); 99 AddRequest(request, consumer);
87 if (history_service_) 100 if (history_service_) {
88 history_service_->UpdateFaviconMappingAndFetch(request, page_url, 101 std::vector<GURL> icon_urls;
89 icon_url, icon_type); 102 icon_urls.push_back(icon_url);
90 else 103 // TODO(pkotwicz): Pass in |desired_size_in_dip| and |desired_scale_factors|
104 // from FaviconHandler.
105 history_service_->UpdateFaviconMappingsAndFetch(request, page_url,
106 icon_urls, icon_type, gfx::kFaviconSize, ui::GetSupportedScaleFactors()) ;
107 } else {
91 ForwardEmptyResultAsync(request); 108 ForwardEmptyResultAsync(request);
109 }
92 return request->handle(); 110 return request->handle();
93 } 111 }
94 112
95 FaviconService::Handle FaviconService::GetFaviconImageForURL( 113 FaviconService::Handle FaviconService::GetFaviconImageForURL(
96 Profile* profile, 114 Profile* profile,
97 const GURL& page_url, 115 const GURL& page_url,
98 int icon_types, 116 int icon_types,
99 int desired_size_in_dip, 117 int desired_size_in_dip,
100 CancelableRequestConsumerBase* consumer, 118 CancelableRequestConsumerBase* consumer,
101 const FaviconImageCallback& callback) { 119 const FaviconImageCallback& callback) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 const FaviconRawCallback& callback) { 171 const FaviconRawCallback& callback) {
154 GetFaviconRequest* request = new GetFaviconRequest(base::Bind( 172 GetFaviconRequest* request = new GetFaviconRequest(base::Bind(
155 &FaviconService::GetRawFaviconCallback, 173 &FaviconService::GetRawFaviconCallback,
156 base::Unretained(this), 174 base::Unretained(this),
157 desired_size_in_dip, 175 desired_size_in_dip,
158 desired_scale_factor, 176 desired_scale_factor,
159 callback)); 177 callback));
160 178
161 AddRequest(request, consumer); 179 AddRequest(request, consumer);
162 FaviconService::Handle handle = request->handle(); 180 FaviconService::Handle handle = request->handle();
163 // TODO(pkotwicz): Pass in desired size and scale factor. 181 if (history_service_) {
164 if (history_service_) 182 history_service_->GetFaviconForID(request, favicon_id, desired_size_in_dip,
165 history_service_->GetFaviconForID(request, favicon_id); 183 desired_scale_factor);
166 else 184 } else {
167 ForwardEmptyResultAsync(request); 185 ForwardEmptyResultAsync(request);
168 186 }
169 return handle; 187 return handle;
170 } 188 }
171 189
172 190
173 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) { 191 void FaviconService::SetFaviconOutOfDateForPage(const GURL& page_url) {
174 if (history_service_) 192 if (history_service_)
175 history_service_->SetFaviconOutOfDateForPage(page_url); 193 history_service_->SetFaviconsOutOfDateForPage(page_url);
176 } 194 }
177 195
178 void FaviconService::CloneFavicon(const GURL& old_page_url, 196 void FaviconService::CloneFavicon(const GURL& old_page_url,
179 const GURL& new_page_url) { 197 const GURL& new_page_url) {
180 if (history_service_) 198 if (history_service_)
181 history_service_->CloneFavicon(old_page_url, new_page_url); 199 history_service_->CloneFavicons(old_page_url, new_page_url);
182 } 200 }
183 201
184 void FaviconService::SetImportedFavicons( 202 void FaviconService::SetImportedFavicons(
185 const std::vector<history::ImportedFaviconUsage>& favicon_usage) { 203 const std::vector<history::ImportedFaviconUsage>& favicon_usage) {
186 if (history_service_) 204 if (history_service_)
187 history_service_->SetImportedFavicons(favicon_usage); 205 history_service_->SetImportedFavicons(favicon_usage);
188 } 206 }
189 207
190 void FaviconService::SetFavicon(const GURL& page_url, 208 void FaviconService::SetFavicon(const GURL& page_url,
191 const GURL& icon_url, 209 const GURL& icon_url,
192 const std::vector<unsigned char>& image_data, 210 const std::vector<unsigned char>& image_data,
193 history::IconType icon_type) { 211 history::IconType icon_type) {
194 if (history_service_) 212 if (history_service_) {
195 history_service_->SetFavicon(page_url, icon_url, image_data, icon_type); 213 // TODO(pkotwicz): Pass in real pixel size to SetFavicons.
michaelbai 2012/09/04 21:18:53 Not sure what did you mean pass in real pixel size
pkotwicz 2012/09/04 22:40:54 I am unsure as to whether the client should parse
214 history::FaviconBitmapData bitmap_data_element;
215 bitmap_data_element.bitmap_data = scoped_refptr<base::RefCountedMemory>(
216 new base::RefCountedBytes(image_data));
217 bitmap_data_element.pixel_size = gfx::Size();
218 bitmap_data_element.icon_url = icon_url;
219 std::vector<history::FaviconBitmapData> favicon_bitmap_data;
220 favicon_bitmap_data.push_back(bitmap_data_element);
221 history::IconURLSizesMap icon_url_sizes;
222 icon_url_sizes[icon_url] = history::GetDefaultFaviconSizes();
223 history_service_->SetFavicons(page_url, icon_type,
224 favicon_bitmap_data, icon_url_sizes);
225 }
196 } 226 }
197 227
198 FaviconService::~FaviconService() { 228 FaviconService::~FaviconService() {
199 } 229 }
200 230
201 FaviconService::Handle FaviconService::GetFaviconForURLImpl( 231 FaviconService::Handle FaviconService::GetFaviconForURLImpl(
202 Profile* profile, 232 Profile* profile,
203 const GURL& page_url, 233 const GURL& page_url,
204 int icon_types, 234 int icon_types,
205 int desired_size_in_dip, 235 int desired_size_in_dip,
206 const std::vector<ui::ScaleFactor>& desired_scale_factors, 236 const std::vector<ui::ScaleFactor>& desired_scale_factors,
207 CancelableRequestConsumerBase* consumer, 237 CancelableRequestConsumerBase* consumer,
208 GetFaviconRequest* request) { 238 GetFaviconRequest* request) {
209 AddRequest(request, consumer); 239 AddRequest(request, consumer);
210 FaviconService::Handle handle = request->handle(); 240 FaviconService::Handle handle = request->handle();
211 if (page_url.SchemeIs(chrome::kChromeUIScheme) || 241 if (page_url.SchemeIs(chrome::kChromeUIScheme) ||
212 page_url.SchemeIs(chrome::kExtensionScheme)) { 242 page_url.SchemeIs(chrome::kExtensionScheme)) {
213 // TODO(pkotwicz): Pass in desired size and desired scale factors. 243 // TODO(pkotwicz): Pass in desired size and desired scale factors.
214 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL( 244 ChromeWebUIControllerFactory::GetInstance()->GetFaviconForURL(
215 profile, request, page_url); 245 profile, request, page_url);
216 } else { 246 } else {
217 // TODO(pkotwicz): Pass in desired size and desired scale factors. 247 if (history_service_) {
218 if (history_service_) 248 history_service_->GetFaviconsForURL(request, page_url, icon_types,
219 history_service_->GetFaviconForURL(request, page_url, icon_types); 249 desired_size_in_dip, desired_scale_factors);
220 else 250 } else {
221 ForwardEmptyResultAsync(request); 251 ForwardEmptyResultAsync(request);
252 }
222 } 253 }
223 return handle; 254 return handle;
224 } 255 }
225 256
226 void FaviconService::GetFaviconImageCallback( 257 void FaviconService::GetFaviconImageCallback(
227 int desired_size_in_dip, 258 int desired_size_in_dip,
228 FaviconImageCallback callback, 259 FaviconImageCallback callback,
229 Handle handle, 260 Handle handle,
230 std::vector<history::FaviconBitmapResult> favicon_bitmap_results, 261 std::vector<history::FaviconBitmapResult> favicon_bitmap_results,
231 history::IconURLSizesMap icon_url_sizes_map) { 262 history::IconURLSizesMap icon_url_sizes_map) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector( 334 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector(
304 &resized_bitmap_data); 335 &resized_bitmap_data);
305 callback.Run(handle, bitmap_result); 336 callback.Run(handle, bitmap_result);
306 } 337 }
307 338
308 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) { 339 void FaviconService::ForwardEmptyResultAsync(GetFaviconRequest* request) {
309 request->ForwardResultAsync(request->handle(), 340 request->ForwardResultAsync(request->handle(),
310 std::vector<history::FaviconBitmapResult>(), 341 std::vector<history::FaviconBitmapResult>(),
311 history::IconURLSizesMap()); 342 history::IconURLSizesMap());
312 } 343 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/favicon/select_favicon_frames.h » ('j') | chrome/browser/history/history.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698