diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-25 20:10:52 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-25 20:10:52 +0000 |
commit | 5f1ba414001730f9260db24b16ea668f916b2be5 (patch) | |
tree | 03ecd67b5473339a158df40497f118b3f5017a6f | |
parent | ad68630e2c7906b36d3f10389eb0e4b19149996b (diff) | |
download | chromium_src-5f1ba414001730f9260db24b16ea668f916b2be5.zip chromium_src-5f1ba414001730f9260db24b16ea668f916b2be5.tar.gz chromium_src-5f1ba414001730f9260db24b16ea668f916b2be5.tar.bz2 |
Get rid of browser::FindLastActiveWithProfile call in extensions uninstall dialog code. I plumbed through Browser* and observe it to make sure it doesn't go away while the icon is loading.
BUG=129187
Review URL: https://chromiumcodereview.appspot.com/10658019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143991 0039d316-1c4b-4281-b951-d872f2087c98
13 files changed, 90 insertions, 68 deletions
diff --git a/chrome/browser/extensions/extension_context_menu_model.cc b/chrome/browser/extensions/extension_context_menu_model.cc index 573bbf6..09d69df 100644 --- a/chrome/browser/extensions/extension_context_menu_model.cc +++ b/chrome/browser/extensions/extension_context_menu_model.cc @@ -126,7 +126,7 @@ void ExtensionContextMenuModel::ExecuteCommand(int command_id) { case UNINSTALL: { AddRef(); // Balanced in Accepted() and Canceled() extension_uninstall_dialog_.reset( - ExtensionUninstallDialog::Create(profile_, this)); + ExtensionUninstallDialog::Create(browser_, this)); extension_uninstall_dialog_->ConfirmUninstall(extension); break; } diff --git a/chrome/browser/extensions/extension_disabled_ui.cc b/chrome/browser/extensions/extension_disabled_ui.cc index cc3b50f..4a8191d 100644 --- a/chrome/browser/extensions/extension_disabled_ui.cc +++ b/chrome/browser/extensions/extension_disabled_ui.cc @@ -263,7 +263,7 @@ void ExtensionDisabledGlobalError::BubbleViewCancelButtonPressed( Browser* browser) { #if !defined(OS_ANDROID) uninstall_dialog_.reset( - ExtensionUninstallDialog::Create(service_->profile(), this)); + ExtensionUninstallDialog::Create(browser, this)); // Delay showing the uninstall dialog, so that this function returns // immediately, to close the bubble properly. See crbug.com/121544. MessageLoop::current()->PostTask(FROM_HERE, diff --git a/chrome/browser/extensions/extension_management_api.cc b/chrome/browser/extensions/extension_management_api.cc index 35008a2..4c933e6 100644 --- a/chrome/browser/extensions/extension_management_api.cc +++ b/chrome/browser/extensions/extension_management_api.cc @@ -475,7 +475,7 @@ bool UninstallFunction::RunImpl() { if (show_confirm_dialog) { AddRef(); // Balanced in ExtensionUninstallAccepted/Canceled extension_uninstall_dialog_.reset(ExtensionUninstallDialog::Create( - profile_, this)); + GetCurrentBrowser(), this)); extension_uninstall_dialog_->ConfirmUninstall(extension); } else { Finish(true); diff --git a/chrome/browser/extensions/extension_uninstall_dialog.cc b/chrome/browser/extensions/extension_uninstall_dialog.cc index 53909bc..1425f57e 100644 --- a/chrome/browser/extensions/extension_uninstall_dialog.cc +++ b/chrome/browser/extensions/extension_uninstall_dialog.cc @@ -6,7 +6,6 @@ #include "base/logging.h" #include "base/message_loop.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension_icon_set.h" #include "chrome/common/extensions/extension_resource.h" @@ -19,15 +18,19 @@ static const int kIconSize = 69; ExtensionUninstallDialog::ExtensionUninstallDialog( - Profile* profile, + Browser* browser, ExtensionUninstallDialog::Delegate* delegate) - : profile_(profile), + : browser_(browser), delegate_(delegate), extension_(NULL), - ui_loop_(MessageLoop::current()), - ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {} + ui_loop_(MessageLoop::current()) { + tracker_.reset(new ImageLoadingTracker(this)); + BrowserList::AddObserver(this); +} -ExtensionUninstallDialog::~ExtensionUninstallDialog() {} +ExtensionUninstallDialog::~ExtensionUninstallDialog() { + BrowserList::RemoveObserver(this); +} void ExtensionUninstallDialog::ConfirmUninstall( const extensions::Extension* extension) { @@ -38,9 +41,9 @@ void ExtensionUninstallDialog::ConfirmUninstall( extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, ExtensionIconSet::MATCH_BIGGER); // Load the image asynchronously. The response will be sent to OnImageLoaded. - tracker_.LoadImage(extension_, image, - gfx::Size(kIconSize, kIconSize), - ImageLoadingTracker::DONT_CACHE); + tracker_->LoadImage(extension_, image, + gfx::Size(kIconSize, kIconSize), + ImageLoadingTracker::DONT_CACHE); } void ExtensionUninstallDialog::SetIcon(const gfx::Image& image) { @@ -62,5 +65,22 @@ void ExtensionUninstallDialog::OnImageLoaded(const gfx::Image& image, int index) { 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(); } + +void ExtensionUninstallDialog::OnBrowserRemoved(Browser* browser) { + if (browser_ != browser) + return; + + 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(); + delegate_->ExtensionUninstallCanceled(); + } +} diff --git a/chrome/browser/extensions/extension_uninstall_dialog.h b/chrome/browser/extensions/extension_uninstall_dialog.h index 6d465c8..625557b 100644 --- a/chrome/browser/extensions/extension_uninstall_dialog.h +++ b/chrome/browser/extensions/extension_uninstall_dialog.h @@ -8,12 +8,13 @@ #include "base/basictypes.h" #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 "chrome/browser/ui/browser_list.h" #include "ui/gfx/image/image_skia.h" class MessageLoop; -class Profile; namespace extensions { class Extension; @@ -21,6 +22,7 @@ class Extension; class ExtensionUninstallDialog : public ImageLoadingTracker::Observer, + public BrowserList::Observer, public base::SupportsWeakPtr<ExtensionUninstallDialog> { public: class Delegate { @@ -36,8 +38,9 @@ class ExtensionUninstallDialog }; // Creates a platform specific implementation of ExtensionUninstallDialog. - static ExtensionUninstallDialog* Create( - Profile* profile, Delegate* delegate); + // |browser| can be NULL only for Ash when this is used with the applist + // window. + static ExtensionUninstallDialog* Create(Browser* browser, Delegate* delegate); virtual ~ExtensionUninstallDialog(); @@ -49,9 +52,9 @@ class ExtensionUninstallDialog protected: // Constructor used by the derived classes. - explicit ExtensionUninstallDialog(Profile* profile, Delegate* delegate); + ExtensionUninstallDialog(Browser* browser, Delegate* delegate); - Profile* profile_; + Browser* browser_; // The delegate we will call Accepted/Canceled on after confirmation dialog. Delegate* delegate_; @@ -72,6 +75,9 @@ class ExtensionUninstallDialog const std::string& extension_id, int index) OVERRIDE; + // BrowserList::Observer + virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; + // Displays the prompt. This should only be called after loading the icon. // The implementations of this method are platform-specific. virtual void Show() = 0; @@ -80,7 +86,7 @@ class ExtensionUninstallDialog // Keeps track of extension images being loaded on the File thread for the // purpose of showing the dialog. - ImageLoadingTracker tracker_; + scoped_ptr<ImageLoadingTracker> tracker_; DISALLOW_COPY_AND_ASSIGN(ExtensionUninstallDialog); }; diff --git a/chrome/browser/ui/browser_list.h b/chrome/browser/ui/browser_list.h index d8fbb63..095f66a 100644 --- a/chrome/browser/ui/browser_list.h +++ b/chrome/browser/ui/browser_list.h @@ -54,10 +54,10 @@ class BrowserList { class Observer { public: // Called immediately after a browser is added to the list - virtual void OnBrowserAdded(Browser* browser) = 0; + virtual void OnBrowserAdded(Browser* browser) {} // Called immediately after a browser is removed from the list - virtual void OnBrowserRemoved(Browser* browser) = 0; + virtual void OnBrowserRemoved(Browser* browser) {} // Called immediately after a browser is set active (SetLastActive) virtual void OnBrowserSetLastActive(Browser* browser) {} diff --git a/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm b/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm index 7f92bdb..beae5f3 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_action_context_menu.mm @@ -11,6 +11,7 @@ #include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" @@ -46,11 +47,11 @@ using extensions::Extension; // Also acts as the extension's UI delegate in order to display the dialog. class AsyncUninstaller : public ExtensionUninstallDialog::Delegate { public: - AsyncUninstaller(const Extension* extension, Profile* profile) + AsyncUninstaller(const Extension* extension, Browser* browser) : extension_(extension), - profile_(profile) { + profile_(browser->profile()) { extension_uninstall_dialog_.reset( - ExtensionUninstallDialog::Create(profile, this)); + ExtensionUninstallDialog::Create(browser, this)); extension_uninstall_dialog_->ConfirmUninstall(extension_); } @@ -184,7 +185,7 @@ int CurrentTabId() { break; } case kExtensionContextUninstall: { - uninstaller_.reset(new AsyncUninstaller(extension_, profile_)); + uninstaller_.reset(new AsyncUninstaller(extension_, browser)); break; } case kExtensionContextHide: { diff --git a/chrome/browser/ui/cocoa/extensions/extension_uninstall_dialog_cocoa.mm b/chrome/browser/ui/cocoa/extensions/extension_uninstall_dialog_cocoa.mm index eb89441..869f220 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_uninstall_dialog_cocoa.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_uninstall_dialog_cocoa.mm @@ -2,14 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/extensions/extension_uninstall_dialog.h" + #import <Cocoa/Cocoa.h> #include <string> #include "base/sys_string_conversions.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/extensions/extension_uninstall_dialog.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/extension.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -25,7 +25,7 @@ namespace { // so there's no way for the dialog to outlive its delegate. class ExtensionUninstallDialogCocoa : public ExtensionUninstallDialog { public: - ExtensionUninstallDialogCocoa(Profile* profile, Delegate* delegate); + ExtensionUninstallDialogCocoa(Browser* browser, Delegate* delegate); virtual ~ExtensionUninstallDialogCocoa() OVERRIDE; private: @@ -33,8 +33,8 @@ class ExtensionUninstallDialogCocoa : public ExtensionUninstallDialog { }; ExtensionUninstallDialogCocoa::ExtensionUninstallDialogCocoa( - Profile* profile, ExtensionUninstallDialog::Delegate* delegate) - : ExtensionUninstallDialog(profile, delegate) {} + Browser* browser, ExtensionUninstallDialog::Delegate* delegate) + : ExtensionUninstallDialog(browser, delegate) {} ExtensionUninstallDialogCocoa::~ExtensionUninstallDialogCocoa() {} @@ -67,6 +67,6 @@ void ExtensionUninstallDialogCocoa::Show() { // static ExtensionUninstallDialog* ExtensionUninstallDialog::Create( - Profile* profile, Delegate* delegate) { - return new ExtensionUninstallDialogCocoa(profile, delegate); + Browser* browser, Delegate* delegate) { + return new ExtensionUninstallDialogCocoa(browser, delegate); } diff --git a/chrome/browser/ui/gtk/extensions/extension_uninstall_dialog_gtk.cc b/chrome/browser/ui/gtk/extensions/extension_uninstall_dialog_gtk.cc index 69968b9..30b227c 100644 --- a/chrome/browser/ui/gtk/extensions/extension_uninstall_dialog_gtk.cc +++ b/chrome/browser/ui/gtk/extensions/extension_uninstall_dialog_gtk.cc @@ -5,12 +5,13 @@ // Currently this file is only used for the uninstall prompt. The install prompt // code is in extension_install_prompt2_gtk.cc. +#include "chrome/browser/extensions/extension_uninstall_dialog.h" + #include <gtk/gtk.h> #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/extensions/extension_uninstall_dialog.h" -#include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/gtk/browser_window_gtk.h" #include "chrome/common/extensions/extension.h" @@ -19,8 +20,6 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/gfx/gtk_util.h" -class Profile; - namespace { // Left or right margin. @@ -29,7 +28,7 @@ const int kPanelHorizMargin = 13; // GTK implementation of the uninstall dialog. class ExtensionUninstallDialogGtk : public ExtensionUninstallDialog { public: - ExtensionUninstallDialogGtk(Profile* profile, Delegate* delegate); + ExtensionUninstallDialogGtk(Browser* browser, Delegate* delegate); virtual ~ExtensionUninstallDialogGtk() OVERRIDE; private: @@ -41,18 +40,12 @@ class ExtensionUninstallDialogGtk : public ExtensionUninstallDialog { }; ExtensionUninstallDialogGtk::ExtensionUninstallDialogGtk( - Profile* profile, ExtensionUninstallDialog::Delegate* delegate) - : ExtensionUninstallDialog(profile, delegate), + Browser* browser, ExtensionUninstallDialog::Delegate* delegate) + : ExtensionUninstallDialog(browser, delegate), dialog_(NULL) {} void ExtensionUninstallDialogGtk::Show() { - Browser* browser = browser::FindLastActiveWithProfile(profile_); - if (!browser) { - delegate_->ExtensionUninstallCanceled(); - return; - } - - BrowserWindow* browser_window = browser->window(); + BrowserWindow* browser_window = browser_->window(); if (!browser_window) { delegate_->ExtensionUninstallCanceled(); return; @@ -128,6 +121,6 @@ void ExtensionUninstallDialogGtk::OnResponse( // static // Platform specific implementation of the uninstall dialog show method. ExtensionUninstallDialog* ExtensionUninstallDialog::Create( - Profile* profile, Delegate* delegate) { - return new ExtensionUninstallDialogGtk(profile, delegate); + Browser* browser, Delegate* delegate) { + return new ExtensionUninstallDialogGtk(browser, delegate); } diff --git a/chrome/browser/ui/views/ash/app_list/extension_app_item.cc b/chrome/browser/ui/views/ash/app_list/extension_app_item.cc index 942e79d..cc76737 100644 --- a/chrome/browser/ui/views/ash/app_list/extension_app_item.cc +++ b/chrome/browser/ui/views/ash/app_list/extension_app_item.cc @@ -61,7 +61,7 @@ class ExtensionUninstaller : public ExtensionUninstallDialog::Delegate { } ExtensionUninstallDialog* dialog = - ExtensionUninstallDialog::Create(profile_, this); + ExtensionUninstallDialog::Create(NULL, this); dialog->ConfirmUninstall(extension); } diff --git a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc index 355218c..e9adf67 100644 --- a/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc +++ b/chrome/browser/ui/views/extensions/extension_uninstall_dialog_view.cc @@ -2,14 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/extensions/extension_uninstall_dialog.h" + #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/extensions/extension_uninstall_dialog.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/common/extensions/extension.h" #include "grit/generated_resources.h" @@ -37,18 +36,17 @@ class ExtensionUninstallDialogDelegateView; // Returns parent window for extension uninstall dialog. // For ash, use app list window if it is visible. // For other platforms or when app list is not visible on ash, -// use browser window of given |profile|. +// use the given browser window. // Note this function could return NULL if ash app list is not visible and -// there is no browser window open for |profile|. -gfx::NativeWindow GetParent(Profile* profile) { +// there is no browser window. +gfx::NativeWindow GetParent(Browser* browser) { #if defined(USE_ASH) gfx::NativeWindow app_list = ash::Shell::GetInstance()->GetAppListWindow(); if (app_list) return app_list; #endif - Browser* browser = browser::FindLastActiveWithProfile(profile); - if (browser && browser->window()) + if (browser->window()) return browser->window()->GetNativeWindow(); return NULL; @@ -57,7 +55,7 @@ gfx::NativeWindow GetParent(Profile* profile) { // Views implementation of the uninstall dialog. class ExtensionUninstallDialogViews : public ExtensionUninstallDialog { public: - ExtensionUninstallDialogViews(Profile* profile, + ExtensionUninstallDialogViews(Browser* browser, ExtensionUninstallDialog::Delegate* delegate); virtual ~ExtensionUninstallDialogViews(); @@ -118,8 +116,8 @@ class ExtensionUninstallDialogDelegateView : public views::DialogDelegateView { }; ExtensionUninstallDialogViews::ExtensionUninstallDialogViews( - Profile* profile, ExtensionUninstallDialog::Delegate* delegate) - : ExtensionUninstallDialog(profile, delegate), + Browser* browser, ExtensionUninstallDialog::Delegate* delegate) + : ExtensionUninstallDialog(browser, delegate), view_(NULL) { } @@ -132,7 +130,7 @@ ExtensionUninstallDialogViews::~ExtensionUninstallDialogViews() { } void ExtensionUninstallDialogViews::Show() { - gfx::NativeWindow parent = GetParent(profile_); + gfx::NativeWindow parent = GetParent(browser_); if (!parent) { delegate_->ExtensionUninstallCanceled(); return; @@ -243,6 +241,6 @@ void ExtensionUninstallDialogDelegateView::Layout() { // static ExtensionUninstallDialog* ExtensionUninstallDialog::Create( - Profile* profile, Delegate* delegate) { - return new ExtensionUninstallDialogViews(profile, delegate); + Browser* browser, Delegate* delegate) { + return new ExtensionUninstallDialogViews(browser, delegate); } diff --git a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc index a379835..fd35f31 100644 --- a/chrome/browser/ui/webui/extensions/extension_settings_handler.cc +++ b/chrome/browser/ui/webui/extensions/extension_settings_handler.cc @@ -510,10 +510,10 @@ void ExtensionSettingsHandler::HandleRequestExtensionsData( results.SetBoolean("developerMode", false); } else { results.SetBoolean("managedMode", false); - Profile* profile = Profile::FromWebUI(web_ui()); - bool developer_mode = - profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); - results.SetBoolean("developerMode", developer_mode); + Profile* profile = Profile::FromWebUI(web_ui()); + bool developer_mode = + profile->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode); + results.SetBoolean("developerMode", developer_mode); } bool load_unpacked_disabled = @@ -863,8 +863,10 @@ ExtensionUninstallDialog* ExtensionSettingsHandler::GetExtensionUninstallDialog() { #if !defined(OS_ANDROID) if (!extension_uninstall_dialog_.get()) { + Browser* browser = browser::FindBrowserWithWebContents( + web_ui()->GetWebContents()); extension_uninstall_dialog_.reset( - ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui()), this)); + ExtensionUninstallDialog::Create(browser, this)); } return extension_uninstall_dialog_.get(); #else diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc index 58a3aae..92e6b6f 100644 --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc @@ -975,8 +975,10 @@ void AppLauncherHandler::InstallUIAbort(bool user_initiated) { ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { if (!extension_uninstall_dialog_.get()) { + Browser* browser = browser::FindBrowserWithWebContents( + web_ui()->GetWebContents()); extension_uninstall_dialog_.reset( - ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui()), this)); + ExtensionUninstallDialog::Create(browser, this)); } return extension_uninstall_dialog_.get(); } |