diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 20:08:26 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 20:08:26 +0000 |
commit | 002c177a487d8fbf4bfe020e3713229e0ee4312a (patch) | |
tree | 9ab7f6c00a388f283b7137394e5c1706832fb1e5 /chrome | |
parent | a065d7506fd6bfcfa9568f356e2c657fb2a04ec2 (diff) | |
download | chromium_src-002c177a487d8fbf4bfe020e3713229e0ee4312a.zip chromium_src-002c177a487d8fbf4bfe020e3713229e0ee4312a.tar.gz chromium_src-002c177a487d8fbf4bfe020e3713229e0ee4312a.tar.bz2 |
Fix DCHECK on download item removal, take 2.
We can't delay destroying the download item view because it has to be destoyed before the download model is destroyed. Insted we delay the execution of the command.
Review URL: http://codereview.chromium.org/173458
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24507 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/download_item_gtk.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index 25ade87..815459a 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -84,7 +84,8 @@ class DownloadShelfContextMenuGtk : public DownloadShelfContextMenu, DownloadItemGtk* download_item) : DownloadShelfContextMenu(model), download_item_(download_item), - menu_is_for_complete_download_(false) { + menu_is_for_complete_download_(false), + method_factory_(this) { } ~DownloadShelfContextMenuGtk() { @@ -113,7 +114,12 @@ class DownloadShelfContextMenuGtk : public DownloadShelfContextMenu, } virtual void ExecuteCommand(int id) { - ExecuteItemCommand(id); + // We delay executing the command so the menu will popdown before it is + // executed. This way if the command ends up destroying us the current event + // will have released its ref beforehand. + MessageLoop::current()->PostTask(FROM_HERE, + method_factory_.NewRunnableMethod( + &DownloadShelfContextMenuGtk::DoCommand, id)); } virtual void StoppedShowing() { @@ -121,6 +127,10 @@ class DownloadShelfContextMenuGtk : public DownloadShelfContextMenu, gtk_widget_queue_draw(download_item_->menu_button_); } + void DoCommand(int id) { + ExecuteItemCommand(id); + } + private: // The menu we show on Popup(). We keep a pointer to it for a couple reasons: // * we don't want to have to recreate the menu every time it's popped up. @@ -140,6 +150,8 @@ class DownloadShelfContextMenuGtk : public DownloadShelfContextMenu, static MenuCreateMaterial in_progress_download_menu[]; static MenuCreateMaterial finished_download_menu[]; + + ScopedRunnableMethodFactory<DownloadShelfContextMenuGtk> method_factory_; }; MenuCreateMaterial DownloadShelfContextMenuGtk::finished_download_menu[] = { |