From 9fe90fe465e046a219411b192d8b08086faae39c Mon Sep 17 00:00:00 2001 From: "erg@chromium.org" Date: Tue, 17 Apr 2012 00:57:30 +0000 Subject: GTK: Stop listening to gtk signals in the omnibox before destroying the model. BUG=123530 TEST=none Review URL: http://codereview.chromium.org/10103012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132498 0039d316-1c4b-4281-b951-d872f2087c98 --- .../ui/gtk/omnibox/omnibox_popup_view_gtk.cc | 24 ++++++++++++++-------- .../ui/gtk/omnibox/omnibox_popup_view_gtk.h | 5 +++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc b/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc index fcdf76c..82824a2 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc +++ b/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.cc @@ -31,6 +31,7 @@ #include "ui/base/gtk/gtk_compat.h" #include "ui/base/gtk/gtk_hig_constants.h" #include "ui/base/gtk/gtk_screen_util.h" +#include "ui/base/gtk/gtk_signal_registrar.h" #include "ui/base/gtk/gtk_windowing.h" #include "ui/gfx/color_utils.h" #include "ui/gfx/font.h" @@ -276,7 +277,8 @@ OmniboxPopupViewGtk::OmniboxPopupViewGtk(const gfx::Font& font, OmniboxView* omnibox_view, AutocompleteEditModel* edit_model, GtkWidget* location_bar) - : model_(new AutocompletePopupModel(this, edit_model)), + : signal_registrar_(new ui::GtkSignalRegistrar), + model_(new AutocompletePopupModel(this, edit_model)), omnibox_view_(omnibox_view), location_bar_(location_bar), window_(gtk_window_new(GTK_WINDOW_POPUP)), @@ -306,14 +308,14 @@ OmniboxPopupViewGtk::OmniboxPopupViewGtk(const gfx::Font& font, GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); - g_signal_connect(window_, "motion-notify-event", - G_CALLBACK(HandleMotionThunk), this); - g_signal_connect(window_, "button-press-event", - G_CALLBACK(HandleButtonPressThunk), this); - g_signal_connect(window_, "button-release-event", - G_CALLBACK(HandleButtonReleaseThunk), this); - g_signal_connect(window_, "expose-event", - G_CALLBACK(HandleExposeThunk), this); + signal_registrar_->Connect(window_, "motion-notify-event", + G_CALLBACK(HandleMotionThunk), this); + signal_registrar_->Connect(window_, "button-press-event", + G_CALLBACK(HandleButtonPressThunk), this); + signal_registrar_->Connect(window_, "button-release-event", + G_CALLBACK(HandleButtonReleaseThunk), this); + signal_registrar_->Connect(window_, "expose-event", + G_CALLBACK(HandleExposeThunk), this); registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, @@ -334,6 +336,10 @@ OmniboxPopupViewGtk::OmniboxPopupViewGtk(const gfx::Font& font, } OmniboxPopupViewGtk::~OmniboxPopupViewGtk() { + // Stop listening to our signals before we destroy the model. I suspect that + // we can race window destruction, otherwise. + signal_registrar_.reset(); + // Explicitly destroy our model here, before we destroy our GTK widgets. // This is because the model destructor can call back into us, and we need // to make sure everything is still valid when it does. diff --git a/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.h b/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.h index e23b2fc..bd0f8c2 100644 --- a/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.h +++ b/chrome/browser/ui/gtk/omnibox/omnibox_popup_view_gtk.h @@ -32,6 +32,10 @@ namespace gfx { class Image; } +namespace ui { +class GtkSignalRegistrar; +} + class OmniboxPopupViewGtk : public AutocompletePopupView, public content::NotificationObserver { public: @@ -101,6 +105,7 @@ class OmniboxPopupViewGtk : public AutocompletePopupView, CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleExpose, GdkEventExpose*); + scoped_ptr signal_registrar_; scoped_ptr model_; OmniboxView* omnibox_view_; GtkWidget* location_bar_; -- cgit v1.1