Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2648)

Unified Diff: chrome/browser/notifications/notification_ui_manager_win.cc

Issue 208068: Desktop Notifications UI (for windows) (Closed)
Patch Set: Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/notifications/notification_ui_manager.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/notifications/notification_ui_manager_win.cc
diff --git a/chrome/browser/notifications/notification_ui_manager_win.cc b/chrome/browser/notifications/notification_ui_manager_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d6687161abeaa193221ec0dd2efe4196c54fba4a
--- /dev/null
+++ b/chrome/browser/notifications/notification_ui_manager_win.cc
@@ -0,0 +1,101 @@
+// Copyright (c) 2009 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/notification_ui_manager.h"
+
+#include "base/logging.h"
+#include "base/scoped_ptr.h"
+#include "base/singleton.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/renderer_host/site_instance.h"
+
+class QueuedNotification {
+ public:
+ QueuedNotification(const Notification& notification,
+ Profile* profile,
+ SiteInstance* site_instance)
+ : notification_(notification),
+ profile_(profile),
+ site_instance_(site_instance) {
+ }
+
+ const Notification& notification() const {
+ return notification_;
+ }
+
+ Profile* profile() const {
+ return profile_;
+ }
+
+ SiteInstance* site_instance() const {
+ return site_instance_;
+ }
+
+ private:
+ Notification notification_;
+ Profile* profile_;
+ SiteInstance* site_instance_;
+ DISALLOW_COPY_AND_ASSIGN(QueuedNotification);
+};
+
+void Clear(NotificationDeque* notifications) {
+ while (!notifications->empty()) {
+ NotificationDeque::reverse_iterator it =
+ notifications->rbegin();
+ QueuedNotification* removed = *it;
+ notifications->pop_back();
+ delete removed;
+ }
+}
+
+// static
+NotificationUIManager* NotificationUIManager::Create() {
+ BalloonCollection* collection = new BalloonCollection();
+ NotificationUIManager* instance = new NotificationUIManager();
+ instance->Initialize(collection);
+ collection->AddObserver(instance);
+ return instance;
+}
+
+void NotificationUIManager::Initialize(
+ BalloonCollectionInterface *balloon_collection) {
+ balloon_collection_.reset(balloon_collection);
+}
+
+NotificationUIManager::~NotificationUIManager() {
+ Clear(&show_queue_);
+}
+
+void NotificationUIManager::Add(const Notification& notification,
+ Profile* profile,
+ SiteInstance* site_instance) {
+ LOG(INFO) << "Added notification. URL: "
+ << notification.content_url().spec().c_str();
+ show_queue_.push_back(
+ new QueuedNotification(notification, profile, site_instance));
+ CheckAndShowNotifications();
+}
+
+void NotificationUIManager::CheckAndShowNotifications() {
+ // TODO(johnnyg): check for screen-saver / presentation mode
+ ShowNotifications();
+}
+
+void NotificationUIManager::ShowNotifications() {
+ while (!show_queue_.empty() && balloon_collection_->HasSpace()) {
+ QueuedNotification* queued_notification = show_queue_.front();
+ show_queue_.pop_front();
+ balloon_collection_->Add(queued_notification->notification(),
+ queued_notification->profile(),
+ queued_notification->site_instance());
+ delete queued_notification;
+ }
+}
+
+void NotificationUIManager::OnBalloonSpaceChanged() {
+ CheckAndShowNotifications();
+ if (balloons_observer_) {
+ balloons_observer_->OnBalloonSpaceChanged();
+ }
+}
« no previous file with comments | « chrome/browser/notifications/notification_ui_manager.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698