OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/gfx/favicon_size.h" | 7 #include "app/gfx/favicon_size.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // identifier for the image that we pass back to the caller. | 31 // identifier for the image that we pass back to the caller. |
32 LoadImageTask(ImageLoadingTracker* tracker, | 32 LoadImageTask(ImageLoadingTracker* tracker, |
33 const ExtensionResource& resource, | 33 const ExtensionResource& resource, |
34 size_t index) | 34 size_t index) |
35 : callback_loop_(MessageLoop::current()), | 35 : callback_loop_(MessageLoop::current()), |
36 tracker_(tracker), | 36 tracker_(tracker), |
37 resource_(resource), | 37 resource_(resource), |
38 index_(index) {} | 38 index_(index) {} |
39 | 39 |
40 void ReportBack(SkBitmap* image) { | 40 void ReportBack(SkBitmap* image) { |
41 DCHECK(image); | |
42 callback_loop_->PostTask(FROM_HERE, NewRunnableMethod(tracker_, | 41 callback_loop_->PostTask(FROM_HERE, NewRunnableMethod(tracker_, |
43 &ImageLoadingTracker::OnImageLoaded, | 42 &ImageLoadingTracker::OnImageLoaded, |
44 image, | 43 image, |
45 index_)); | 44 index_)); |
46 } | 45 } |
47 | 46 |
48 virtual void Run() { | 47 virtual void Run() { |
49 // Read the file from disk. | 48 // Read the file from disk. |
50 std::string file_contents; | 49 std::string file_contents; |
51 FilePath path = resource_.GetFilePath(); | 50 FilePath path = resource_.GetFilePath(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 //////////////////////////////////////////////////////////////////////////////// | 95 //////////////////////////////////////////////////////////////////////////////// |
97 // ImageLoadingTracker | 96 // ImageLoadingTracker |
98 | 97 |
99 void ImageLoadingTracker::PostLoadImageTask(const ExtensionResource& resource) { | 98 void ImageLoadingTracker::PostLoadImageTask(const ExtensionResource& resource) { |
100 MessageLoop* file_loop = g_browser_process->file_thread()->message_loop(); | 99 MessageLoop* file_loop = g_browser_process->file_thread()->message_loop(); |
101 file_loop->PostTask(FROM_HERE, new LoadImageTask(this, resource, | 100 file_loop->PostTask(FROM_HERE, new LoadImageTask(this, resource, |
102 posted_count_++)); | 101 posted_count_++)); |
103 } | 102 } |
104 | 103 |
105 void ImageLoadingTracker::OnImageLoaded(SkBitmap* image, size_t index) { | 104 void ImageLoadingTracker::OnImageLoaded(SkBitmap* image, size_t index) { |
106 if (image == NULL) { | |
107 NOTREACHED() << "Image failed to decode."; | |
108 image = new SkBitmap(); | |
109 } | |
110 if (observer_) | 105 if (observer_) |
111 observer_->OnImageLoaded(image, index); | 106 observer_->OnImageLoaded(image, index); |
112 delete image; | 107 |
| 108 if (image) |
| 109 delete image; |
| 110 |
113 if (--image_count_ == 0) | 111 if (--image_count_ == 0) |
114 Release(); // We are no longer needed. | 112 Release(); // We are no longer needed. |
115 } | 113 } |
OLD | NEW |