summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc2
-rw-r--r--chrome/browser/chromeos/notifications/balloon_collection_impl.cc64
-rw-r--r--chrome/browser/chromeos/notifications/balloon_collection_impl.h19
-rw-r--r--chrome/browser/chromeos/notifications/balloon_view.cc4
-rw-r--r--chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc25
-rw-r--r--chrome/browser/chromeos/notifications/desktop_notifications_unittest.h5
-rw-r--r--chrome/browser/chromeos/notifications/notification_browsertest.cc46
-rw-r--r--chrome/browser/chromeos/notifications/notification_panel.cc6
-rw-r--r--chrome/browser/chromeos/notifications/system_notification.cc4
-rw-r--r--chrome/browser/cocoa/notifications/balloon_controller.mm1
-rw-r--r--chrome/browser/cocoa/notifications/balloon_controller_unittest.mm3
-rw-r--r--chrome/browser/gtk/notifications/balloon_view_gtk.cc1
-rw-r--r--chrome/browser/notifications/balloon_collection.cc59
-rw-r--r--chrome/browser/notifications/balloon_collection.h10
-rw-r--r--chrome/browser/notifications/balloon_collection_base.cc76
-rw-r--r--chrome/browser/notifications/balloon_collection_base.h62
-rw-r--r--chrome/browser/notifications/balloon_collection_impl.h26
-rw-r--r--chrome/browser/notifications/balloon_collection_linux.cc5
-rw-r--r--chrome/browser/notifications/balloon_collection_win.cc5
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc45
-rw-r--r--chrome/browser/notifications/desktop_notification_service.h11
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.cc22
-rw-r--r--chrome/browser/notifications/desktop_notifications_unittest.h7
-rw-r--r--chrome/browser/notifications/notification.cc4
-rw-r--r--chrome/browser/notifications/notification.h4
-rw-r--r--chrome/browser/notifications/notification_options_menu_model.cc1
-rw-r--r--chrome/browser/notifications/notification_test_util.h23
-rw-r--r--chrome/browser/notifications/notification_ui_manager.cc27
-rw-r--r--chrome/browser/notifications/notification_ui_manager.h11
-rw-r--r--chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc5
-rw-r--r--chrome/browser/task_manager/task_manager_browsertest.cc5
-rw-r--r--chrome/browser/ui/views/extensions/extension_view.cc2
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc2
-rw-r--r--chrome/browser/ui/views/notifications/balloon_view.cc1
-rw-r--r--chrome/chrome_browser.gypi2
35 files changed, 233 insertions, 362 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index f56488b..18c57e4 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -4277,7 +4277,7 @@ void TestingAutomationProvider::CloseNotification(
// This will delete itself when finished.
new OnNotificationBalloonCountObserver(
this, reply_message, collection, balloon_count - 1);
- manager->CancelById(balloons[index]->notification().notification_id());
+ manager->Cancel(balloons[index]->notification());
}
// Refer to WaitForNotificationCount() in chrome/test/pyautolib/pyauto.py for
diff --git a/chrome/browser/chromeos/notifications/balloon_collection_impl.cc b/chrome/browser/chromeos/notifications/balloon_collection_impl.cc
index 14da2d6..56a3d1c 100644
--- a/chrome/browser/chromeos/notifications/balloon_collection_impl.cc
+++ b/chrome/browser/chromeos/notifications/balloon_collection_impl.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#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"
@@ -23,6 +24,17 @@ namespace {
const int kVerticalEdgeMargin = 5;
const int kHorizontalEdgeMargin = 5;
+class NotificationMatcher {
+ public:
+ explicit NotificationMatcher(const Notification& notification)
+ : notification_(notification) {}
+ bool operator()(const Balloon* b) const {
+ return notification_.IsSame(b->notification());
+ }
+ private:
+ Notification notification_;
+};
+
} // namespace
namespace chromeos {
@@ -40,7 +52,7 @@ BalloonCollectionImpl::~BalloonCollectionImpl() {
void BalloonCollectionImpl::Add(const Notification& notification,
Profile* profile) {
Balloon* new_balloon = MakeBalloon(notification, profile);
- base_.Add(new_balloon);
+ balloons_.push_back(new_balloon);
new_balloon->Show();
notification_ui_->Add(new_balloon);
@@ -53,13 +65,13 @@ bool BalloonCollectionImpl::AddDOMUIMessageCallback(
const Notification& notification,
const std::string& message,
MessageCallback* callback) {
- Balloon* balloon = FindBalloon(notification);
- if (!balloon) {
+ Balloons::iterator iter = FindBalloon(notification);
+ if (iter == balloons_.end()) {
delete callback;
return false;
}
BalloonViewHost* host =
- static_cast<BalloonViewHost*>(balloon->view()->GetHost());
+ static_cast<BalloonViewHost*>((*iter)->view()->GetHost());
return host->AddDOMUIMessageCallback(message, callback);
}
@@ -68,11 +80,10 @@ void BalloonCollectionImpl::AddSystemNotification(
Profile* profile,
bool sticky,
bool control) {
-
Balloon* new_balloon = new Balloon(notification, profile, this);
new_balloon->set_view(
new chromeos::BalloonViewImpl(sticky, control, true));
- base_.Add(new_balloon);
+ balloons_.push_back(new_balloon);
new_balloon->Show();
notification_ui_->Add(new_balloon);
@@ -83,9 +94,10 @@ void BalloonCollectionImpl::AddSystemNotification(
bool BalloonCollectionImpl::UpdateNotification(
const Notification& notification) {
- Balloon* balloon = FindBalloon(notification);
- if (!balloon)
+ Balloons::iterator iter = FindBalloon(notification);
+ if (iter == balloons_.end())
return false;
+ Balloon* balloon = *iter;
balloon->Update(notification);
notification_ui_->Update(balloon);
return true;
@@ -93,9 +105,10 @@ bool BalloonCollectionImpl::UpdateNotification(
bool BalloonCollectionImpl::UpdateAndShowNotification(
const Notification& notification) {
- Balloon* balloon = FindBalloon(notification);
- if (!balloon)
+ Balloons::iterator iter = FindBalloon(notification);
+ if (iter == balloons_.end())
return false;
+ Balloon* balloon = *iter;
balloon->Update(notification);
bool updated = notification_ui_->Update(balloon);
DCHECK(updated);
@@ -103,12 +116,15 @@ bool BalloonCollectionImpl::UpdateAndShowNotification(
return true;
}
-bool BalloonCollectionImpl::RemoveById(const std::string& id) {
- return base_.CloseById(id);
-}
-
-bool BalloonCollectionImpl::RemoveBySourceOrigin(const GURL& origin) {
- return base_.CloseAllBySourceOrigin(origin);
+bool BalloonCollectionImpl::Remove(const Notification& notification) {
+ Balloons::iterator iter = FindBalloon(notification);
+ if (iter != balloons_.end()) {
+ // Balloon.CloseByScript() will cause OnBalloonClosed() to be called on
+ // this object, which will remove it from the collection and free it.
+ (*iter)->CloseByScript();
+ return true;
+ }
+ return false;
}
bool BalloonCollectionImpl::HasSpace() const {
@@ -121,9 +137,15 @@ void BalloonCollectionImpl::ResizeBalloon(Balloon* balloon,
}
void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
+ // We want to free the balloon when finished.
+ scoped_ptr<Balloon> closed(source);
+
notification_ui_->Remove(source);
- base_.Remove(source);
+ Balloons::iterator iter = FindBalloon(source->notification());
+ if (iter != balloons_.end()) {
+ balloons_.erase(iter);
+ }
// There may be no listener in a unit test.
if (space_change_listener_)
space_change_listener_->OnBalloonSpaceChanged();
@@ -148,6 +170,7 @@ void BalloonCollectionImpl::Shutdown() {
// themselves from the parent.
DVLOG(1) << "Shutting down notification UI";
notification_ui_.reset();
+ STLDeleteElements(&balloons_);
}
Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
@@ -157,6 +180,13 @@ Balloon* BalloonCollectionImpl::MakeBalloon(const Notification& notification,
return new_balloon;
}
+std::deque<Balloon*>::iterator BalloonCollectionImpl::FindBalloon(
+ const Notification& notification) {
+ return std::find_if(balloons_.begin(),
+ balloons_.end(),
+ NotificationMatcher(notification));
+}
+
} // namespace chromeos
// static
diff --git a/chrome/browser/chromeos/notifications/balloon_collection_impl.h b/chrome/browser/chromeos/notifications/balloon_collection_impl.h
index c9c74b5..79cfe14 100644
--- a/chrome/browser/chromeos/notifications/balloon_collection_impl.h
+++ b/chrome/browser/chromeos/notifications/balloon_collection_impl.h
@@ -12,7 +12,6 @@
#include "base/scoped_ptr.h"
#include "chrome/browser/chromeos/notifications/balloon_view_host.h"
#include "chrome/browser/notifications/balloon_collection.h"
-#include "chrome/browser/notifications/balloon_collection_base.h"
#include "chrome/common/notification_registrar.h"
#include "gfx/point.h"
#include "gfx/rect.h"
@@ -61,13 +60,12 @@ class BalloonCollectionImpl : public BalloonCollection,
// BalloonCollectionInterface overrides
virtual void Add(const Notification& notification,
Profile* profile);
- virtual bool RemoveById(const std::string& id);
- virtual bool RemoveBySourceOrigin(const GURL& origin);
+ virtual bool Remove(const Notification& notification);
virtual bool HasSpace() const;
virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size);
virtual void DisplayChanged() {}
virtual void OnBalloonClosed(Balloon* source);
- virtual const Balloons& GetActiveBalloons() { return base_.balloons(); }
+ virtual const Balloons& GetActiveBalloons() { return balloons_; }
// NotificationObserver overrides:
virtual void Observe(NotificationType type,
@@ -117,18 +115,19 @@ class BalloonCollectionImpl : public BalloonCollection,
virtual Balloon* MakeBalloon(const Notification& notification,
Profile* profile);
- // Base implementation for the collection of active balloons.
- BalloonCollectionBase base_;
-
private:
friend class NotificationPanelTester;
// Shutdown the notification ui.
void Shutdown();
- Balloon* FindBalloon(const Notification& notification) {
- return base_.FindBalloon(notification);
- }
+ // The number of balloons being displayed.
+ int count() const { return balloons_.size(); }
+
+ Balloons::iterator FindBalloon(const Notification& notification);
+
+ // Queue of active balloons.
+ Balloons balloons_;
scoped_ptr<NotificationUI> notification_ui_;
diff --git a/chrome/browser/chromeos/notifications/balloon_view.cc b/chrome/browser/chromeos/notifications/balloon_view.cc
index ff5ea0f..24a6004 100644
--- a/chrome/browser/chromeos/notifications/balloon_view.cc
+++ b/chrome/browser/chromeos/notifications/balloon_view.cc
@@ -15,7 +15,6 @@
#include "chrome/browser/chromeos/notifications/notification_panel.h"
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
-#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
@@ -301,8 +300,7 @@ void BalloonViewImpl::Observe(NotificationType type,
// BalloonViewImpl public.
bool BalloonViewImpl::IsFor(const Notification& notification) const {
- return balloon_->notification().notification_id() ==
- notification.notification_id();
+ return balloon_->notification().IsSame(notification);
}
void BalloonViewImpl::Activated() {
diff --git a/chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc b/chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc
index 377828b..8c0a4be 100644
--- a/chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/chromeos/notifications/desktop_notifications_unittest.cc
@@ -24,24 +24,33 @@ class MockNotificationUI : public BalloonCollectionImpl::NotificationUI {
virtual void SetActiveView(BalloonViewImpl* view) {}
};
-MockBalloonCollection::MockBalloonCollection() {
+MockBalloonCollection::MockBalloonCollection()
+ : log_proxy_(new LoggingNotificationProxy()) {
set_notification_ui(new MockNotificationUI());
}
void MockBalloonCollection::Add(const Notification& notification,
Profile* profile) {
- // Swap in a logging proxy for the purpose of logging calls that
+ // Swap in the logging proxy for the purpose of logging calls that
// would be made into javascript, then pass this down to the
// balloon collection.
- Notification test_notification(
- notification.origin_url(),
- notification.content_url(),
- notification.display_source(),
- notification.replace_id(),
- new LoggingNotificationProxy(notification.notification_id()));
+ Notification test_notification(notification.origin_url(),
+ notification.content_url(),
+ notification.display_source(),
+ string16(), /* replace_id */
+ log_proxy_.get());
BalloonCollectionImpl::Add(test_notification, profile);
}
+bool MockBalloonCollection::Remove(const Notification& notification) {
+ Notification test_notification(notification.origin_url(),
+ notification.content_url(),
+ notification.display_source(),
+ string16(), /* replace_id */
+ log_proxy_.get());
+ return BalloonCollectionImpl::Remove(test_notification);
+}
+
Balloon* MockBalloonCollection::MakeBalloon(const Notification& notification,
Profile* profile) {
// Start with a normal balloon but mock out the view.
diff --git a/chrome/browser/chromeos/notifications/desktop_notifications_unittest.h b/chrome/browser/chromeos/notifications/desktop_notifications_unittest.h
index 5471b3b..8e0d7ae 100644
--- a/chrome/browser/chromeos/notifications/desktop_notifications_unittest.h
+++ b/chrome/browser/chromeos/notifications/desktop_notifications_unittest.h
@@ -17,6 +17,7 @@
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_object_proxy.h"
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/notifications/notifications_prefs_cache.h"
@@ -27,7 +28,7 @@
namespace chromeos {
class DesktopNotificationsTest;
-typedef LoggingNotificationDelegate<DesktopNotificationsTest>
+typedef LoggingNotificationProxyBase<DesktopNotificationsTest>
LoggingNotificationProxy;
// Test version of the balloon collection which counts the number
@@ -39,6 +40,7 @@ class MockBalloonCollection : public BalloonCollectionImpl {
// BalloonCollectionImpl overrides
virtual void Add(const Notification& notification,
Profile* profile);
+ virtual bool Remove(const Notification& notification);
virtual Balloon* MakeBalloon(const Notification& notification,
Profile* profile);
virtual void OnBalloonClosed(Balloon* source);
@@ -52,6 +54,7 @@ class MockBalloonCollection : public BalloonCollectionImpl {
private:
std::set<Balloon*> balloons_;
+ scoped_refptr<LoggingNotificationProxy> log_proxy_;
};
class DesktopNotificationsTest : public testing::Test {
diff --git a/chrome/browser/chromeos/notifications/notification_browsertest.cc b/chrome/browser/chromeos/notifications/notification_browsertest.cc
index 82cd702..b5830d5 100644
--- a/chrome/browser/chromeos/notifications/notification_browsertest.cc
+++ b/chrome/browser/chromeos/notifications/notification_browsertest.cc
@@ -15,7 +15,7 @@
#include "chrome/browser/chromeos/notifications/balloon_view.h"
#include "chrome/browser/chromeos/notifications/notification_panel.h"
#include "chrome/browser/chromeos/notifications/system_notification_factory.h"
-#include "chrome/browser/notifications/notification_test_util.h"
+#include "chrome/browser/notifications/notification_delegate.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/notification_service.h"
@@ -24,6 +24,22 @@
namespace {
+class MockNotificationDelegate : public NotificationDelegate {
+ public:
+ explicit MockNotificationDelegate(const std::string& id) : id_(id) {}
+
+ virtual void Display() {}
+ virtual void Error() {}
+ virtual void Close(bool by_user) {}
+ virtual void Click() {}
+ virtual std::string id() const { return id_; }
+
+ private:
+ std::string id_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate);
+};
+
// The name of ChromeOS's window manager.
const char* kChromeOsWindowManagerName = "chromeos-wm";
@@ -146,14 +162,14 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestBasic) {
EXPECT_EQ(2, tester->GetNotificationCount());
EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
- collection->RemoveById("1");
+ collection->Remove(NewMockNotification("1"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(1, tester->GetNewNotificationCount());
EXPECT_EQ(1, tester->GetNotificationCount());
EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
- collection->RemoveById("2");
+ collection->Remove(NewMockNotification("2"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(0, tester->GetNewNotificationCount());
EXPECT_EQ(0, tester->GetNotificationCount());
@@ -182,7 +198,7 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestKeepSizeState) {
panel->OnMouseMotion(gfx::Point(10, 10));
EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state());
- collection->RemoveById("1");
+ collection->Remove(NewMockNotification("1"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(1, tester->GetNewNotificationCount());
EXPECT_EQ(1, tester->GetNotificationCount());
@@ -194,20 +210,20 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestKeepSizeState) {
EXPECT_EQ(2, tester->GetNotificationCount());
EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state());
- collection->RemoveById("1");
+ collection->Remove(NewMockNotification("1"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(1, tester->GetNewNotificationCount());
EXPECT_EQ(1, tester->GetNotificationCount());
EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state());
- collection->RemoveById("2");
+ collection->Remove(NewMockNotification("2"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(0, tester->GetNotificationCount());
EXPECT_EQ(NotificationPanel::CLOSED, tester->state());
collection->Add(NewMockNotification("3"), browser()->profile());
EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
- collection->RemoveById("3");
+ collection->Remove(NewMockNotification("3"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(0, tester->GetNotificationCount());
@@ -241,7 +257,10 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestSystemNotification) {
EXPECT_EQ(1, tester->GetStickyNotificationCount());
// Dismiss the notification.
- collection->RemoveById(delegate->id());
+ // TODO(oshima): Consider updating API to Remove(NotificationDelegate)
+ // or Remove(std::string id);
+ collection->Remove(Notification(GURL(), GURL(), string16(), string16(),
+ delegate.get()));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(0, tester->GetStickyNotificationCount());
@@ -268,11 +287,11 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition1) {
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state());
- collection->RemoveById("2");
+ collection->Remove(NewMockNotification("2"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state());
- collection->RemoveById("1");
+ collection->Remove(NewMockNotification("1"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(0, tester->GetNotificationCount());
EXPECT_EQ(NotificationPanel::CLOSED, tester->state());
@@ -338,19 +357,20 @@ IN_PROC_BROWSER_TEST_F(NotificationTest, FLAKY_TestStateTransition2) {
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
- collection->RemoveById("1");
+ collection->Remove(NewMockNotification("1"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state());
// Removing the system notification should minimize the panel.
- collection->RemoveById("3");
+ collection->Remove(NewMockNotification("3"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(1, tester->GetNotificationCount());
EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state());
WaitForPanelState(tester, PanelController::MINIMIZED);
// Removing the last notification. Should close the panel.
- collection->RemoveById("2");
+
+ collection->Remove(NewMockNotification("2"));
ui_test_utils::RunAllPendingInMessageLoop();
EXPECT_EQ(0, tester->GetNotificationCount());
EXPECT_EQ(NotificationPanel::CLOSED, tester->state());
diff --git a/chrome/browser/chromeos/notifications/notification_panel.cc b/chrome/browser/chromeos/notifications/notification_panel.cc
index 6ab3b31..1ff6014 100644
--- a/chrome/browser/chromeos/notifications/notification_panel.cc
+++ b/chrome/browser/chromeos/notifications/notification_panel.cc
@@ -848,8 +848,10 @@ PanelController* NotificationPanelTester::GetPanelController() const {
BalloonViewImpl* NotificationPanelTester::GetBalloonView(
BalloonCollectionImpl* collection,
const Notification& notification) {
- Balloon* balloon = collection->FindBalloon(notification);
- DCHECK(balloon);
+ BalloonCollectionImpl::Balloons::iterator iter =
+ collection->FindBalloon(notification);
+ DCHECK(iter != collection->balloons_.end());
+ Balloon* balloon = (*iter);
return GetBalloonViewOf(balloon);
}
diff --git a/chrome/browser/chromeos/notifications/system_notification.cc b/chrome/browser/chromeos/notifications/system_notification.cc
index 0d85687..f83c414 100644
--- a/chrome/browser/chromeos/notifications/system_notification.cc
+++ b/chrome/browser/chromeos/notifications/system_notification.cc
@@ -65,7 +65,9 @@ void SystemNotification::Show(const string16& message,
void SystemNotification::Hide() {
if (visible_) {
- collection_->RemoveById(delegate_->id());
+ collection_->Remove(Notification(GURL(), GURL(), string16(), string16(),
+ delegate_.get()));
+
visible_ = false;
urgent_ = false;
}
diff --git a/chrome/browser/cocoa/notifications/balloon_controller.mm b/chrome/browser/cocoa/notifications/balloon_controller.mm
index 048888c..3f8a8b0 100644
--- a/chrome/browser/cocoa/notifications/balloon_controller.mm
+++ b/chrome/browser/cocoa/notifications/balloon_controller.mm
@@ -17,7 +17,6 @@
#include "chrome/browser/cocoa/notifications/balloon_view_host_mac.h"
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
-#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_options_menu_model.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
diff --git a/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm b/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm
index 31f7c15..6f6a1ab 100644
--- a/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm
+++ b/chrome/browser/cocoa/notifications/balloon_controller_unittest.mm
@@ -30,8 +30,7 @@ namespace {
class MockBalloonCollection : public BalloonCollection {
virtual void Add(const Notification& notification,
Profile* profile) {}
- virtual bool RemoveById(const std::string& id) { return false; }
- virtual bool RemoveBySourceOrigin(const GURL& origin) { return false; }
+ virtual bool Remove(const Notification& notification) { return false; }
virtual bool HasSpace() const { return true; }
virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size) {};
virtual void DisplayChanged() {}
diff --git a/chrome/browser/gtk/notifications/balloon_view_gtk.cc b/chrome/browser/gtk/notifications/balloon_view_gtk.cc
index 9161be5..795b4ea 100644
--- a/chrome/browser/gtk/notifications/balloon_view_gtk.cc
+++ b/chrome/browser/gtk/notifications/balloon_view_gtk.cc
@@ -27,7 +27,6 @@
#include "chrome/browser/gtk/rounded_window.h"
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
-#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_options_menu_model.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
diff --git a/chrome/browser/notifications/balloon_collection.cc b/chrome/browser/notifications/balloon_collection.cc
index 7d926ed..a125837 100644
--- a/chrome/browser/notifications/balloon_collection.cc
+++ b/chrome/browser/notifications/balloon_collection.cc
@@ -45,6 +45,7 @@ BalloonCollectionImpl::BalloonCollectionImpl()
}
BalloonCollectionImpl::~BalloonCollectionImpl() {
+ STLDeleteElements(&balloons_);
}
void BalloonCollectionImpl::Add(const Notification& notification,
@@ -58,11 +59,10 @@ void BalloonCollectionImpl::Add(const Notification& notification,
new_balloon->SetPosition(layout_.OffScreenLocation(), false);
new_balloon->Show();
#if USE_OFFSETS
- int count = base_.count();
- if (count > 0)
- new_balloon->set_offset(base_.balloons()[count - 1]->offset());
+ if (balloons_.size() > 0)
+ new_balloon->set_offset(balloons_[balloons_.size() - 1]->offset());
#endif
- base_.Add(new_balloon);
+ balloons_.push_back(new_balloon);
PositionBalloons(false);
// There may be no listener in a unit test.
@@ -74,24 +74,28 @@ void BalloonCollectionImpl::Add(const Notification& notification,
on_collection_changed_callback_->Run();
}
-bool BalloonCollectionImpl::RemoveById(const std::string& id) {
- return base_.CloseById(id);
-}
-
-bool BalloonCollectionImpl::RemoveBySourceOrigin(const GURL& origin) {
- return base_.CloseAllBySourceOrigin(origin);
+bool BalloonCollectionImpl::Remove(const Notification& notification) {
+ Balloons::iterator iter;
+ for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) {
+ if (notification.IsSame((*iter)->notification())) {
+ // Balloon.CloseByScript() will cause OnBalloonClosed() to be called on
+ // this object, which will remove it from the collection and free it.
+ (*iter)->CloseByScript();
+ return true;
+ }
+ }
+ return false;
}
bool BalloonCollectionImpl::HasSpace() const {
- int count = base_.count();
- if (count < kMinAllowedBalloonCount)
+ if (count() < kMinAllowedBalloonCount)
return true;
int max_balloon_size = 0;
int total_size = 0;
layout_.GetMaxLinearSize(&max_balloon_size, &total_size);
- int current_max_size = max_balloon_size * count;
+ int current_max_size = max_balloon_size * count();
int max_allowed_size = static_cast<int>(total_size *
kPercentBalloonFillFactor);
return current_max_size < max_allowed_size - max_balloon_size;
@@ -110,16 +114,16 @@ void BalloonCollectionImpl::DisplayChanged() {
void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
// We want to free the balloon when finished.
- const Balloons& balloons = base_.balloons();
- Balloons::const_iterator it = balloons.begin();
+ scoped_ptr<Balloon> closed(source);
+ Balloons::iterator it = balloons_.begin();
#if USE_OFFSETS
gfx::Point offset;
bool apply_offset = false;
- while (it != balloons.end()) {
+ while (it != balloons_.end()) {
if (*it == source) {
- ++it;
- if (it != balloons.end()) {
+ it = balloons_.erase(it);
+ if (it != balloons_.end()) {
apply_offset = true;
offset.set_y((source)->offset().y() - (*it)->offset().y() +
(*it)->content_size().height() - source->content_size().height());
@@ -134,9 +138,15 @@ void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
// leaves the balloon area.
if (apply_offset)
AddMessageLoopObserver();
+#else
+ for (; it != balloons_.end(); ++it) {
+ if (*it == source) {
+ balloons_.erase(it);
+ break;
+ }
+ }
#endif
- base_.Remove(source);
PositionBalloons(true);
// There may be no listener in a unit test.
@@ -149,13 +159,9 @@ void BalloonCollectionImpl::OnBalloonClosed(Balloon* source) {
}
void BalloonCollectionImpl::PositionBalloonsInternal(bool reposition) {
- const Balloons& balloons = base_.balloons();
-
layout_.RefreshSystemMetrics();
gfx::Point origin = layout_.GetLayoutOrigin();
- for (Balloons::const_iterator it = balloons.begin();
- it != balloons.end();
- ++it) {
+ for (Balloons::iterator it = balloons_.begin(); it != balloons_.end(); ++it) {
gfx::Point upper_left = layout_.NextPosition((*it)->GetViewSize(), &origin);
(*it)->SetPosition(upper_left, reposition);
}
@@ -182,10 +188,7 @@ void BalloonCollectionImpl::CancelOffsets() {
// Unhook from listening to all UI events.
RemoveMessageLoopObserver();
- const Balloons& balloons = base_.balloons();
- for (Balloons::const_iterator it = balloons.begin();
- it != balloons.end();
- ++it)
+ for (Balloons::iterator it = balloons_.begin(); it != balloons_.end(); ++it)
(*it)->set_offset(gfx::Point(0, 0));
PositionBalloons(true);
diff --git a/chrome/browser/notifications/balloon_collection.h b/chrome/browser/notifications/balloon_collection.h
index 2d75686..499b937 100644
--- a/chrome/browser/notifications/balloon_collection.h
+++ b/chrome/browser/notifications/balloon_collection.h
@@ -9,13 +9,11 @@
#pragma once
#include <deque>
-#include <string>
#include "base/callback.h"
#include "base/scoped_ptr.h"
class Balloon;
-class GURL;
class Notification;
class Profile;
@@ -46,13 +44,9 @@ class BalloonCollection {
virtual void Add(const Notification& notification,
Profile* profile) = 0;
- // Removes any balloons that have this notification id. Returns
+ // Removes a balloon from the collection if present. Returns
// true if anything was removed.
- virtual bool RemoveById(const std::string& id) = 0;
-
- // Removes any balloons that have this source origin. Returns
- // true if anything was removed.
- virtual bool RemoveBySourceOrigin(const GURL& source_origin) = 0;
+ virtual bool Remove(const Notification& notification) = 0;
// Is there room to add another notification?
virtual bool HasSpace() const = 0;
diff --git a/chrome/browser/notifications/balloon_collection_base.cc b/chrome/browser/notifications/balloon_collection_base.cc
deleted file mode 100644
index 94765c0..0000000
--- a/chrome/browser/notifications/balloon_collection_base.cc
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/notifications/balloon_collection_base.h"
-
-#include "base/stl_util-inl.h"
-#include "chrome/browser/notifications/balloon.h"
-#include "chrome/browser/notifications/notification.h"
-#include "googleurl/src/gurl.h"
-
-BalloonCollectionBase::BalloonCollectionBase() {
-}
-
-BalloonCollectionBase::~BalloonCollectionBase() {
- STLDeleteElements(&balloons_);
-}
-
-void BalloonCollectionBase::Add(Balloon* balloon) {
- balloons_.push_back(balloon);
-}
-
-void BalloonCollectionBase::Remove(Balloon* balloon) {
- // Free after removing.
- scoped_ptr<Balloon> to_delete(balloon);
- Balloons::iterator iter;
- for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) {
- if ((*iter) == balloon) {
- balloons_.erase(iter);
- return;
- }
- }
-}
-
-bool BalloonCollectionBase::CloseById(const std::string& id) {
- // Use a local list of balloons to close to avoid breaking
- // iterator changes on each close.
- Balloons to_close;
- Balloons::iterator iter;
- for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) {
- if ((*iter)->notification().notification_id() == id)
- to_close.push_back(*iter);
- }
- for (iter = to_close.begin(); iter != to_close.end(); ++iter)
- (*iter)->CloseByScript();
-
- return !to_close.empty();
-}
-
-bool BalloonCollectionBase::CloseAllBySourceOrigin(
- const GURL& source_origin) {
- // Use a local list of balloons to close to avoid breaking
- // iterator changes on each close.
- Balloons to_close;
- Balloons::iterator iter;
- for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) {
- if ((*iter)->notification().origin_url() == source_origin)
- to_close.push_back(*iter);
- }
- for (iter = to_close.begin(); iter != to_close.end(); ++iter)
- (*iter)->CloseByScript();
-
- return !to_close.empty();
-}
-
-Balloon* BalloonCollectionBase::FindBalloon(
- const Notification& notification) {
- Balloons::iterator iter;
- for (iter = balloons_.begin(); iter != balloons_.end(); ++iter) {
- if ((*iter)->notification().notification_id() ==
- notification.notification_id()) {
- return *iter;
- }
- }
- return NULL;
-}
diff --git a/chrome/browser/notifications/balloon_collection_base.h b/chrome/browser/notifications/balloon_collection_base.h
deleted file mode 100644
index 8511030..0000000
--- a/chrome/browser/notifications/balloon_collection_base.h
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Handles the visible notification (or balloons).
-
-#ifndef CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_BASE_H_
-#define CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_BASE_H_
-#pragma once
-
-#include <deque>
-#include <string>
-
-#include "base/basictypes.h"
-
-class Balloon;
-class GURL;
-class Notification;
-
-// This class provides support for implementing a BalloonCollection
-// including the parts common between Chrome UI and ChromeOS UI.
-class BalloonCollectionBase {
- public:
- BalloonCollectionBase();
- virtual ~BalloonCollectionBase();
-
- typedef std::deque<Balloon*> Balloons;
-
- // Adds a balloon to the collection. Takes ownership of pointer.
- virtual void Add(Balloon* balloon);
-
- // Removes a balloon from the collection (if present). Frees
- // the pointer after removal.
- virtual void Remove(Balloon* balloon);
-
- // Finds any balloon matching the given notification id, and
- // calls CloseByScript on it. Returns true if anything was
- // found.
- virtual bool CloseById(const std::string& id);
-
- // Finds all balloons matching the given notification source,
- // and calls CloseByScript on them. Returns true if anything
- // was found.
- virtual bool CloseAllBySourceOrigin(const GURL& source_origin);
-
- const Balloons& balloons() const { return balloons_; }
-
- // Returns the balloon matching the given notification, or
- // NULL if there is no matching balloon.
- Balloon* FindBalloon(const Notification& notification);
-
- // The number of balloons being displayed.
- int count() const { return static_cast<int>(balloons_.size()); }
-
- private:
- // Queue of active balloons. Pointers are owned by this class.
- Balloons balloons_;
-
- DISALLOW_COPY_AND_ASSIGN(BalloonCollectionBase);
-};
-
-#endif // CHROME_BROWSER_NOTIFICATIONS_BALLOON_COLLECTION_BASE_H_
diff --git a/chrome/browser/notifications/balloon_collection_impl.h b/chrome/browser/notifications/balloon_collection_impl.h
index 3596a25..a9c7afc 100644
--- a/chrome/browser/notifications/balloon_collection_impl.h
+++ b/chrome/browser/notifications/balloon_collection_impl.h
@@ -13,7 +13,6 @@
#include "base/basictypes.h"
#include "base/message_loop.h"
#include "chrome/browser/notifications/balloon_collection.h"
-#include "chrome/browser/notifications/balloon_collection_base.h"
#include "gfx/point.h"
#include "gfx/rect.h"
@@ -42,13 +41,14 @@ class BalloonCollectionImpl : public BalloonCollection
// BalloonCollection interface.
virtual void Add(const Notification& notification,
Profile* profile);
- virtual bool RemoveById(const std::string& id);
- virtual bool RemoveBySourceOrigin(const GURL& source_origin);
+ virtual bool Remove(const Notification& notification);
virtual bool HasSpace() const;
virtual void ResizeBalloon(Balloon* balloon, const gfx::Size& size);
virtual void DisplayChanged();
virtual void OnBalloonClosed(Balloon* source);
- virtual const Balloons& GetActiveBalloons() { return base_.balloons(); }
+ virtual const Balloons& GetActiveBalloons() {
+ return balloons_;
+ }
// MessageLoopForUI::Observer interface.
#if defined(OS_WIN)
@@ -135,6 +135,9 @@ class BalloonCollectionImpl : public BalloonCollection
Profile* profile);
private:
+ // The number of balloons being displayed.
+ int count() const { return balloons_.size(); }
+
// Adjusts the positions of the balloons (e.g., when one is closed).
// Implemented by each platform for specific UI requirements.
void PositionBalloons(bool is_reposition);
@@ -147,12 +150,6 @@ class BalloonCollectionImpl : public BalloonCollection
static gfx::Rect GetMacWorkArea();
#endif
- // Base implementation for the collection of active balloons.
- BalloonCollectionBase base_;
-
- // The layout parameters for balloons in this collection.
- Layout layout_;
-
#if USE_OFFSETS
// Start and stop observing all UI events.
void AddMessageLoopObserver();
@@ -166,7 +163,16 @@ class BalloonCollectionImpl : public BalloonCollection
// Is the current cursor in the balloon area?
bool IsCursorInBalloonCollection() const;
+#endif
+ // Queue of active balloons.
+ typedef std::deque<Balloon*> Balloons;
+ Balloons balloons_;
+
+ // The layout parameters for balloons in this collection.
+ Layout layout_;
+
+#if USE_OFFSETS
// Factory for generating delayed reposition tasks on mouse motion.
ScopedRunnableMethodFactory<BalloonCollectionImpl> reposition_factory_;
diff --git a/chrome/browser/notifications/balloon_collection_linux.cc b/chrome/browser/notifications/balloon_collection_linux.cc
index 08354a0..f15c713 100644
--- a/chrome/browser/notifications/balloon_collection_linux.cc
+++ b/chrome/browser/notifications/balloon_collection_linux.cc
@@ -46,11 +46,10 @@ void BalloonCollectionImpl::DidProcessEvent(GdkEvent* event) {
}
bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
- const Balloons& balloons = base_.balloons();
- if (balloons.empty())
+ if (balloons_.empty())
return false;
- gfx::Point upper_left = balloons[balloons.size() - 1]->GetPosition();
+ gfx::Point upper_left = balloons_[balloons_.size() - 1]->GetPosition();
gfx::Point lower_right = layout_.GetLayoutOrigin();
gfx::Rect bounds = gfx::Rect(upper_left.x(),
diff --git a/chrome/browser/notifications/balloon_collection_win.cc b/chrome/browser/notifications/balloon_collection_win.cc
index 07bcd18..8915662 100644
--- a/chrome/browser/notifications/balloon_collection_win.cc
+++ b/chrome/browser/notifications/balloon_collection_win.cc
@@ -44,11 +44,10 @@ void BalloonCollectionImpl::DidProcessMessage(const MSG& msg) {
}
bool BalloonCollectionImpl::IsCursorInBalloonCollection() const {
- const Balloons& balloons = base_.balloons();
- if (balloons.empty())
+ if (balloons_.empty())
return false;
- gfx::Point upper_left = balloons[balloons.size() - 1]->GetPosition();
+ gfx::Point upper_left = balloons_[balloons_.size() - 1]->GetPosition();
gfx::Point lower_right = layout_.GetLayoutOrigin();
gfx::Rect bounds = gfx::Rect(upper_left.x(),
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index 065d355..e7530e4 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -215,7 +215,7 @@ DesktopNotificationService::DesktopNotificationService(Profile* profile,
NotificationUIManager* ui_manager)
: profile_(profile),
ui_manager_(ui_manager) {
- prefs_registrar_.Init(profile_->GetPrefs());
+ registrar_.Init(profile_->GetPrefs());
InitPrefs();
StartObserving();
}
@@ -260,24 +260,16 @@ void DesktopNotificationService::InitPrefs() {
void DesktopNotificationService::StartObserving() {
if (!profile_->IsOffTheRecord()) {
- prefs_registrar_.Add(prefs::kDesktopNotificationDefaultContentSetting,
- this);
- prefs_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this);
- prefs_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this);
-
- notification_registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
- NotificationService::AllSources());
+ registrar_.Add(prefs::kDesktopNotificationDefaultContentSetting, this);
+ registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this);
+ registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this);
}
-
- notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED,
- Source<Profile>(profile_));
}
void DesktopNotificationService::StopObserving() {
if (!profile_->IsOffTheRecord()) {
- prefs_registrar_.RemoveAll();
+ registrar_.RemoveAll();
}
- notification_registrar_.RemoveAll();
}
void DesktopNotificationService::GrantPermission(const GURL& origin) {
@@ -307,24 +299,11 @@ void DesktopNotificationService::DenyPermission(const GURL& origin) {
void DesktopNotificationService::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- if (NotificationType::PREF_CHANGED == type) {
- const std::string& name = *Details<std::string>(details).ptr();
- OnPrefsChanged(name);
- } else if (NotificationType::EXTENSION_UNLOADED == type) {
- // Remove all notifications currently shown or queued by the extension
- // which was unloaded.
- Extension* extension = Details<Extension>(details).ptr();
- if (extension)
- ui_manager_->CancelAllBySourceOrigin(extension->url());
- } else if (NotificationType::PROFILE_DESTROYED == type) {
- StopObserving();
- }
-}
-
-void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) {
+ DCHECK(NotificationType::PREF_CHANGED == type);
PrefService* prefs = profile_->GetPrefs();
+ const std::string& name = *Details<std::string>(details).ptr();
- if (pref_name == prefs::kDesktopNotificationAllowedOrigins) {
+ if (name == prefs::kDesktopNotificationAllowedOrigins) {
NotificationService::current()->Notify(
NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
Source<DesktopNotificationService>(this),
@@ -338,7 +317,7 @@ void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) {
prefs_cache_.get(),
&NotificationsPrefsCache::SetCacheAllowedOrigins,
allowed_origins));
- } else if (pref_name == prefs::kDesktopNotificationDeniedOrigins) {
+ } else if (name == prefs::kDesktopNotificationDeniedOrigins) {
NotificationService::current()->Notify(
NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED,
Source<DesktopNotificationService>(this),
@@ -352,7 +331,7 @@ void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) {
prefs_cache_.get(),
&NotificationsPrefsCache::SetCacheDeniedOrigins,
denied_origins));
- } else if (pref_name == prefs::kDesktopNotificationDefaultContentSetting) {
+ } else if (name == prefs::kDesktopNotificationDefaultContentSetting) {
NotificationService::current()->Notify(
NotificationType::DESKTOP_NOTIFICATION_DEFAULT_CHANGED,
Source<DesktopNotificationService>(this),
@@ -584,7 +563,9 @@ bool DesktopNotificationService::CancelDesktopNotification(
scoped_refptr<NotificationObjectProxy> proxy(
new NotificationObjectProxy(process_id, route_id, notification_id,
false));
- return ui_manager_->CancelById(proxy->id());
+ // TODO(johnnyg): clean up this "empty" notification.
+ Notification notif(GURL(), GURL(), string16(), string16(), proxy);
+ return ui_manager_->Cancel(notif);
}
diff --git a/chrome/browser/notifications/desktop_notification_service.h b/chrome/browser/notifications/desktop_notification_service.h
index 53fa56f..d92d7e6 100644
--- a/chrome/browser/notifications/desktop_notification_service.h
+++ b/chrome/browser/notifications/desktop_notification_service.h
@@ -6,24 +6,24 @@
#define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATION_SERVICE_H_
#pragma once
-#include <string>
#include <vector>
#include "base/basictypes.h"
-#include "base/ref_counted.h"
#include "base/string16.h"
+#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/prefs/pref_change_registrar.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
+#include "chrome/common/notification_service.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h"
-class Notification;
class NotificationUIManager;
class NotificationsPrefsCache;
class PrefService;
class Profile;
+class Task;
class TabContents;
struct ViewHostMsg_ShowNotification_Params;
@@ -121,8 +121,6 @@ class DesktopNotificationService : public NotificationObserver {
void StartObserving();
void StopObserving();
- void OnPrefsChanged(const std::string& pref_name);
-
// Takes a notification object and shows it in the UI.
void ShowNotification(const Notification& notification);
@@ -145,8 +143,7 @@ class DesktopNotificationService : public NotificationObserver {
// UI for desktop toasts.
NotificationUIManager* ui_manager_;
- PrefChangeRegistrar prefs_registrar_;
- NotificationRegistrar notification_registrar_;
+ PrefChangeRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(DesktopNotificationService);
};
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc
index ebb6ab8..99466901 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.cc
+++ b/chrome/browser/notifications/desktop_notifications_unittest.cc
@@ -16,18 +16,26 @@ std::string DesktopNotificationsTest::log_output_;
void MockBalloonCollection::Add(const Notification& notification,
Profile* profile) {
- // Swap in a logging proxy for the purpose of logging calls that
+ // Swap in the logging proxy for the purpose of logging calls that
// would be made into javascript, then pass this down to the
// balloon collection.
- Notification test_notification(
- notification.origin_url(),
- notification.content_url(),
- notification.display_source(),
- notification.replace_id(),
- new LoggingNotificationProxy(notification.notification_id()));
+ Notification test_notification(notification.origin_url(),
+ notification.content_url(),
+ notification.display_source(),
+ string16(), /* replace_id */
+ log_proxy_.get());
BalloonCollectionImpl::Add(test_notification, profile);
}
+bool MockBalloonCollection::Remove(const Notification& notification) {
+ Notification test_notification(notification.origin_url(),
+ notification.content_url(),
+ notification.display_source(),
+ string16(), /* replace_id */
+ log_proxy_.get());
+ return BalloonCollectionImpl::Remove(test_notification);
+}
+
Balloon* MockBalloonCollection::MakeBalloon(const Notification& notification,
Profile* profile) {
// Start with a normal balloon but mock out the view.
diff --git a/chrome/browser/notifications/desktop_notifications_unittest.h b/chrome/browser/notifications/desktop_notifications_unittest.h
index 9f556e4..3b02b7b 100644
--- a/chrome/browser/notifications/desktop_notifications_unittest.h
+++ b/chrome/browser/notifications/desktop_notifications_unittest.h
@@ -22,14 +22,15 @@
#include "testing/gtest/include/gtest/gtest.h"
class DesktopNotificationsTest;
-typedef LoggingNotificationDelegate<DesktopNotificationsTest>
+typedef LoggingNotificationProxyBase<DesktopNotificationsTest>
LoggingNotificationProxy;
// Test version of the balloon collection which counts the number
// of notifications that are added to it.
class MockBalloonCollection : public BalloonCollectionImpl {
public:
- MockBalloonCollection() {}
+ MockBalloonCollection() :
+ log_proxy_(new LoggingNotificationProxy()) {}
// Our mock collection has an area large enough for a fixed number
// of balloons.
@@ -39,6 +40,7 @@ class MockBalloonCollection : public BalloonCollectionImpl {
// BalloonCollectionImpl overrides
virtual void Add(const Notification& notification,
Profile* profile);
+ virtual bool Remove(const Notification& notification);
virtual bool HasSpace() const { return count() < kMockBalloonSpace; }
virtual Balloon* MakeBalloon(const Notification& notification,
Profile* profile);
@@ -61,6 +63,7 @@ class MockBalloonCollection : public BalloonCollectionImpl {
private:
std::deque<Balloon*> balloons_;
+ scoped_refptr<LoggingNotificationProxy> log_proxy_;
};
class DesktopNotificationsTest : public testing::Test {
diff --git a/chrome/browser/notifications/notification.cc b/chrome/browser/notifications/notification.cc
index e6d69a6..c429efa 100644
--- a/chrome/browser/notifications/notification.cc
+++ b/chrome/browser/notifications/notification.cc
@@ -34,3 +34,7 @@ Notification& Notification::operator=(const Notification& notification) {
delegate_ = notification.delegate();
return *this;
}
+
+bool Notification::IsSame(const Notification& other) const {
+ return delegate()->id() == other.delegate()->id();
+}
diff --git a/chrome/browser/notifications/notification.h b/chrome/browser/notifications/notification.h
index 2040cf3..7b0ab8c 100644
--- a/chrome/browser/notifications/notification.h
+++ b/chrome/browser/notifications/notification.h
@@ -6,8 +6,6 @@
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
#pragma once
-#include <string>
-
#include "base/basictypes.h"
#include "chrome/browser/notifications/notification_object_proxy.h"
#include "googleurl/src/gurl.h"
@@ -44,7 +42,7 @@ class Notification {
void Click() const { delegate()->Click(); }
void Close(bool by_user) const { delegate()->Close(by_user); }
- std::string notification_id() const { return delegate()->id(); }
+ bool IsSame(const Notification& other) const;
private:
NotificationDelegate* delegate() const { return delegate_.get(); }
diff --git a/chrome/browser/notifications/notification_options_menu_model.cc b/chrome/browser/notifications/notification_options_menu_model.cc
index 4370e63..97d269c 100644
--- a/chrome/browser/notifications/notification_options_menu_model.cc
+++ b/chrome/browser/notifications/notification_options_menu_model.cc
@@ -10,7 +10,6 @@
#include "chrome/browser/browser_list.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
-#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notifications_prefs_cache.h"
#include "chrome/browser/profile.h"
#include "chrome/common/content_settings_types.h"
diff --git a/chrome/browser/notifications/notification_test_util.h b/chrome/browser/notifications/notification_test_util.h
index fbaec4e..4cbf600 100644
--- a/chrome/browser/notifications/notification_test_util.h
+++ b/chrome/browser/notifications/notification_test_util.h
@@ -6,8 +6,6 @@
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_
#pragma once
-#include <string>
-
#include "chrome/browser/notifications/notification_object_proxy.h"
#include "chrome/browser/notifications/balloon.h"
#include "gfx/size.h"
@@ -16,7 +14,7 @@
// the notification events are not important.
class MockNotificationDelegate : public NotificationDelegate {
public:
- explicit MockNotificationDelegate(const std::string& id) : id_(id) {}
+ explicit MockNotificationDelegate(std::string id) : id_(id) {}
virtual ~MockNotificationDelegate() {}
// NotificationDelegate interface.
@@ -28,8 +26,6 @@ class MockNotificationDelegate : public NotificationDelegate {
private:
std::string id_;
-
- DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate);
};
// Mock implementation of Javascript object proxy which logs events that
@@ -39,11 +35,10 @@ class MockNotificationDelegate : public NotificationDelegate {
// |Logger| class provided in template must implement method
// static void log(string);
template<class Logger>
-class LoggingNotificationDelegate : public NotificationDelegate {
+class LoggingNotificationProxyBase : public NotificationObjectProxy {
public:
- explicit LoggingNotificationDelegate(std::string id)
- : notification_id_(id) {
- }
+ LoggingNotificationProxyBase() :
+ NotificationObjectProxy(0, 0, 0, false) {}
// NotificationObjectProxy override
virtual void Display() {
@@ -52,22 +47,12 @@ class LoggingNotificationDelegate : public NotificationDelegate {
virtual void Error() {
Logger::log("notification error\n");
}
- virtual void Click() {
- Logger::log("notification clicked\n");
- }
virtual void Close(bool by_user) {
if (by_user)
Logger::log("notification closed by user\n");
else
Logger::log("notification closed by script\n");
}
- virtual std::string id() const {
- return notification_id_;
- }
- private:
- std::string notification_id_;
-
- DISALLOW_COPY_AND_ASSIGN(LoggingNotificationDelegate);
};
// Test version of a balloon view which doesn't do anything
diff --git a/chrome/browser/notifications/notification_ui_manager.cc b/chrome/browser/notifications/notification_ui_manager.cc
index 27f7626..adc44cf 100644
--- a/chrome/browser/notifications/notification_ui_manager.cc
+++ b/chrome/browser/notifications/notification_ui_manager.cc
@@ -66,34 +66,17 @@ void NotificationUIManager::Add(const Notification& notification,
CheckAndShowNotifications();
}
-bool NotificationUIManager::CancelById(const std::string& id) {
- // See if this ID hasn't been shown yet.
+bool NotificationUIManager::Cancel(const Notification& notification) {
+ // First look through the notifications that haven't been shown. If not
+ // found there, call to the active balloon collection to tear it down.
NotificationDeque::iterator iter;
for (iter = show_queue_.begin(); iter != show_queue_.end(); ++iter) {
- if ((*iter)->notification().notification_id() == id) {
+ if (notification.IsSame((*iter)->notification())) {
show_queue_.erase(iter);
return true;
}
}
- // If it has been shown, remove it from the balloon collections.
- return balloon_collection_->RemoveById(id);
-}
-
-bool NotificationUIManager::CancelAllBySourceOrigin(const GURL& source) {
- // Same pattern as CancelById, but more complicated than the above
- // because there may be multiple notifications from the same source.
- bool removed = false;
- NotificationDeque::iterator iter;
- for (iter = show_queue_.begin(); iter != show_queue_.end(); ++iter) {
- if ((*iter)->notification().origin_url() == source) {
- iter = show_queue_.erase(iter);
- removed = true;
- } else {
- ++iter;
- }
- }
-
- return balloon_collection_->RemoveBySourceOrigin(source) || removed;
+ return balloon_collection_->Remove(notification);
}
void NotificationUIManager::CheckAndShowNotifications() {
diff --git a/chrome/browser/notifications/notification_ui_manager.h b/chrome/browser/notifications/notification_ui_manager.h
index 6d46198..10687a9 100644
--- a/chrome/browser/notifications/notification_ui_manager.h
+++ b/chrome/browser/notifications/notification_ui_manager.h
@@ -7,7 +7,6 @@
#pragma once
#include <deque>
-#include <string>
#include "base/id_map.h"
#include "base/scoped_ptr.h"
@@ -44,14 +43,8 @@ class NotificationUIManager
virtual void Add(const Notification& notification,
Profile* profile);
- // Removes any notifications matching the supplied ID, either currently
- // displayed or in the queue. Returns true if anything was removed.
- virtual bool CancelById(const std::string& notification_id);
-
- // Removes any notifications matching the supplied source origin
- // (which could be an extension ID), either currently displayed or in the
- // queue. Returns true if anything was removed.
- virtual bool CancelAllBySourceOrigin(const GURL& source_origin);
+ // Removes a notification.
+ virtual bool Cancel(const Notification& notification);
// Returns balloon collection.
BalloonCollection* balloon_collection() {
diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc
index c27b1a3..9607e3f 100644
--- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc
+++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc
@@ -124,8 +124,9 @@ void CloudPrintProxyService::OnTokenExpiredNotificationClick() {
void CloudPrintProxyService::TokenExpiredNotificationDone(bool keep_alive) {
if (token_expired_delegate_.get()) {
- g_browser_process->notification_ui_manager()->CancelById(
- token_expired_delegate_->id());
+ g_browser_process->notification_ui_manager()->Cancel(
+ Notification(GURL(), GURL(), string16(), string16(),
+ token_expired_delegate_.get()));
token_expired_delegate_ = NULL;
if (!keep_alive)
BrowserList::EndKeepAlive();
diff --git a/chrome/browser/task_manager/task_manager_browsertest.cc b/chrome/browser/task_manager/task_manager_browsertest.cc
index bc2655a..91cc23d 100644
--- a/chrome/browser/task_manager/task_manager_browsertest.cc
+++ b/chrome/browser/task_manager/task_manager_browsertest.cc
@@ -12,7 +12,6 @@
#include "chrome/browser/extensions/crashed_extension_infobar.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
-#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/profile.h"
@@ -201,9 +200,9 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeNotificationChanges) {
WaitForResourceChange(3);
notifications->Add(n2, browser()->profile());
WaitForResourceChange(4);
- notifications->CancelById(n1.notification_id());
+ notifications->Cancel(n1);
WaitForResourceChange(3);
- notifications->CancelById(n2.notification_id());
+ notifications->Cancel(n2);
WaitForResourceChange(2);
}
diff --git a/chrome/browser/ui/views/extensions/extension_view.cc b/chrome/browser/ui/views/extensions/extension_view.cc
index 99cf2eb..fcace1a 100644
--- a/chrome/browser/ui/views/extensions/extension_view.cc
+++ b/chrome/browser/ui/views/extensions/extension_view.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/views/extensions/extension_view.h"
+#include "chrome/browser/views/extensions/extension_view.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index c3fd530..d7a8920 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
+#include "chrome/browser/views/location_bar/location_bar_view.h"
#if defined(OS_LINUX)
#include <gtk/gtk.h>
diff --git a/chrome/browser/ui/views/notifications/balloon_view.cc b/chrome/browser/ui/views/notifications/balloon_view.cc
index d2696d4..c394b9a 100644
--- a/chrome/browser/ui/views/notifications/balloon_view.cc
+++ b/chrome/browser/ui/views/notifications/balloon_view.cc
@@ -14,7 +14,6 @@
#include "chrome/browser/notifications/balloon.h"
#include "chrome/browser/notifications/balloon_collection.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
-#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_options_menu_model.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 433eaee..2a81da5 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2299,8 +2299,6 @@
'browser/notifications/balloon_host.cc',
'browser/notifications/balloon_collection.cc',
'browser/notifications/balloon_collection.h',
- 'browser/notifications/balloon_collection_base.cc',
- 'browser/notifications/balloon_collection_base.h',
'browser/notifications/balloon_collection_impl.h',
'browser/notifications/balloon_collection_win.cc',
'browser/notifications/balloon_collection_mac.mm',