| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "chrome/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" |
| 9 #include "chrome/common/extensions/extension_resource.h" | 9 #include "chrome/common/extensions/extension_resource.h" |
| 10 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
| 11 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "content/common/notification_service.h" | 12 #include "content/common/notification_service.h" |
| 12 #include "content/common/notification_type.h" | |
| 13 #include "skia/ext/image_operations.h" | 13 #include "skia/ext/image_operations.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "webkit/glue/image_decoder.h" | 15 #include "webkit/glue/image_decoder.h" |
| 16 | 16 |
| 17 ImageLoadingTracker::Observer::~Observer() {} | 17 ImageLoadingTracker::Observer::~Observer() {} |
| 18 | 18 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
| 20 // ImageLoadingTracker::ImageLoader | 20 // ImageLoadingTracker::ImageLoader |
| 21 | 21 |
| 22 // A RefCounted class for loading images on the File thread and reporting back | 22 // A RefCounted class for loading images on the File thread and reporting back |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(ImageLoader); | 115 DISALLOW_COPY_AND_ASSIGN(ImageLoader); |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 //////////////////////////////////////////////////////////////////////////////// | 118 //////////////////////////////////////////////////////////////////////////////// |
| 119 // ImageLoadingTracker | 119 // ImageLoadingTracker |
| 120 | 120 |
| 121 ImageLoadingTracker::ImageLoadingTracker(Observer* observer) | 121 ImageLoadingTracker::ImageLoadingTracker(Observer* observer) |
| 122 : observer_(observer), | 122 : observer_(observer), |
| 123 next_id_(0) { | 123 next_id_(0) { |
| 124 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 124 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 125 NotificationService::AllSources()); | 125 NotificationService::AllSources()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 ImageLoadingTracker::~ImageLoadingTracker() { | 128 ImageLoadingTracker::~ImageLoadingTracker() { |
| 129 // The loader is created lazily and is NULL if the tracker is destroyed before | 129 // The loader is created lazily and is NULL if the tracker is destroyed before |
| 130 // any valid image load tasks have been posted. | 130 // any valid image load tasks have been posted. |
| 131 if (loader_) | 131 if (loader_) |
| 132 loader_->StopTracking(); | 132 loader_->StopTracking(); |
| 133 } | 133 } |
| 134 | 134 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 LoadMap::iterator i = load_map_.find(id); | 172 LoadMap::iterator i = load_map_.find(id); |
| 173 if (i != load_map_.end()) { | 173 if (i != load_map_.end()) { |
| 174 i->second->SetCachedImage(resource, image ? *image : SkBitmap(), | 174 i->second->SetCachedImage(resource, image ? *image : SkBitmap(), |
| 175 original_size); | 175 original_size); |
| 176 load_map_.erase(i); | 176 load_map_.erase(i); |
| 177 } | 177 } |
| 178 | 178 |
| 179 observer_->OnImageLoaded(image, resource, id); | 179 observer_->OnImageLoaded(image, resource, id); |
| 180 } | 180 } |
| 181 | 181 |
| 182 void ImageLoadingTracker::Observe(NotificationType type, | 182 void ImageLoadingTracker::Observe(int type, |
| 183 const NotificationSource& source, | 183 const NotificationSource& source, |
| 184 const NotificationDetails& details) { | 184 const NotificationDetails& details) { |
| 185 DCHECK(type == NotificationType::EXTENSION_UNLOADED); | 185 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); |
| 186 | 186 |
| 187 const Extension* extension = | 187 const Extension* extension = |
| 188 Details<UnloadedExtensionInfo>(details)->extension; | 188 Details<UnloadedExtensionInfo>(details)->extension; |
| 189 | 189 |
| 190 // Remove all entries in the load_map_ referencing the extension. This ensures | 190 // Remove all entries in the load_map_ referencing the extension. This ensures |
| 191 // we don't attempt to cache the image when the load completes. | 191 // we don't attempt to cache the image when the load completes. |
| 192 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end();) { | 192 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end();) { |
| 193 if (i->second == extension) { | 193 if (i->second == extension) { |
| 194 load_map_.erase(i++); | 194 load_map_.erase(i++); |
| 195 } else { | 195 } else { |
| 196 ++i; | 196 ++i; |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 } | 199 } |
| OLD | NEW |