summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/image_loading_tracker.h
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-24 16:00:34 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-24 16:00:34 +0000
commit699e1cd56df7b6f775601c80e99d26f83162a412 (patch)
tree22d80a14e0ddd552731daac0be3aa2e6dc8bd9ec /chrome/browser/extensions/image_loading_tracker.h
parentbfae5e6625d0b3cd38d1b7481a12f6a177a2fbde (diff)
downloadchromium_src-699e1cd56df7b6f775601c80e99d26f83162a412.zip
chromium_src-699e1cd56df7b6f775601c80e99d26f83162a412.tar.gz
chromium_src-699e1cd56df7b6f775601c80e99d26f83162a412.tar.bz2
Eliminate all UI thread decoding of extension images.
Except one, that is. We have one location we need to take a look at (I've added a comment). This changelist converts UI usage of DecodeImage on the UI thread to a revamped and simplified ImageLoadingTracker class. I plan on adding to GetFilePath a DCHECK for the File thread but decided to do so in another changelist, since it has a high likelyhood of flushing something out and be backed out because of that. This started out as issue 38521 (make infobar use cached icons) but grew in scope to just eliminate all UI thread access to DecodeImage and GetFilePath. BUG=http://crbug.com/38521 TEST=None (extensions should work as before) Review URL: http://codereview.chromium.org/1075006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/image_loading_tracker.h')
-rw-r--r--chrome/browser/extensions/image_loading_tracker.h82
1 files changed, 37 insertions, 45 deletions
diff --git a/chrome/browser/extensions/image_loading_tracker.h b/chrome/browser/extensions/image_loading_tracker.h
index 23f7b71..adcf009 100644
--- a/chrome/browser/extensions/image_loading_tracker.h
+++ b/chrome/browser/extensions/image_loading_tracker.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,76 +6,68 @@
#define CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_
#include "base/ref_counted.h"
+#include "chrome/common/extensions/extension.h"
class ExtensionResource;
class SkBitmap;
namespace gfx {
-class Size;
+ class Size;
}
// The views need to load their icons asynchronously but might be deleted before
-// the images have loaded. This class stays alive while the request is in
-// progress (manages its own lifetime) and keeps track of whether the view still
-// cares about the icon loading.
-// Consider abstracting out a FilePathProvider (ExtensionResource) and moving
-// back to chrome/browser/ if other subsystems want to use it.
-class ImageLoadingTracker
- : public base::RefCountedThreadSafe<ImageLoadingTracker> {
+// the images have loaded. This class encapsulates a loader class that stays
+// alive while the request is in progress (manages its own lifetime) and keeps
+// track of whether the view still cares about the icon loading.
+//
+// To use this class, have your class derive from ImageLoadingTracker::Observer,
+// and add a member variable ImageLoadingTracker tracker_. Then override
+// Observer::OnImageLoaded and call:
+// tracker_.LoadImage(resource, max_size);
+// ... and wait for OnImageLoaded to be called back on you with a pointer to the
+// SkBitmap loaded.
+//
+class ImageLoadingTracker {
public:
class Observer {
public:
// Will be called when the image with the given index has loaded.
// The |image| is owned by the tracker, so the observer should make a copy
- // if they need to access it after this call.
- virtual void OnImageLoaded(SkBitmap* image, size_t index) = 0;
+ // if they need to access it after this call. |image| can be null if valid
+ // image was not found or it failed to decode. |resource| is the
+ // ExtensionResource where the |image| came from and the |index| represents
+ // the index of the image just loaded (starts at 0 and increments every
+ // time this function is called).
+ virtual void OnImageLoaded(SkBitmap* image, ExtensionResource resource,
+ int index) = 0;
};
- ImageLoadingTracker(Observer* observer, size_t image_count)
- : observer_(observer), image_count_(image_count), posted_count_(0) {
- AddRef(); // We hold on to a reference to ourself to make sure we don't
- // get deleted until we get a response from image loading (see
- // ImageLoadingDone).
- }
+ explicit ImageLoadingTracker(Observer* observer);
+ ~ImageLoadingTracker();
- // If there are remaining images to be loaded, the observing object should
- // call this method on its destruction, so that the tracker will not attempt
- // to make any more callbacks to it.
- void StopTrackingImageLoad() {
- observer_ = NULL;
- }
-
- // Specify image resource to load. This method must be called a number of
- // times equal to the |image_count| arugment to the constructor. Calling it
- // any more or less than that is an error. If the loaded image is larger than
+ // Specify image resource to load. If the loaded image is larger than
// |max_size| it will be resized to those dimensions.
- void PostLoadImageTask(const ExtensionResource& resource,
- const gfx::Size& max_size);
+ void LoadImage(const ExtensionResource& resource,
+ gfx::Size max_size);
private:
- class LoadImageTask;
-
- friend class base::RefCountedThreadSafe<ImageLoadingTracker>;
-
- ~ImageLoadingTracker() {}
+ class ImageLoader;
- // When an image has finished loaded and scaled on the file thread, it is
- // posted back to this method on the original thread. This method then calls
- // the observer's OnImageLoaded and deletes the ImageLoadingTracker if it was
- // the last image in the list.
+ // When an image has finished loaded and been resized on the file thread, it
+ // is posted back to this method on the original thread. This method then
+ // calls the observer's OnImageLoaded and deletes the ImageLoadingTracker if
+ // it was the last image in the list.
// |image| may be null if the file failed to decode.
- void OnImageLoaded(SkBitmap* image, size_t index);
+ void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource);
// The view that is waiting for the image to load.
Observer* observer_;
- // The number of images this ImageTracker should keep track of. This is
- // decremented as each image finishes loading, and the tracker will delete
- // itself when it reaches zero.
- size_t image_count_;
+ // The number of times we've reported back.
+ int responses_;
- // The number of tasks that have been posted so far.
- size_t posted_count_;
+ // The object responsible for loading the image on the File thread.
+ scoped_refptr<ImageLoader> loader_;
DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker);
};