diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-09 00:11:56 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-09 00:11:56 +0000 |
commit | f6afff3feb06da707b9c2bc42383ede292929476 (patch) | |
tree | 3a426d970934acf290985c2d20efa2c1b302293b | |
parent | 3f4f881f99238038d0cdbec4929c0b6c4ea538e6 (diff) | |
download | chromium_src-f6afff3feb06da707b9c2bc42383ede292929476.zip chromium_src-f6afff3feb06da707b9c2bc42383ede292929476.tar.gz chromium_src-f6afff3feb06da707b9c2bc42383ede292929476.tar.bz2 |
Delete all RenderViewHost in BalloonViewImpl on exit.
Not deleting them was causing assertion failure. See the bug description for details.
* Added TestCleanExit
* Removed empty test that was checked in by my mistake.
BUG=40810
TEST=Added NotificationTest.TestCleanExit
Review URL: http://codereview.chromium.org/1600018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44028 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 51 insertions, 7 deletions
diff --git a/chrome/browser/chromeos/notifications/balloon_collection_impl.cc b/chrome/browser/chromeos/notifications/balloon_collection_impl.cc index b06edf1..732edbc 100644 --- a/chrome/browser/chromeos/notifications/balloon_collection_impl.cc +++ b/chrome/browser/chromeos/notifications/balloon_collection_impl.cc @@ -8,11 +8,13 @@ #include "base/logging.h" #include "base/stl_util-inl.h" +#include "chrome/browser/browser_list.h" #include "chrome/browser/chromeos/notifications/balloon_view.h" #include "chrome/browser/chromeos/notifications/notification_panel.h" #include "chrome/browser/notifications/balloon.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/window_sizer.h" +#include "chrome/common/notification_service.h" #include "gfx/rect.h" #include "gfx/size.h" @@ -46,14 +48,12 @@ namespace chromeos { BalloonCollectionImpl::BalloonCollectionImpl() : notification_ui_(new NotificationPanel()) { + registrar_.Add(this, NotificationType::BROWSER_CLOSED, + NotificationService::AllSources()); } BalloonCollectionImpl::~BalloonCollectionImpl() { - // We need to remove the panel first because deleting - // views that are not owned by parent will not remove - // themselves from the parent. - notification_ui_.reset(); - STLDeleteElements(&balloons_); + Shutdown(); } void BalloonCollectionImpl::Add(const Notification& notification, @@ -134,6 +134,27 @@ void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) { space_change_listener_->OnBalloonSpaceChanged(); } +void BalloonCollectionImpl::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::BROWSER_CLOSED); + if (BrowserList::GetLastActive() == NULL) { + // When exitting, we need to shutdown all renderers in + // BalloonViewImpl before IO thread gets deleted in the + // BrowserProcessImpl's destructor. See http://crbug.com/40810 + // for details. + Shutdown(); + } +} + +void BalloonCollectionImpl::Shutdown() { + // We need to remove the panel first because deleting + // views that are not owned by parent will not remove + // themselves from the parent. + notification_ui_.reset(); + STLDeleteElements(&balloons_); +} + Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification, Profile* profile) { Balloon* new_balloon = new Balloon(notification, profile, this); diff --git a/chrome/browser/chromeos/notifications/balloon_collection_impl.h b/chrome/browser/chromeos/notifications/balloon_collection_impl.h index 4a071b9..a7c2051 100644 --- a/chrome/browser/chromeos/notifications/balloon_collection_impl.h +++ b/chrome/browser/chromeos/notifications/balloon_collection_impl.h @@ -10,6 +10,7 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "chrome/browser/notifications/balloon_collection.h" +#include "chrome/common/notification_registrar.h" #include "gfx/point.h" #include "gfx/rect.h" @@ -23,7 +24,8 @@ namespace chromeos { // shown in the chromeos notification panel. Unlike other platforms, // chromeos shows the all notifications in the notification panel, and // this class does not manage the location of balloons. -class BalloonCollectionImpl : public BalloonCollection { +class BalloonCollectionImpl : public BalloonCollection, + public NotificationObserver { public: // An interface to display balloons on the screen. // This is used for unit tests to inject a mock ui implementation. @@ -55,6 +57,11 @@ class BalloonCollectionImpl : public BalloonCollection { virtual void OnBalloonClosed(Balloon* source); virtual const Balloons& GetActiveBalloons() { return balloons_; } + // NotificationObserver overrides: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + // Adds new system notification. // |sticky| is used to indicate that the notification // is sticky and cannot be dismissed by a user. |controls| turns on/off @@ -84,6 +91,9 @@ class BalloonCollectionImpl : public BalloonCollection { Profile* profile); private: + // Shutdown the notification ui. + void Shutdown(); + // The number of balloons being displayed. int count() const { return balloons_.size(); } @@ -94,6 +104,8 @@ class BalloonCollectionImpl : public BalloonCollection { scoped_ptr<NotificationUI> notification_ui_; + NotificationRegistrar registrar_; + DISALLOW_COPY_AND_ASSIGN(BalloonCollectionImpl); }; diff --git a/chrome/browser/chromeos/notifications/notification_browsertest.cc b/chrome/browser/chromeos/notifications/notification_browsertest.cc index d548742..d90d1fd 100644 --- a/chrome/browser/chromeos/notifications/notification_browsertest.cc +++ b/chrome/browser/chromeos/notifications/notification_browsertest.cc @@ -338,7 +338,18 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition2) { ui_test_utils::RunAllPendingInMessageLoop(); } -IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition3) { +IN_PROC_BROWSER_TEST_F(NotificationTest, TestCleanupOnExit) { + BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); + NotificationPanel* panel = GetNotificationPanel(); + NotificationPanelTester* tester = panel->GetTester(); + + // Don't become stale. + tester->SetStaleTimeout(100000); + + collection->Add(NewMockNotification("1"), browser()->profile()); + EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); + WaitForPanelState(tester, PanelController::EXPANDED); + // end without closing. } } // namespace chromeos |