summaryrefslogtreecommitdiffstats
path: root/ui/message_center
diff options
context:
space:
mode:
authormukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-28 14:33:08 +0000
committermukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-28 14:33:08 +0000
commit94822e5db882cac84cf24be8bda518f2d7fcf3cd (patch)
tree7c284ec7ab1fc68274c0b40a08b7f486b278a418 /ui/message_center
parent670464149140f9a4635392bcdd5df33527900f31 (diff)
downloadchromium_src-94822e5db882cac84cf24be8bda518f2d7fcf3cd.zip
chromium_src-94822e5db882cac84cf24be8bda518f2d7fcf3cd.tar.gz
chromium_src-94822e5db882cac84cf24be8bda518f2d7fcf3cd.tar.bz2
Converts MessagePopupCollection into a long-lived object.
This improves the behavior since there were several scenarios where observer methods would cause re-entrancy into the destructor of MessagePopupCollection. Since it observes MessageCenter, it knows when it should show popups and when it shouldn't. This CL is based on dewittj's crrev.com/114553002 with a fix for some tests in linux-aura and win because of screen_aura. BUG=327363 R=dewittj@chromium.org, stevenjb@chromium.org Review URL: https://codereview.chromium.org/180513002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254101 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center')
-rw-r--r--ui/message_center/views/message_popup_collection.cc46
-rw-r--r--ui/message_center/views/message_popup_collection.h5
2 files changed, 28 insertions, 23 deletions
diff --git a/ui/message_center/views/message_popup_collection.cc b/ui/message_center/views/message_popup_collection.cc
index bc2da0c..2039d49 100644
--- a/ui/message_center/views/message_popup_collection.cc
+++ b/ui/message_center/views/message_popup_collection.cc
@@ -65,6 +65,8 @@ MessagePopupCollection::MessagePopupCollection(gfx::NativeView parent,
: parent_(parent),
message_center_(message_center),
tray_(tray),
+ display_id_(gfx::Display::kInvalidDisplayID),
+ screen_(NULL),
defer_counter_(0),
latest_toast_entered_(NULL),
user_is_closing_toasts_by_clicking_(false),
@@ -74,34 +76,13 @@ MessagePopupCollection::MessagePopupCollection(gfx::NativeView parent,
DCHECK(message_center_);
defer_timer_.reset(new base::OneShotTimer<MessagePopupCollection>);
message_center_->AddObserver(this);
- gfx::Screen* screen = NULL;
- gfx::Display display;
- if (!parent_) {
- // On Win+Aura, we don't have a parent since the popups currently show up
- // on the Windows desktop, not in the Aura/Ash desktop. This code will
- // display the popups on the primary display.
- screen = gfx::Screen::GetNativeScreen();
- display = screen->GetPrimaryDisplay();
- } else {
- screen = gfx::Screen::GetScreenFor(parent_);
- display = screen->GetDisplayNearestWindow(parent_);
- }
- screen->AddObserver(this);
-
- display_id_ = display.id();
- work_area_ = display.work_area();
- ComputePopupAlignment(work_area_, display.bounds());
-
- // We should not update before work area and popup alignment are computed.
- DoUpdateIfPossible();
}
MessagePopupCollection::~MessagePopupCollection() {
weak_factory_.InvalidateWeakPtrs();
- gfx::Screen* screen = parent_ ?
- gfx::Screen::GetScreenFor(parent_) : gfx::Screen::GetNativeScreen();
- screen->RemoveObserver(this);
+ if (screen_)
+ screen_->RemoveObserver(this);
message_center_->RemoveObserver(this);
CloseAllWidgets();
@@ -525,6 +506,25 @@ void MessagePopupCollection::DecrementDeferCounter() {
// deferred tasks are even able to run)
// Then, see if there is vacant space for new toasts.
void MessagePopupCollection::DoUpdateIfPossible() {
+ if (!screen_) {
+ gfx::Display display;
+ if (!parent_) {
+ // On Win+Aura, we don't have a parent since the popups currently show up
+ // on the Windows desktop, not in the Aura/Ash desktop. This code will
+ // display the popups on the primary display.
+ screen_ = gfx::Screen::GetNativeScreen();
+ display = screen_->GetPrimaryDisplay();
+ } else {
+ screen_ = gfx::Screen::GetScreenFor(parent_);
+ display = screen_->GetDisplayNearestWindow(parent_);
+ }
+ screen_->AddObserver(this);
+
+ display_id_ = display.id();
+ work_area_ = display.work_area();
+ ComputePopupAlignment(work_area_, display.bounds());
+ }
+
if (defer_counter_ > 0)
return;
diff --git a/ui/message_center/views/message_popup_collection.h b/ui/message_center/views/message_popup_collection.h
index 6586b41..907274e 100644
--- a/ui/message_center/views/message_popup_collection.h
+++ b/ui/message_center/views/message_popup_collection.h
@@ -35,6 +35,10 @@ class WebNotificationTrayTest;
FORWARD_DECLARE_TEST(WebNotificationTrayTest, ManyPopupNotifications);
}
+namespace gfx {
+class Screen;
+}
+
namespace message_center {
namespace test {
class MessagePopupCollectionTest;
@@ -184,6 +188,7 @@ class MESSAGE_CENTER_EXPORT MessagePopupCollection
Toasts toasts_;
gfx::Rect work_area_;
int64 display_id_;
+ gfx::Screen* screen_;
// Specifies which corner of the screen popups should show up. This should
// ideally be the same corner the notification area (systray) is at.