OLD | NEW |
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" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 | 172 |
173 ReportBack(decoded.release(), image_info, original_size, id, | 173 ReportBack(decoded.release(), image_info, original_size, id, |
174 true /* delete bitmap */); | 174 true /* delete bitmap */); |
175 } | 175 } |
176 | 176 |
177 // Instructs the loader to load a resource on the File thread. | 177 // Instructs the loader to load a resource on the File thread. |
178 void LoadResource(const ImageRepresentation& image_info, | 178 void LoadResource(const ImageRepresentation& image_info, |
179 int id, | 179 int id, |
180 int resource_id) { | 180 int resource_id) { |
| 181 LOG(ERROR) << "post load job to file thread"; |
181 DCHECK(BrowserThread::CurrentlyOn(callback_thread_id_)); | 182 DCHECK(BrowserThread::CurrentlyOn(callback_thread_id_)); |
182 BrowserThread::PostTask( | 183 BrowserThread::PostTask( |
183 BrowserThread::FILE, FROM_HERE, | 184 BrowserThread::FILE, FROM_HERE, |
184 base::Bind(&ImageLoader::LoadResourceOnFileThread, this, image_info, | 185 base::Bind(&ImageLoader::LoadResourceOnFileThread, this, image_info, |
185 id, resource_id)); | 186 id, resource_id)); |
186 } | 187 } |
187 | 188 |
188 void LoadResourceOnFileThread(const ImageRepresentation& image_info, | 189 void LoadResourceOnFileThread(const ImageRepresentation& image_info, |
189 int id, | 190 int id, |
190 int resource_id) { | 191 int resource_id) { |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
192 const SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetImageNamed( | 193 const SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetImageNamed( |
193 resource_id).ToSkBitmap(); | 194 resource_id).ToSkBitmap(); |
194 ReportBack(bitmap, image_info, image_info.desired_size, id, | 195 ReportBack(bitmap, image_info, image_info.desired_size, id, |
195 false /* don't delete bitmap */); | 196 false /* don't delete bitmap */); |
196 } | 197 } |
197 | 198 |
198 void ReportBack(const SkBitmap* bitmap, const ImageRepresentation& image_info, | 199 void ReportBack(const SkBitmap* bitmap, const ImageRepresentation& image_info, |
199 const gfx::Size& original_size, int id, bool delete_bitmap) { | 200 const gfx::Size& original_size, int id, bool delete_bitmap) { |
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
201 | 202 |
| 203 LOG(ERROR) << "post load job resp to calling thread"; |
202 BrowserThread::PostTask( | 204 BrowserThread::PostTask( |
203 callback_thread_id_, FROM_HERE, | 205 callback_thread_id_, FROM_HERE, |
204 base::Bind(&ImageLoader::ReportOnCallingThread, this, | 206 base::Bind(&ImageLoader::ReportOnCallingThread, this, |
205 bitmap, image_info, original_size, id, delete_bitmap)); | 207 bitmap, image_info, original_size, id, delete_bitmap)); |
206 } | 208 } |
207 | 209 |
208 void ReportOnCallingThread(const SkBitmap* bitmap, | 210 void ReportOnCallingThread(const SkBitmap* bitmap, |
209 const ImageRepresentation& image_info, | 211 const ImageRepresentation& image_info, |
210 const gfx::Size& original_size, | 212 const gfx::Size& original_size, |
211 int id, | 213 int id, |
212 bool delete_bitmap) { | 214 bool delete_bitmap) { |
213 DCHECK(BrowserThread::CurrentlyOn(callback_thread_id_)); | 215 DCHECK(BrowserThread::CurrentlyOn(callback_thread_id_)); |
214 | 216 LOG(ERROR) << "OnBitmapLoaded"; |
215 if (tracker_) | 217 if (tracker_) |
216 tracker_->OnBitmapLoaded(bitmap, image_info, original_size, id, true); | 218 tracker_->OnBitmapLoaded(bitmap, image_info, original_size, id, true); |
217 | 219 |
218 if (bitmap && delete_bitmap) | 220 if (bitmap && delete_bitmap) |
219 delete bitmap; | 221 delete bitmap; |
220 } | 222 } |
221 | 223 |
222 private: | 224 private: |
223 friend class base::RefCountedThreadSafe<ImageLoader>; | 225 friend class base::RefCountedThreadSafe<ImageLoader>; |
224 ~ImageLoader() {} | 226 ~ImageLoader() {} |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 if (info->pending_count == 0) { | 373 if (info->pending_count == 0) { |
372 gfx::Image image; | 374 gfx::Image image; |
373 std::string extension_id = info->extension_id; | 375 std::string extension_id = info->extension_id; |
374 | 376 |
375 if (!info->image_skia.isNull()) { | 377 if (!info->image_skia.isNull()) { |
376 info->image_skia.MakeThreadSafe(); | 378 info->image_skia.MakeThreadSafe(); |
377 image = gfx::Image(info->image_skia); | 379 image = gfx::Image(info->image_skia); |
378 } | 380 } |
379 | 381 |
380 load_map_.erase(load_map_it); | 382 load_map_.erase(load_map_it); |
381 | 383 LOG(ERROR) << "on image loaded"; |
382 // ImageLoadingTracker might be deleted after the callback so don't do | 384 // ImageLoadingTracker might be deleted after the callback so don't do |
383 // anything after this statement. | 385 // anything after this statement. |
384 observer_->OnImageLoaded(image, extension_id, id); | 386 observer_->OnImageLoaded(image, extension_id, id); |
385 } | 387 } |
386 } | 388 } |
387 | 389 |
388 void ImageLoadingTracker::Observe(int type, | 390 void ImageLoadingTracker::Observe(int type, |
389 const content::NotificationSource& source, | 391 const content::NotificationSource& source, |
390 const content::NotificationDetails& details) { | 392 const content::NotificationDetails& details) { |
391 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); | 393 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); |
392 | 394 |
393 const Extension* extension = | 395 const Extension* extension = |
394 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; | 396 content::Details<extensions::UnloadedExtensionInfo>(details)->extension; |
395 | 397 |
396 // Remove reference to this extension from all pending load entries. This | 398 // Remove reference to this extension from all pending load entries. This |
397 // ensures we don't attempt to cache the bitmap when the load completes. | 399 // ensures we don't attempt to cache the bitmap when the load completes. |
398 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { | 400 for (LoadMap::iterator i = load_map_.begin(); i != load_map_.end(); ++i) { |
399 PendingLoadInfo* info = &i->second; | 401 PendingLoadInfo* info = &i->second; |
400 if (info->extension == extension) { | 402 if (info->extension == extension) { |
401 info->extension = NULL; | 403 info->extension = NULL; |
402 info->cache = DONT_CACHE; | 404 info->cache = DONT_CACHE; |
403 } | 405 } |
404 } | 406 } |
405 } | 407 } |
OLD | NEW |