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

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

Issue 531493002: Move encoding SkBitmaps to PNG out of FaviconService::SetFavicons() and onto the history thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | chrome/browser/history/android/android_provider_backend_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <cmath> 7 #include <cmath>
8 8
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 void FaviconService::SetFavicons(const GURL& page_url, 304 void FaviconService::SetFavicons(const GURL& page_url,
305 const GURL& icon_url, 305 const GURL& icon_url,
306 favicon_base::IconType icon_type, 306 favicon_base::IconType icon_type,
307 const gfx::Image& image) { 307 const gfx::Image& image) {
308 if (!history_service_) 308 if (!history_service_)
309 return; 309 return;
310 310
311 gfx::ImageSkia image_skia = image.AsImageSkia(); 311 gfx::ImageSkia image_skia = image.AsImageSkia();
312 image_skia.EnsureRepsForSupportedScales(); 312 image_skia.EnsureRepsForSupportedScales();
313 const std::vector<gfx::ImageSkiaRep>& image_reps = image_skia.image_reps(); 313 const std::vector<gfx::ImageSkiaRep>& image_reps = image_skia.image_reps();
314 std::vector<favicon_base::FaviconRawBitmapData> favicon_bitmap_data; 314 std::vector<SkBitmap> bitmaps;
315 const std::vector<float> favicon_scales = favicon_base::GetFaviconScales(); 315 const std::vector<float> favicon_scales = favicon_base::GetFaviconScales();
316 for (size_t i = 0; i < image_reps.size(); ++i) { 316 for (size_t i = 0; i < image_reps.size(); ++i) {
317 // Don't save if the scale isn't one of supported favicon scale. 317 // Don't save if the scale isn't one of supported favicon scales.
318 if (std::find(favicon_scales.begin(), 318 if (std::find(favicon_scales.begin(),
319 favicon_scales.end(), 319 favicon_scales.end(),
320 image_reps[i].scale()) == favicon_scales.end()) { 320 image_reps[i].scale()) == favicon_scales.end()) {
321 continue; 321 continue;
322 } 322 }
323 323 bitmaps.push_back(image_reps[i].sk_bitmap());
324 scoped_refptr<base::RefCountedBytes> bitmap_data(
325 new base::RefCountedBytes());
326 if (gfx::PNGCodec::EncodeBGRASkBitmap(image_reps[i].sk_bitmap(),
327 false,
328 &bitmap_data->data())) {
329 gfx::Size pixel_size(image_reps[i].pixel_width(),
330 image_reps[i].pixel_height());
331 favicon_base::FaviconRawBitmapData bitmap_data_element;
332 bitmap_data_element.bitmap_data = bitmap_data;
333 bitmap_data_element.pixel_size = pixel_size;
334 bitmap_data_element.icon_url = icon_url;
335
336 favicon_bitmap_data.push_back(bitmap_data_element);
337 }
338 } 324 }
339 history_service_->SetFavicons(page_url, icon_type, favicon_bitmap_data); 325 history_service_->SetFavicons(page_url, icon_type, icon_url, bitmaps);
340 } 326 }
341 327
342 void FaviconService::UnableToDownloadFavicon(const GURL& icon_url) { 328 void FaviconService::UnableToDownloadFavicon(const GURL& icon_url) {
343 MissingFaviconURLHash url_hash = base::Hash(icon_url.spec()); 329 MissingFaviconURLHash url_hash = base::Hash(icon_url.spec());
344 missing_favicon_urls_.insert(url_hash); 330 missing_favicon_urls_.insert(url_hash);
345 } 331 }
346 332
347 bool FaviconService::WasUnableToDownloadFavicon(const GURL& icon_url) const { 333 bool FaviconService::WasUnableToDownloadFavicon(const GURL& icon_url) const {
348 MissingFaviconURLHash url_hash = base::Hash(icon_url.spec()); 334 MissingFaviconURLHash url_hash = base::Hash(icon_url.spec());
349 return missing_favicon_urls_.find(url_hash) != missing_favicon_urls_.end(); 335 return missing_favicon_urls_.find(url_hash) != missing_favicon_urls_.end();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (!gfx::PNGCodec::EncodeBGRASkBitmap(resized_image.AsBitmap(), false, 418 if (!gfx::PNGCodec::EncodeBGRASkBitmap(resized_image.AsBitmap(), false,
433 &resized_bitmap_data)) { 419 &resized_bitmap_data)) {
434 callback.Run(favicon_base::FaviconRawBitmapResult()); 420 callback.Run(favicon_base::FaviconRawBitmapResult());
435 return; 421 return;
436 } 422 }
437 423
438 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector( 424 bitmap_result.bitmap_data = base::RefCountedBytes::TakeVector(
439 &resized_bitmap_data); 425 &resized_bitmap_data);
440 callback.Run(bitmap_result); 426 callback.Run(bitmap_result);
441 } 427 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/history/android/android_provider_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698