summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorrpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-14 20:37:46 +0000
committerrpaquay@chromium.org <rpaquay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-14 20:37:46 +0000
commiteed8549b6de38f1b9d2398420f2c92051d21905a (patch)
treed2a4b907a3b3f14f7926f38cbf577e2a0a53a2de /chrome/browser
parent610398af2888d2fdb17b39e4589bbd1255840c5d (diff)
downloadchromium_src-eed8549b6de38f1b9d2398420f2c92051d21905a.zip
chromium_src-eed8549b6de38f1b9d2398420f2c92051d21905a.tar.gz
chromium_src-eed8549b6de38f1b9d2398420f2c92051d21905a.tar.bz2
Use ImageLoader instead of ImageLoadingTracker (part 2)
BUG=163929 Review URL: https://chromiumcodereview.appspot.com/11823062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176710 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/extension_uninstall_dialog.cc47
-rw-r--r--chrome/browser/extensions/extension_uninstall_dialog.h26
-rw-r--r--chrome/browser/extensions/image_loading_tracker.h1
3 files changed, 44 insertions, 30 deletions
diff --git a/chrome/browser/extensions/extension_uninstall_dialog.cc b/chrome/browser/extensions/extension_uninstall_dialog.cc
index 0059ef7..bfb9feb 100644
--- a/chrome/browser/extensions/extension_uninstall_dialog.cc
+++ b/chrome/browser/extensions/extension_uninstall_dialog.cc
@@ -6,6 +6,8 @@
#include "base/logging.h"
#include "base/message_loop.h"
+#include "chrome/browser/extensions/image_loader.h"
+#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
@@ -47,6 +49,7 @@ ExtensionUninstallDialog::ExtensionUninstallDialog(
: browser_(browser),
delegate_(delegate),
extension_(NULL),
+ state_(kImageIsLoading),
ui_loop_(MessageLoop::current()) {
if (browser) {
registrar_.Add(this,
@@ -66,14 +69,19 @@ void ExtensionUninstallDialog::ConfirmUninstall(
ExtensionResource image =
extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE,
ExtensionIconSet::MATCH_BIGGER);
- // Load the image asynchronously. The response will be sent to OnImageLoaded.
- tracker_.reset(new ImageLoadingTracker(this));
+
// Load the icon whose pixel size is large enough to be displayed under
// maximal supported scale factor. UI code will scale the icon down if needed.
int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
- tracker_->LoadImage(extension_, image,
- gfx::Size(pixel_size, pixel_size),
- ImageLoadingTracker::DONT_CACHE);
+
+ // Load the image asynchronously. The response will be sent to OnImageLoaded.
+ state_ = kImageIsLoading;
+ extensions::ImageLoader* loader =
+ extensions::ImageLoader::Get(browser_->profile());
+ loader->LoadImageAsync(extension_, image,
+ gfx::Size(pixel_size, pixel_size),
+ base::Bind(&ExtensionUninstallDialog::OnImageLoaded,
+ AsWeakPtr()));
}
void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
@@ -90,16 +98,17 @@ void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) {
}
}
-void ExtensionUninstallDialog::OnImageLoaded(const gfx::Image& image,
- const std::string& extension_id,
- int index) {
+void ExtensionUninstallDialog::OnImageLoaded(const gfx::Image& image) {
SetIcon(image);
- // Reset the tracker so that we can use its presence as a signal that we're
- // still waiting for the icon to load.
- tracker_.reset();
-
- Show();
+ // Show the dialog unless the browser has been closed while we were waiting
+ // for the image.
+ DCHECK(state_ == kImageIsLoading || state_ == kBrowserIsClosing);
+ if (state_ == kImageIsLoading) {
+ state_ = kDialogIsShowing;
+ DCHECK(browser_ != NULL);
+ Show();
+ }
}
void ExtensionUninstallDialog::Observe(
@@ -108,11 +117,13 @@ void ExtensionUninstallDialog::Observe(
const content::NotificationDetails& details) {
DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSING);
- browser_ = NULL;
- if (tracker_.get()) {
- // If we're waiting for the icon, stop doing so because we're not going to
- // show the dialog.
- tracker_.reset();
+ // If the browser is closed while waiting for the image, we need to send a
+ // "cancel" event here, because there will not be another opportunity to
+ // notify the delegate of the cancellation as we won't open the dialog.
+ if (state_ == kImageIsLoading) {
+ state_ = kBrowserIsClosing;
+ DCHECK(browser_ != NULL);
+ browser_ = NULL;
delegate_->ExtensionUninstallCanceled();
}
}
diff --git a/chrome/browser/extensions/extension_uninstall_dialog.h b/chrome/browser/extensions/extension_uninstall_dialog.h
index e8e96a3..83a921e 100644
--- a/chrome/browser/extensions/extension_uninstall_dialog.h
+++ b/chrome/browser/extensions/extension_uninstall_dialog.h
@@ -9,7 +9,6 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "chrome/browser/extensions/image_loading_tracker.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/gfx/image/image_skia.h"
@@ -21,9 +20,12 @@ namespace extensions {
class Extension;
}
+namespace gfx {
+class Image;
+}
+
class ExtensionUninstallDialog
- : public ImageLoadingTracker::Observer,
- public content::NotificationObserver,
+ : public content::NotificationObserver,
public base::SupportsWeakPtr<ExtensionUninstallDialog> {
public:
class Delegate {
@@ -71,10 +73,7 @@ class ExtensionUninstallDialog
// image, then we use a default icon instead.
void SetIcon(const gfx::Image& image);
- // ImageLoadingTracker::Observer:
- virtual void OnImageLoaded(const gfx::Image& image,
- const std::string& extension_id,
- int index) OVERRIDE;
+ void OnImageLoaded(const gfx::Image& image);
// content::NotificationObserver implementation.
virtual void Observe(int type,
@@ -85,11 +84,16 @@ class ExtensionUninstallDialog
// The implementations of this method are platform-specific.
virtual void Show() = 0;
- MessageLoop* ui_loop_;
+ // Keeps track of whether we're still waiting for an image to load before
+ // we show the dialog.
+ enum State {
+ kImageIsLoading, // Image is loading asynchronously.
+ kDialogIsShowing, // Dialog is shown after image is loaded.
+ kBrowserIsClosing // Browser is closed while image is still loading.
+ };
+ State state_;
- // Keeps track of extension images being loaded on the File thread for the
- // purpose of showing the dialog.
- scoped_ptr<ImageLoadingTracker> tracker_;
+ MessageLoop* ui_loop_;
content::NotificationRegistrar registrar_;
diff --git a/chrome/browser/extensions/image_loading_tracker.h b/chrome/browser/extensions/image_loading_tracker.h
index 779ee6e..4e36d26 100644
--- a/chrome/browser/extensions/image_loading_tracker.h
+++ b/chrome/browser/extensions/image_loading_tracker.h
@@ -135,7 +135,6 @@ class ImageLoadingTracker : public content::NotificationObserver {
friend class ExtensionIconManager;
friend class ExtensionInfoBar;
friend class ExtensionInfoBarGtk;
- friend class ExtensionUninstallDialog;
friend class InfobarBridge;
friend class Panel;
friend class ShellWindow;