diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 01:01:01 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 01:01:01 +0000 |
commit | ebca346eb646c5b714f4efb4f383cb538780f1ae (patch) | |
tree | 08c38802387f891384916e5ee22e718965781718 | |
parent | 1e9b956212e328f18c12d406fd0f867e2bb13619 (diff) | |
download | chromium_src-ebca346eb646c5b714f4efb4f383cb538780f1ae.zip chromium_src-ebca346eb646c5b714f4efb4f383cb538780f1ae.tar.gz chromium_src-ebca346eb646c5b714f4efb4f383cb538780f1ae.tar.bz2 |
Try to add more sanity checking to help track down a crash.
BUG=20511
TEST=none
Review URL: http://codereview.chromium.org/342112
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30908 0039d316-1c4b-4281-b951-d872f2087c98
6 files changed, 46 insertions, 19 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index 2e7c7ec..f9223b4 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -511,7 +511,7 @@ AutocompleteProvider::~AutocompleteProvider() { void AutocompleteProvider::SetProfile(Profile* profile) { DCHECK(profile); - Stop(); // It makes no sense to continue running a query from an old profile. + DCHECK(done_); // The controller should have already stopped us. profile_ = profile; } @@ -688,6 +688,7 @@ AutocompleteController::~AutocompleteController() { } void AutocompleteController::SetProfile(Profile* profile) { + Stop(true); for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) (*i)->SetProfile(profile); input_.Clear(); // Ensure we don't try to do a "minimal_changes" query on a @@ -756,7 +757,7 @@ void AutocompleteController::Stop(bool clear_result) { updated_latest_result_ = false; delay_interval_has_passed_ = false; done_ = true; - if (clear_result) { + if (clear_result && !result_.empty()) { result_.Reset(); NotificationService::current()->Notify( NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED, diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc index 8b0c9d1..c3147c1 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_model.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc @@ -175,7 +175,12 @@ GURL AutocompletePopupModel::URLsForCurrentSelection( // If there are no results, the popup should be closed (so we should have // failed the CHECK above), and URLsForDefaultMatch() should have been // called instead. - CHECK(!result->empty()); + if (result->empty()) { + // We're going to checkfail, but first see whether + // controller_->latest_result() is actually in sync with |result|. + CHECK(controller_->latest_result().empty()); + CHECK(false); + } CHECK(selected_line_ < result->size()); match = result->begin() + selected_line_; } diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc index 97fdfdc..419e0bb 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc @@ -591,7 +591,8 @@ AutocompletePopupContentsView::AutocompletePopupContentsView( edit_view_(edit_view), bubble_positioner_(bubble_positioner), result_font_(font.DeriveFont(kEditFontAdjust)), - ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)), + is_open_(false) { // The following little dance is required because set_border() requires a // pointer to a non-const object. BubbleBorder* bubble_border = new BubbleBorder; @@ -619,7 +620,9 @@ gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const { // AutocompletePopupContentsView, AutocompletePopupView overrides: bool AutocompletePopupContentsView::IsOpen() const { - return popup_->IsOpen(); + const bool is_open = popup_->IsOpen(); + CHECK(is_open == is_open_); + return is_open; } void AutocompletePopupContentsView::InvalidateLine(size_t line) { @@ -633,6 +636,7 @@ void AutocompletePopupContentsView::UpdatePopupAppearance() { size_animation_.Stop(); popup_->Hide(); } + is_open_ = false; return; } @@ -681,6 +685,7 @@ void AutocompletePopupContentsView::UpdatePopupAppearance() { start_bounds_ = target_bounds_; popup_->Show(); } + is_open_ = true; SchedulePaint(); } @@ -737,7 +742,9 @@ void AutocompletePopupContentsView::SetSelectedLine(size_t index, void AutocompletePopupContentsView::AnimationProgressed( const Animation* animation) { - popup_->Show(); + // We should only be running the animation when the popup is already visible. + CHECK(IsOpen()); + popup_->Show(); // Adjusts bounds. } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h index d5f710e..056e653 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h @@ -132,6 +132,8 @@ class AutocompletePopupContentsView : public views::View, gfx::Rect start_bounds_; gfx::Rect target_bounds_; + bool is_open_; // Used only for sanity-checking. + DISALLOW_COPY_AND_ASSIGN(AutocompletePopupContentsView); }; diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_win.cc b/chrome/browser/views/autocomplete/autocomplete_popup_win.cc index 3834a861b..30721d7 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_win.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_win.cc @@ -15,7 +15,8 @@ AutocompletePopupWin::AutocompletePopupWin( AutocompletePopupContentsView* contents) - : contents_(contents) { + : contents_(contents), + is_open_(false) { set_delete_on_destroy(false); set_window_style(WS_POPUP | WS_CLIPCHILDREN); set_window_ex_style(WS_EX_TOOLWINDOW | WS_EX_LAYERED); @@ -24,6 +25,19 @@ AutocompletePopupWin::AutocompletePopupWin( AutocompletePopupWin::~AutocompletePopupWin() { } +void AutocompletePopupWin::Show() { + // Move the popup to the place appropriate for the window's current position - + // it may have been moved since it was last shown. + SetBounds(contents_->GetPopupBounds()); + WidgetWin::Show(); + is_open_ = true; +} + +void AutocompletePopupWin::Hide() { + WidgetWin::Hide(); + is_open_ = false; +} + void AutocompletePopupWin::Init(AutocompleteEditView* edit_view, views::View* contents) { // Create the popup @@ -41,18 +55,13 @@ void AutocompletePopupWin::Init(AutocompleteEditView* edit_view, HWND ime_window = ImmGetDefaultIMEWnd(edit_view->GetNativeView()); SetWindowPos(ime_window ? ime_window : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW); -} - -void AutocompletePopupWin::Show() { - // Move the popup to the place appropriate for the window's current position - - // it may have been moved since it was last shown. - SetBounds(contents_->GetPopupBounds()); - if (!IsVisible()) - WidgetWin::Show(); + is_open_ = true; } bool AutocompletePopupWin::IsOpen() const { - return IsCreated() && IsVisible(); + const bool is_open = IsCreated() && IsVisible(); + CHECK(is_open == is_open_); + return is_open; } bool AutocompletePopupWin::IsCreated() const { diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_win.h b/chrome/browser/views/autocomplete/autocomplete_popup_win.h index 8e33f56..6290b4d 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_win.h +++ b/chrome/browser/views/autocomplete/autocomplete_popup_win.h @@ -15,13 +15,14 @@ class AutocompletePopupWin : public views::WidgetWin { explicit AutocompletePopupWin(AutocompletePopupContentsView* contents); virtual ~AutocompletePopupWin(); + // Overridden from WidgetWin: + virtual void Show(); + virtual void Hide(); + // Creates the popup and shows it for the first time. |edit_view| is the edit // that created us. void Init(AutocompleteEditView* edit_view, views::View* contents); - // Shows the popup and moves it to the right position. - void Show(); - // Returns true if the popup is open. bool IsOpen() const; @@ -37,6 +38,8 @@ class AutocompletePopupWin : public views::WidgetWin { private: AutocompletePopupContentsView* contents_; + bool is_open_; // Used only for sanity-checking. + DISALLOW_COPY_AND_ASSIGN(AutocompletePopupWin); }; |