| 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 #ifndef CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ |
| 7 | 7 |
| 8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 9 | 9 |
| 10 class ExtensionResource; | 10 class ExtensionResource; |
| 11 class SkBitmap; | 11 class SkBitmap; |
| 12 | 12 |
| 13 namespace gfx { | 13 namespace gfx { |
| 14 class Size; | 14 class Size; |
| 15 } | 15 } |
| 16 | 16 |
| 17 // The views need to load their icons asynchronously but might be deleted before | 17 // The views need to load their icons asynchronously but might be deleted before |
| 18 // the images have loaded. This class stays alive while the request is in | 18 // the images have loaded. This class stays alive while the request is in |
| 19 // progress (manages its own lifetime) and keeps track of whether the view still | 19 // progress (manages its own lifetime) and keeps track of whether the view still |
| 20 // cares about the icon loading. | 20 // cares about the icon loading. |
| 21 // Consider abstracting out a FilePathProvider (ExtensionResource) and moving | 21 // Consider abstracting out a FilePathProvider (ExtensionResource) and moving |
| 22 // back to chrome/browser/ if other subsystems want to use it. | 22 // back to chrome/browser/ if other subsystems want to use it. |
| 23 class ImageLoadingTracker | 23 class ImageLoadingTracker |
| 24 : public base::RefCountedThreadSafe<ImageLoadingTracker> { | 24 : public base::RefCountedThreadSafe<ImageLoadingTracker> { |
| 25 public: | 25 public: |
| 26 class Observer { | 26 class Observer { |
| 27 public: | 27 public: |
| 28 // Will be called when the image with the given index has loaded. | 28 // Will be called when the image with the given index has loaded. |
| 29 // The |image| is owned by the tracker, so the observer should make a copy | 29 // The |image| is owned by the tracker, so the observer should make a copy |
| 30 // if they need to access it after this call. | 30 // if they need to access it after this call. |
| 31 virtual void OnImageLoaded(SkBitmap* image, size_t index) = 0; | 31 virtual void OnImageLoaded(ImageLoadingTracker* source, |
| 32 SkBitmap* image, |
| 33 size_t index) = 0; |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 ImageLoadingTracker(Observer* observer, size_t image_count) | 36 ImageLoadingTracker(Observer* observer, size_t image_count) |
| 35 : observer_(observer), image_count_(image_count), posted_count_(0) { | 37 : observer_(observer), |
| 38 image_count_(image_count), |
| 39 posted_count_(0) { |
| 36 AddRef(); // We hold on to a reference to ourself to make sure we don't | 40 AddRef(); // We hold on to a reference to ourself to make sure we don't |
| 37 // get deleted until we get a response from image loading (see | 41 // get deleted until we get a response from image loading (see |
| 38 // ImageLoadingDone). | 42 // ImageLoadingDone). |
| 39 } | 43 } |
| 40 | 44 |
| 41 // If there are remaining images to be loaded, the observing object should | 45 // If there are remaining images to be loaded, the observing object should |
| 42 // call this method on its destruction, so that the tracker will not attempt | 46 // call this method on its destruction, so that the tracker will not attempt |
| 43 // to make any more callbacks to it. | 47 // to make any more callbacks to it. |
| 44 void StopTrackingImageLoad() { | 48 void StopTrackingImageLoad() { |
| 45 observer_ = NULL; | 49 observer_ = NULL; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 74 // itself when it reaches zero. | 78 // itself when it reaches zero. |
| 75 size_t image_count_; | 79 size_t image_count_; |
| 76 | 80 |
| 77 // The number of tasks that have been posted so far. | 81 // The number of tasks that have been posted so far. |
| 78 size_t posted_count_; | 82 size_t posted_count_; |
| 79 | 83 |
| 80 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker); | 84 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker); |
| 81 }; | 85 }; |
| 82 | 86 |
| 83 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ | 87 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ |
| OLD | NEW |