diff options
author | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 19:11:36 +0000 |
---|---|---|
committer | andybons@chromium.org <andybons@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-25 19:11:36 +0000 |
commit | 91968bc1e60c8ee2a3cab902c7f8246565974850 (patch) | |
tree | 3ed12c59c30b7abeeca54f6b089b0babb55d0327 | |
parent | e131cf56c776248bb22d234ad806aafb64869e5a (diff) | |
download | chromium_src-91968bc1e60c8ee2a3cab902c7f8246565974850.zip chromium_src-91968bc1e60c8ee2a3cab902c7f8246565974850.tar.gz chromium_src-91968bc1e60c8ee2a3cab902c7f8246565974850.tar.bz2 |
[Mac] Clean up the icon loading code for extensions after finnur's change (r42471) which made the interface a lot cleaner.
TEST=none
BUG=38521
Review URL: http://codereview.chromium.org/1251004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42648 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 17 insertions, 54 deletions
diff --git a/chrome/browser/cocoa/extensions/browser_action_button.h b/chrome/browser/cocoa/extensions/browser_action_button.h index 3470f3e..caf03a1 100644 --- a/chrome/browser/cocoa/extensions/browser_action_button.h +++ b/chrome/browser/cocoa/extensions/browser_action_button.h @@ -24,10 +24,14 @@ extern const CGFloat kBrowserActionWidth; @interface BrowserActionButton : NSButton { @private + // Bridge to proxy Chrome notifications to the Obj-C class as well as load the + // extension's icon. scoped_ptr<ExtensionImageTrackerBridge> imageLoadingBridge_; + // The default icon of the Button. scoped_nsobject<NSImage> defaultIcon_; + // The icon specific to the active tab. scoped_nsobject<NSImage> tabSpecificIcon_; // The extension for this button. Weak. diff --git a/chrome/browser/cocoa/extensions/extension_action_context_menu.h b/chrome/browser/cocoa/extensions/extension_action_context_menu.h index c43ba37..2d3f698 100644 --- a/chrome/browser/cocoa/extensions/extension_action_context_menu.h +++ b/chrome/browser/cocoa/extensions/extension_action_context_menu.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_COCOA_EXTENSIONS_EXTENSION_ACTION_CONTEXT_MENU_H_ #define CHROME_BROWSER_COCOA_EXTENSIONS_EXTENSION_ACTION_CONTEXT_MENU_H_ -#include "base/ref_counted.h" +#include "base/scoped_ptr.h" #import <Cocoa/Cocoa.h> @@ -25,7 +25,7 @@ class Profile; // Used to load the extension icon asynchronously on the I/O thread then show // the uninstall confirmation dialog. - scoped_refptr<AsyncUninstaller> uninstaller_; + scoped_ptr<AsyncUninstaller> uninstaller_; } // Initializes and returns a context menu for the given extension and profile. diff --git a/chrome/browser/cocoa/extensions/extension_action_context_menu.mm b/chrome/browser/cocoa/extensions/extension_action_context_menu.mm index f055e33..eca2e8e 100644 --- a/chrome/browser/cocoa/extensions/extension_action_context_menu.mm +++ b/chrome/browser/cocoa/extensions/extension_action_context_menu.mm @@ -19,69 +19,32 @@ // A class that loads the extension icon on the I/O thread before showing the // confirmation dialog to uninstall the given extension. // Also acts as the extension's UI delegate in order to display the dialog. -class AsyncUninstaller : public base::RefCountedThreadSafe<AsyncUninstaller>, - public ExtensionInstallUI::Delegate { +class AsyncUninstaller : public ExtensionInstallUI::Delegate { public: - AsyncUninstaller(Extension* extension) : extension_(extension) {} - - // Load the uninstall icon then show the confirmation dialog when finished. - void LoadExtensionIconThenConfirmUninstall() { - ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, - NewRunnableMethod(this, &AsyncUninstaller::LoadIconOnFileThread, - &uninstall_icon_)); + AsyncUninstaller(Extension* extension, Profile* profile) + : extension_(extension), + profile_(profile) { + install_ui_.reset(new ExtensionInstallUI(profile)); + install_ui_->ConfirmUninstall(this, extension_); } - void Cancel() { - uninstall_icon_.reset(); - extension_ = NULL; - } + ~AsyncUninstaller() {} // Overridden by ExtensionInstallUI::Delegate. virtual void InstallUIProceed(bool create_shortcut) { DCHECK(!create_shortcut); - Browser* browser = BrowserList::GetLastActive(); - // GetLastActive() returns NULL during testing. - if (!browser) - return; - browser->profile()->GetExtensionsService()-> + profile_->GetExtensionsService()-> UninstallExtension(extension_->id(), false); } virtual void InstallUIAbort() {} private: - friend class base::RefCountedThreadSafe<AsyncUninstaller>; - ~AsyncUninstaller() {} - - void LoadIconOnFileThread(scoped_ptr<SkBitmap>* uninstall_icon) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); - Extension::DecodeIcon(extension_, Extension::EXTENSION_ICON_LARGE, - uninstall_icon); - ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, - NewRunnableMethod(this, &AsyncUninstaller::ShowConfirmationDialog, - uninstall_icon)); - } - - void ShowConfirmationDialog(scoped_ptr<SkBitmap>* uninstall_icon) { - DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); - // If |extension_| is NULL, then the action was cancelled. Bail. - if (!extension_) - return; - - Browser* browser = BrowserList::GetLastActive(); - // GetLastActive() returns NULL during testing. - if (!browser) - return; - - install_ui_.reset(new ExtensionInstallUI(browser->profile())); - install_ui_->ConfirmUninstall(this, extension_); - } - // The extension that we're loading the icon for. Weak. Extension* extension_; - // The uninstall icon shown by the confirmation dialog. - scoped_ptr<SkBitmap> uninstall_icon_; + // The current profile. Weak. + Profile* profile_; scoped_ptr<ExtensionInstallUI> install_ui_; @@ -177,11 +140,7 @@ enum { break; } case kExtensionContextUninstall: { - if (uninstaller_.get()) - uninstaller_->Cancel(); - - uninstaller_ = new AsyncUninstaller(extension_); - uninstaller_->LoadExtensionIconThenConfirmUninstall(); + uninstaller_.reset(new AsyncUninstaller(extension_, profile_)); break; } case kExtensionContextManage: { |