Chromium Code Reviews| Index: chrome/browser/extensions/image_loading_tracker.cc |
| diff --git a/chrome/browser/extensions/image_loading_tracker.cc b/chrome/browser/extensions/image_loading_tracker.cc |
| index e6c88913b8b7db189dccee2776be7f83f3feca16..d831031858d673d1af99e93083da7b7f2f2ce46b 100644 |
| --- a/chrome/browser/extensions/image_loading_tracker.cc |
| +++ b/chrome/browser/extensions/image_loading_tracker.cc |
| @@ -140,7 +140,7 @@ class ImageLoadingTracker::ImageLoader |
| std::string file_contents; |
| FilePath path = image_info.resource.GetFilePath(); |
| if (path.empty() || !file_util::ReadFileToString(path, &file_contents)) { |
| - ReportBack(NULL, image_info, gfx::Size(), id, false); |
| + ReportBack(NULL, image_info, gfx::Size(), id); |
| return; |
| } |
| @@ -157,21 +157,14 @@ class ImageLoadingTracker::ImageLoader |
| // Chrome is therefore decoding bitmaps here that were generated by Chrome. |
| *decoded = decoder.Decode(data, file_contents.length()); |
| if (decoded->empty()) { |
| - ReportBack(NULL, image_info, gfx::Size(), id, false); |
| + ReportBack(NULL, image_info, gfx::Size(), id); |
| return; // Unable to decode. |
| } |
| gfx::Size original_size(decoded->width(), decoded->height()); |
| - if (ShouldResizeImageRepresentation(image_info.resize_method, |
| - original_size, |
| - image_info.desired_size)) { |
| - *decoded = skia::ImageOperations::Resize( |
| - *decoded, skia::ImageOperations::RESIZE_LANCZOS3, |
| - image_info.desired_size.width(), image_info.desired_size.height()); |
| - } |
| + *decoded = ResizeIfNeeded(*decoded, image_info); |
| - ReportBack(decoded.release(), image_info, original_size, id, |
| - true /* delete bitmap */); |
| + ReportBack(decoded.release(), image_info, original_size, id); |
| } |
| // Instructs the loader to load a resource on the File thread. |
| @@ -189,33 +182,34 @@ class ImageLoadingTracker::ImageLoader |
| int id, |
| int resource_id) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| - const SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetImageNamed( |
| + scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
|
pkotwicz
2012/09/07 19:24:49
Optional: You can probably use SkBitmap instead of
xiyuan
2012/09/07 20:05:59
Added a TODO and I'll leave that to a dedicated cl
|
| + *bitmap = *ResourceBundle::GetSharedInstance().GetImageNamed( |
| resource_id).ToSkBitmap(); |
|
pkotwicz
2012/09/07 19:24:49
Nit: Use AsBitmap() instead of GetImageNamed()
xiyuan
2012/09/07 20:05:59
Done.
|
| - ReportBack(bitmap, image_info, image_info.desired_size, id, |
| - false /* don't delete bitmap */); |
| + |
| + *bitmap = ResizeIfNeeded(*bitmap, image_info); |
| + ReportBack(bitmap.release(), image_info, image_info.desired_size, id); |
| } |
| void ReportBack(const SkBitmap* bitmap, const ImageRepresentation& image_info, |
| - const gfx::Size& original_size, int id, bool delete_bitmap) { |
| + const gfx::Size& original_size, int id) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| BrowserThread::PostTask( |
| callback_thread_id_, FROM_HERE, |
| base::Bind(&ImageLoader::ReportOnCallingThread, this, |
| - bitmap, image_info, original_size, id, delete_bitmap)); |
| + bitmap, image_info, original_size, id)); |
| } |
| void ReportOnCallingThread(const SkBitmap* bitmap, |
| const ImageRepresentation& image_info, |
| const gfx::Size& original_size, |
| - int id, |
| - bool delete_bitmap) { |
| + int id) { |
| DCHECK(BrowserThread::CurrentlyOn(callback_thread_id_)); |
| if (tracker_) |
| tracker_->OnBitmapLoaded(bitmap, image_info, original_size, id, true); |
| - if (bitmap && delete_bitmap) |
| + if (bitmap) |
| delete bitmap; |
| } |
| @@ -223,6 +217,20 @@ class ImageLoadingTracker::ImageLoader |
| friend class base::RefCountedThreadSafe<ImageLoader>; |
| ~ImageLoader() {} |
| + SkBitmap ResizeIfNeeded(const SkBitmap& bitmap, |
| + const ImageRepresentation& image_info) { |
| + gfx::Size original_size(bitmap.width(), bitmap.height()); |
| + if (ShouldResizeImageRepresentation(image_info.resize_method, |
| + original_size, |
| + image_info.desired_size)) { |
| + return skia::ImageOperations::Resize( |
| + bitmap, skia::ImageOperations::RESIZE_LANCZOS3, |
| + image_info.desired_size.width(), image_info.desired_size.height()); |
| + } |
| + |
| + return bitmap; |
| + } |
| + |
| // The tracker we are loading the bitmap for. If NULL, it means the tracker is |
| // no longer interested in the reply. |
| ImageLoadingTracker* tracker_; |
| @@ -236,6 +244,13 @@ class ImageLoadingTracker::ImageLoader |
| //////////////////////////////////////////////////////////////////////////////// |
| // ImageLoadingTracker |
| +// static |
| +bool ImageLoadingTracker::IsSpecialBundledExtensionId( |
| + const std::string& extension_id) { |
| + int resource_id = -1; |
| + return FindSpecialExtensionResourceId(extension_id, &resource_id); |
| +} |
| + |
| ImageLoadingTracker::ImageLoadingTracker(Observer* observer) |
| : observer_(observer), |
| next_id_(0) { |