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

Side by Side Diff: chrome/browser/extensions/image_loading_tracker.cc

Issue 10245003: Makes ImageSkia more like SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comment Created 8 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/extensions/image_loading_tracker_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/extensions/image_loading_tracker.h" 5 #include "chrome/browser/extensions/image_loading_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 9 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
10 #include "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/extensions/extension.h" 11 #include "chrome/common/extensions/extension.h"
12 #include "chrome/common/extensions/extension_constants.h" 12 #include "chrome/common/extensions/extension_constants.h"
13 #include "chrome/common/extensions/extension_resource.h" 13 #include "chrome/common/extensions/extension_resource.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_service.h" 15 #include "content/public/browser/notification_service.h"
16 #include "grit/component_extension_resources_map.h" 16 #include "grit/component_extension_resources_map.h"
17 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
18 #include "skia/ext/image_operations.h" 18 #include "skia/ext/image_operations.h"
19 #include "third_party/skia/include/core/SkBitmap.h" 19 #include "third_party/skia/include/core/SkBitmap.h"
20 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
21 #include "ui/gfx/image/image_skia.h"
21 #include "webkit/glue/image_decoder.h" 22 #include "webkit/glue/image_decoder.h"
22 23
23 using content::BrowserThread; 24 using content::BrowserThread;
24 25
25 //////////////////////////////////////////////////////////////////////////////// 26 ////////////////////////////////////////////////////////////////////////////////
26 // ImageLoadingTracker::Observer 27 // ImageLoadingTracker::Observer
27 28
28 ImageLoadingTracker::Observer::~Observer() {} 29 ImageLoadingTracker::Observer::~Observer() {}
29 30
30 //////////////////////////////////////////////////////////////////////////////// 31 ////////////////////////////////////////////////////////////////////////////////
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 info->extension->SetCachedImage(resource, image ? *image : SkBitmap(), 297 info->extension->SetCachedImage(resource, image ? *image : SkBitmap(),
297 original_size); 298 original_size);
298 } 299 }
299 300
300 // If all pending images are done then report back. 301 // If all pending images are done then report back.
301 if (info->pending_count == 0) { 302 if (info->pending_count == 0) {
302 gfx::Image image; 303 gfx::Image image;
303 std::string extension_id = info->extension_id; 304 std::string extension_id = info->extension_id;
304 305
305 if (info->bitmaps.size() > 0) { 306 if (info->bitmaps.size() > 0) {
306 std::vector<const SkBitmap*> bitmaps; 307 gfx::ImageSkia image_skia;
307 for (std::vector<SkBitmap>::const_iterator it = info->bitmaps.begin(); 308 for (std::vector<SkBitmap>::const_iterator it = info->bitmaps.begin();
308 it != info->bitmaps.end(); ++it) { 309 it != info->bitmaps.end(); ++it) {
309 // gfx::Image takes ownership of this bitmap. 310 // TODO(pkotwicz): Do something better but ONLY when ENABLE_DIP.
310 bitmaps.push_back(new SkBitmap(*it)); 311 image_skia.AddBitmapForScale(*it, 1.0f);
311 } 312 }
312 image = gfx::Image(bitmaps); 313 image = gfx::Image(image_skia);
313 } 314 }
314 315
315 load_map_.erase(load_map_it); 316 load_map_.erase(load_map_it);
316 317
317 // ImageLoadingTracker might be deleted after the callback so don't 318 // ImageLoadingTracker might be deleted after the callback so don't
318 // anything after this statement. 319 // anything after this statement.
319 observer_->OnImageLoaded(image, extension_id, id); 320 observer_->OnImageLoaded(image, extension_id, id);
320 } 321 }
321 } 322 }
322 323
323 void ImageLoadingTracker::Observe(int type, 324 void ImageLoadingTracker::Observe(int type,
324 const content::NotificationSource& source, 325 const content::NotificationSource& source,
325 const content::NotificationDetails& details) { 326 const content::NotificationDetails& details) {
326 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); 327 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED);
327 328
328 const Extension* extension = 329 const Extension* extension =
329 content::Details<UnloadedExtensionInfo>(details)->extension; 330 content::Details<UnloadedExtensionInfo>(details)->extension;
330 331
331 // Remove reference to this extension from all pending load entries. This 332 // Remove reference to this extension from all pending load entries. This
332 // ensures we don't attempt to cache the image when the load completes. 333 // ensures we don't attempt to cache the image when the load completes.
333 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { 334 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) {
334 PendingLoadInfo* info = &i->second; 335 PendingLoadInfo* info = &i->second;
335 if (info->extension == extension) { 336 if (info->extension == extension) {
336 info->extension = NULL; 337 info->extension = NULL;
337 info->cache = DONT_CACHE; 338 info->cache = DONT_CACHE;
338 } 339 }
339 } 340 }
340 } 341 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/image_loading_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698