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

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

Issue 10699065: chromeos: Fix pixelated icons in app list and launcher (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, move Resize/CreateDropShadow into ImageSkiaSource Created 8 years, 5 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/extensions/image_loading_tracker.h" 5 #include "chrome/browser/extensions/image_loading_tracker.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 12 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
13 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/extensions/extension.h" 14 #include "chrome/common/extensions/extension.h"
15 #include "chrome/common/extensions/extension_constants.h" 15 #include "chrome/common/extensions/extension_constants.h"
16 #include "chrome/common/extensions/extension_icon_set.h"
16 #include "chrome/common/extensions/extension_resource.h" 17 #include "chrome/common/extensions/extension_resource.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "grit/component_extension_resources_map.h" 20 #include "grit/component_extension_resources_map.h"
20 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
21 #include "skia/ext/image_operations.h" 22 #include "skia/ext/image_operations.h"
22 #include "third_party/skia/include/core/SkBitmap.h" 23 #include "third_party/skia/include/core/SkBitmap.h"
23 #include "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
24 #include "ui/gfx/image/image_skia.h"
25 #include "ui/gfx/image/image_skia_rep.h" 25 #include "ui/gfx/image/image_skia_rep.h"
26 #include "ui/gfx/screen.h"
26 #include "webkit/glue/image_decoder.h" 27 #include "webkit/glue/image_decoder.h"
27 28
28 using content::BrowserThread; 29 using content::BrowserThread;
29 using extensions::Extension; 30 using extensions::Extension;
30 31
31 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
32 // ImageLoadingTracker::Observer 33 // ImageLoadingTracker::Observer
33 34
34 ImageLoadingTracker::Observer::~Observer() {} 35 ImageLoadingTracker::Observer::~Observer() {}
35 36
36 //////////////////////////////////////////////////////////////////////////////// 37 ////////////////////////////////////////////////////////////////////////////////
37 // ImageLoadingTracker::ImageInfo 38 // ImageLoadingTracker::ImageInfo
38 39
39 ImageLoadingTracker::ImageInfo::ImageInfo( 40 ImageLoadingTracker::ImageInfo::ImageInfo(
40 const ExtensionResource& resource, gfx::Size max_size) 41 const ExtensionResource& resource, const gfx::Size& max_size)
pkotwicz 2012/07/04 00:19:50 Maybe a bad diff. We're doing this in a different
xiyuan 2012/07/10 20:02:13 Not really a bad diff. I still keep those files in
41 : resource(resource), max_size(max_size) { 42 : resource(resource), max_size(max_size), scale(1.0f) {
43 }
44
45 ImageLoadingTracker::ImageInfo::ImageInfo(
46 const ExtensionResource& resource, const gfx::Size& max_size, float scale)
47 : resource(resource), max_size(max_size), scale(scale) {
42 } 48 }
43 49
44 ImageLoadingTracker::ImageInfo::~ImageInfo() { 50 ImageLoadingTracker::ImageInfo::~ImageInfo() {
45 } 51 }
46 52
47 //////////////////////////////////////////////////////////////////////////////// 53 ////////////////////////////////////////////////////////////////////////////////
48 // ImageLoadingTracker::PendingLoadInfo 54 // ImageLoadingTracker::PendingLoadInfo
49 55
50 ImageLoadingTracker::PendingLoadInfo::PendingLoadInfo() 56 ImageLoadingTracker::PendingLoadInfo::PendingLoadInfo()
51 : extension(NULL), 57 : extension(NULL),
(...skipping 17 matching lines...) Expand all
69 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); 75 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE));
70 } 76 }
71 77
72 // Lets this class know that the tracker is no longer interested in the 78 // Lets this class know that the tracker is no longer interested in the
73 // results. 79 // results.
74 void StopTracking() { 80 void StopTracking() {
75 tracker_ = NULL; 81 tracker_ = NULL;
76 } 82 }
77 83
78 // Instructs the loader to load a task on the File thread. 84 // Instructs the loader to load a task on the File thread.
79 void LoadImage(const ExtensionResource& resource, 85 void LoadImage(const ImageInfo& image_info, int id) {
80 const gfx::Size& max_size,
81 int id) {
82 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); 86 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE));
83 BrowserThread::PostTask( 87 BrowserThread::PostTask(
84 BrowserThread::FILE, FROM_HERE, 88 BrowserThread::FILE, FROM_HERE,
85 base::Bind(&ImageLoader::LoadOnFileThread, this, resource, 89 base::Bind(&ImageLoader::LoadOnFileThread, this, image_info, id));
86 max_size, id));
87 } 90 }
88 91
89 void LoadOnFileThread(const ExtensionResource& resource, 92 void LoadOnFileThread(const ImageInfo& image_info, int id) {
90 const gfx::Size& max_size,
91 int id) {
92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
93 94
94 // Read the file from disk. 95 // Read the file from disk.
95 std::string file_contents; 96 std::string file_contents;
96 FilePath path = resource.GetFilePath(); 97 FilePath path = image_info.resource.GetFilePath();
97 if (path.empty() || !file_util::ReadFileToString(path, &file_contents)) { 98 if (path.empty() || !file_util::ReadFileToString(path, &file_contents)) {
98 ReportBack(NULL, resource, gfx::Size(), id); 99 ReportBack(NULL, image_info, gfx::Size(), id);
99 return; 100 return;
100 } 101 }
101 102
102 // Decode the image using WebKit's image decoder. 103 // Decode the image using WebKit's image decoder.
103 const unsigned char* data = 104 const unsigned char* data =
104 reinterpret_cast<const unsigned char*>(file_contents.data()); 105 reinterpret_cast<const unsigned char*>(file_contents.data());
105 webkit_glue::ImageDecoder decoder; 106 webkit_glue::ImageDecoder decoder;
106 scoped_ptr<SkBitmap> decoded(new SkBitmap()); 107 scoped_ptr<SkBitmap> decoded(new SkBitmap());
107 // Note: This class only decodes images from extension resources. Chrome 108 // Note: This class only decodes images from extension resources. Chrome
108 // doesn't (for security reasons) directly load extension resources provided 109 // doesn't (for security reasons) directly load extension resources provided
109 // by the extension author, but instead decodes them in a separate 110 // by the extension author, but instead decodes them in a separate
110 // locked-down utility process. Only if the decoding succeeds is the image 111 // locked-down utility process. Only if the decoding succeeds is the image
111 // saved from memory to disk and subsequently used in the Chrome UI. 112 // saved from memory to disk and subsequently used in the Chrome UI.
112 // Chrome is therefore decoding images here that were generated by Chrome. 113 // Chrome is therefore decoding images here that were generated by Chrome.
113 *decoded = decoder.Decode(data, file_contents.length()); 114 *decoded = decoder.Decode(data, file_contents.length());
114 if (decoded->empty()) { 115 if (decoded->empty()) {
115 ReportBack(NULL, resource, gfx::Size(), id); 116 ReportBack(NULL, image_info, gfx::Size(), id);
116 return; // Unable to decode. 117 return; // Unable to decode.
117 } 118 }
118 119
119 gfx::Size original_size(decoded->width(), decoded->height()); 120 gfx::Size original_size(decoded->width(), decoded->height());
120 121
121 if (decoded->width() > max_size.width() || 122 if (decoded->width() > image_info.max_size.width() ||
122 decoded->height() > max_size.height()) { 123 decoded->height() > image_info.max_size.height()) {
123 // The bitmap is too big, re-sample. 124 // The bitmap is too big, re-sample.
124 *decoded = skia::ImageOperations::Resize( 125 *decoded = skia::ImageOperations::Resize(
125 *decoded, skia::ImageOperations::RESIZE_LANCZOS3, 126 *decoded, skia::ImageOperations::RESIZE_LANCZOS3,
126 max_size.width(), max_size.height()); 127 image_info.max_size.width(), image_info.max_size.height());
127 } 128 }
128 129
129 ReportBack(decoded.release(), resource, original_size, id); 130 ReportBack(decoded.release(), image_info, original_size, id);
130 } 131 }
131 132
132 // Instructs the loader to load a resource on the File thread. 133 // Instructs the loader to load a resource on the File thread.
133 void LoadResource(const ExtensionResource& resource, 134 void LoadResource(const ImageInfo& image_info, int id, int resource_id) {
134 const gfx::Size& max_size,
135 int id,
136 int resource_id) {
137 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); 135 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE));
138 BrowserThread::PostTask( 136 BrowserThread::PostTask(
139 BrowserThread::FILE, FROM_HERE, 137 BrowserThread::FILE, FROM_HERE,
140 base::Bind(&ImageLoader::LoadResourceOnFileThread, this, resource, 138 base::Bind(&ImageLoader::LoadResourceOnFileThread, this, image_info,
141 max_size, id, resource_id)); 139 id, resource_id));
142 } 140 }
143 141
144 void LoadResourceOnFileThread(const ExtensionResource& resource, 142 void LoadResourceOnFileThread(const ImageInfo& image_info,
145 const gfx::Size& max_size,
146 int id, 143 int id,
147 int resource_id) { 144 int resource_id) {
148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
149 SkBitmap* image = ExtensionIconSource::LoadImageByResourceId( 146 SkBitmap* image = ExtensionIconSource::LoadImageByResourceId(
150 resource_id); 147 resource_id);
151 ReportBack(image, resource, max_size, id); 148 ReportBack(image, image_info, image_info.max_size, id);
152 } 149 }
153 150
154 void ReportBack(SkBitmap* image, const ExtensionResource& resource, 151 void ReportBack(SkBitmap* image, const ImageInfo& image_info,
155 const gfx::Size& original_size, int id) { 152 const gfx::Size& original_size, int id) {
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
157 154
158 BrowserThread::PostTask( 155 BrowserThread::PostTask(
159 callback_thread_id_, FROM_HERE, 156 callback_thread_id_, FROM_HERE,
160 base::Bind(&ImageLoader::ReportOnUIThread, this, 157 base::Bind(&ImageLoader::ReportOnUIThread, this,
161 image, resource, original_size, id)); 158 image, image_info, original_size, id));
162 } 159 }
163 160
164 void ReportOnUIThread(SkBitmap* image, const ExtensionResource& resource, 161 void ReportOnUIThread(SkBitmap* image, const ImageInfo& image_info,
165 const gfx::Size& original_size, int id) { 162 const gfx::Size& original_size, int id) {
166 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); 163 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE));
167 164
168 if (tracker_) 165 if (tracker_)
169 tracker_->OnImageLoaded(image, resource, original_size, id, true); 166 tracker_->OnImageLoaded(image, image_info, original_size, id, true);
170 167
171 delete image; 168 delete image;
172 } 169 }
173 170
174 private: 171 private:
175 friend class base::RefCountedThreadSafe<ImageLoader>; 172 friend class base::RefCountedThreadSafe<ImageLoader>;
176 ~ImageLoader() {} 173 ~ImageLoader() {}
177 174
178 // The tracker we are loading the image for. If NULL, it means the tracker is 175 // The tracker we are loading the image for. If NULL, it means the tracker is
179 // no longer interested in the reply. 176 // no longer interested in the reply.
(...skipping 24 matching lines...) Expand all
204 201
205 void ImageLoadingTracker::LoadImage(const Extension* extension, 202 void ImageLoadingTracker::LoadImage(const Extension* extension,
206 const ExtensionResource& resource, 203 const ExtensionResource& resource,
207 const gfx::Size& max_size, 204 const gfx::Size& max_size,
208 CacheParam cache) { 205 CacheParam cache) {
209 std::vector<ImageInfo> info_list; 206 std::vector<ImageInfo> info_list;
210 info_list.push_back(ImageInfo(resource, max_size)); 207 info_list.push_back(ImageInfo(resource, max_size));
211 LoadImages(extension, info_list, cache); 208 LoadImages(extension, info_list, cache);
212 } 209 }
213 210
211 void ImageLoadingTracker::LoadDIPImage(
212 const extensions::Extension* extension,
213 int preferred_dip_size,
214 gfx::Size max_dip_size,
215 CacheParam cache) {
216 if (!gfx::Screen::IsDIPEnabled()) {
217 LoadImage(extension,
218 extension->GetIconResource(preferred_dip_size,
219 ExtensionIconSet::MATCH_BIGGER),
220 max_dip_size,
221 cache);
222 return;
223 }
224
225 float scale = ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P);
oshima 2012/07/03 23:00:06 can you comment on why we want to always use 200P?
xiyuan 2012/07/10 20:02:13 This is because I think ImageLoadingTracker should
226 std::vector<ImageInfo> info_list;
227 info_list.push_back(ImageInfo(
228 extension->GetIconResource(static_cast<int>(preferred_dip_size * scale),
229 ExtensionIconSet::MATCH_BIGGER),
230 gfx::Size(static_cast<int>(max_dip_size.width() * scale),
231 static_cast<int>(max_dip_size.height() * scale)),
232 scale));
233 LoadImages(extension, info_list, cache);
234 }
235
214 void ImageLoadingTracker::LoadImages(const Extension* extension, 236 void ImageLoadingTracker::LoadImages(const Extension* extension,
215 const std::vector<ImageInfo>& info_list, 237 const std::vector<ImageInfo>& info_list,
216 CacheParam cache) { 238 CacheParam cache) {
217 PendingLoadInfo load_info; 239 PendingLoadInfo load_info;
218 load_info.extension = extension; 240 load_info.extension = extension;
219 load_info.cache = cache; 241 load_info.cache = cache;
220 load_info.extension_id = extension->id(); 242 load_info.extension_id = extension->id();
221 load_info.pending_count = info_list.size(); 243 load_info.pending_count = info_list.size();
222 int id = next_id_++; 244 int id = next_id_++;
223 load_map_[id] = load_info; 245 load_map_[id] = load_info;
224 246
225 for (std::vector<ImageInfo>::const_iterator it = info_list.begin(); 247 for (std::vector<ImageInfo>::const_iterator it = info_list.begin();
226 it != info_list.end(); ++it) { 248 it != info_list.end(); ++it) {
227 // Load resources for special component extensions. 249 // Load resources for special component extensions.
228 if (load_info.extension_id == extension_misc::kWebStoreAppId) { 250 if (load_info.extension_id == extension_misc::kWebStoreAppId) {
229 if (!loader_) 251 if (!loader_)
230 loader_ = new ImageLoader(this); 252 loader_ = new ImageLoader(this);
231 loader_->LoadResource(it->resource, it->max_size, id, IDR_WEBSTORE_ICON); 253 loader_->LoadResource(*it, id, IDR_WEBSTORE_ICON);
232 continue; 254 continue;
233 } else if (load_info.extension_id == extension_misc::kChromeAppId) { 255 } else if (load_info.extension_id == extension_misc::kChromeAppId) {
234 if (!loader_) 256 if (!loader_)
235 loader_ = new ImageLoader(this); 257 loader_ = new ImageLoader(this);
236 loader_->LoadResource(it->resource, 258 loader_->LoadResource(*it, id, IDR_PRODUCT_LOGO_128);
237 it->max_size,
238 id,
239 IDR_PRODUCT_LOGO_128);
240 continue; 259 continue;
241 } 260 }
242 261
243 // If we don't have a path we don't need to do any further work, just 262 // If we don't have a path we don't need to do any further work, just
244 // respond back. 263 // respond back.
245 if (it->resource.relative_path().empty()) { 264 if (it->resource.relative_path().empty()) {
246 OnImageLoaded(NULL, it->resource, it->max_size, id, false); 265 OnImageLoaded(NULL, *it, it->max_size, id, false);
247 continue; 266 continue;
248 } 267 }
249 268
250 DCHECK(extension->path() == it->resource.extension_root()); 269 DCHECK(extension->path() == it->resource.extension_root());
251 270
252 // See if the extension has the image already. 271 // See if the extension has the image already.
253 if (extension->HasCachedImage(it->resource, it->max_size)) { 272 if (extension->HasCachedImage(it->resource, it->max_size)) {
254 SkBitmap image = extension->GetCachedImage(it->resource, it->max_size); 273 SkBitmap image = extension->GetCachedImage(it->resource, it->max_size);
255 OnImageLoaded(&image, it->resource, it->max_size, id, false); 274 OnImageLoaded(&image, *it, it->max_size, id, false);
256 continue; 275 continue;
257 } 276 }
258 277
259 // Instruct the ImageLoader to load this on the File thread. LoadImage and 278 // Instruct the ImageLoader to load this on the File thread. LoadImage and
260 // LoadResource do not block. 279 // LoadResource do not block.
261 if (!loader_) 280 if (!loader_)
262 loader_ = new ImageLoader(this); 281 loader_ = new ImageLoader(this);
263 282
264 int resource_id; 283 int resource_id;
265 if (IsComponentExtensionResource(extension, it->resource, resource_id)) 284 if (IsComponentExtensionResource(extension, it->resource, resource_id))
266 loader_->LoadResource(it->resource, it->max_size, id, resource_id); 285 loader_->LoadResource(*it, id, resource_id);
267 else 286 else
268 loader_->LoadImage(it->resource, it->max_size, id); 287 loader_->LoadImage(*it, id);
269 } 288 }
270 } 289 }
271 290
272 bool ImageLoadingTracker::IsComponentExtensionResource( 291 bool ImageLoadingTracker::IsComponentExtensionResource(
273 const Extension* extension, 292 const Extension* extension,
274 const ExtensionResource& resource, 293 const ExtensionResource& resource,
275 int& resource_id) const { 294 int& resource_id) const {
276 if (extension->location() != Extension::COMPONENT) 295 if (extension->location() != Extension::COMPONENT)
277 return false; 296 return false;
278 297
279 FilePath directory_path = extension->path(); 298 FilePath directory_path = extension->path();
280 FilePath relative_path = directory_path.BaseName().Append( 299 FilePath relative_path = directory_path.BaseName().Append(
281 resource.relative_path()); 300 resource.relative_path());
282 301
283 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) { 302 for (size_t i = 0; i < kComponentExtensionResourcesSize; ++i) {
284 FilePath resource_path = 303 FilePath resource_path =
285 FilePath().AppendASCII(kComponentExtensionResources[i].name); 304 FilePath().AppendASCII(kComponentExtensionResources[i].name);
286 resource_path = resource_path.NormalizePathSeparators(); 305 resource_path = resource_path.NormalizePathSeparators();
287 306
288 if (relative_path == resource_path) { 307 if (relative_path == resource_path) {
289 resource_id = kComponentExtensionResources[i].value; 308 resource_id = kComponentExtensionResources[i].value;
290 return true; 309 return true;
291 } 310 }
292 } 311 }
293 return false; 312 return false;
294 } 313 }
295 314
296 void ImageLoadingTracker::OnImageLoaded( 315 void ImageLoadingTracker::OnImageLoaded(
297 SkBitmap* image, 316 SkBitmap* image,
298 const ExtensionResource& resource, 317 const ImageInfo& image_info,
299 const gfx::Size& original_size, 318 const gfx::Size& original_size,
300 int id, 319 int id,
301 bool should_cache) { 320 bool should_cache) {
302 LoadMap::iterator load_map_it = load_map_.find(id); 321 LoadMap::iterator load_map_it = load_map_.find(id);
303 DCHECK(load_map_it != load_map_.end()); 322 DCHECK(load_map_it != load_map_.end());
304 PendingLoadInfo* info = &load_map_it->second; 323 PendingLoadInfo* info = &load_map_it->second;
305 324
306 // Save the pending results. 325 // Save the pending results.
307 DCHECK(info->pending_count > 0); 326 DCHECK(info->pending_count > 0);
308 info->pending_count--; 327 info->pending_count--;
309 if (image) 328 if (image) {
310 info->bitmaps.push_back(*image); 329 info->images.AddRepresentation(gfx::ImageSkiaRep(*image,
330 ui::GetScaleFactorFromScale(image_info.scale)));
331 }
311 332
312 // Add to the extension's image cache if requested. 333 // Add to the extension's image cache if requested.
313 DCHECK(info->cache != CACHE || info->extension); 334 DCHECK(info->cache != CACHE || info->extension);
314 if (should_cache && info->cache == CACHE && 335 if (should_cache && info->cache == CACHE &&
315 !info->extension->HasCachedImage(resource, original_size)) { 336 !info->extension->HasCachedImage(image_info.resource, original_size)) {
316 info->extension->SetCachedImage(resource, image ? *image : SkBitmap(), 337 info->extension->SetCachedImage(image_info.resource,
338 image ? *image : SkBitmap(),
317 original_size); 339 original_size);
318 } 340 }
319 341
320 // If all pending images are done then report back. 342 // If all pending images are done then report back.
321 if (info->pending_count == 0) { 343 if (info->pending_count == 0) {
322 gfx::Image image; 344 gfx::Image image(info->images);
323 std::string extension_id = info->extension_id; 345 std::string extension_id = info->extension_id;
324 346
325 if (info->bitmaps.size() > 0) {
326 gfx::ImageSkia image_skia;
327 for (std::vector<SkBitmap>::const_iterator it = info->bitmaps.begin();
328 it != info->bitmaps.end(); ++it) {
329 // TODO(pkotwicz): Do something better but ONLY when DIP is enabled.
330 image_skia.AddRepresentation(
331 gfx::ImageSkiaRep(*it, ui::SCALE_FACTOR_100P));
332 }
333 image = gfx::Image(image_skia);
334 }
335
336 load_map_.erase(load_map_it); 347 load_map_.erase(load_map_it);
337 348
338 // ImageLoadingTracker might be deleted after the callback so don't 349 // ImageLoadingTracker might be deleted after the callback so don't
339 // anything after this statement. 350 // anything after this statement.
340 observer_->OnImageLoaded(image, extension_id, id); 351 observer_->OnImageLoaded(image, extension_id, id);
341 } 352 }
342 } 353 }
343 354
344 void ImageLoadingTracker::Observe(int type, 355 void ImageLoadingTracker::Observe(int type,
345 const content::NotificationSource& source, 356 const content::NotificationSource& source,
346 const content::NotificationDetails& details) { 357 const content::NotificationDetails& details) {
347 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); 358 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED);
348 359
349 const Extension* extension = 360 const Extension* extension =
350 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; 361 content::Details<extensions::UnloadedExtensionInfo>(details)->extension;
351 362
352 // Remove reference to this extension from all pending load entries. This 363 // Remove reference to this extension from all pending load entries. This
353 // ensures we don't attempt to cache the image when the load completes. 364 // ensures we don't attempt to cache the image when the load completes.
354 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { 365 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) {
355 PendingLoadInfo* info = &i->second; 366 PendingLoadInfo* info = &i->second;
356 if (info->extension == extension) { 367 if (info->extension == extension) {
357 info->extension = NULL; 368 info->extension = NULL;
358 info->cache = DONT_CACHE; 369 info->cache = DONT_CACHE;
359 } 370 }
360 } 371 }
361 } 372 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698