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

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

Issue 342043: Connect the various pieces for notifications... hook up NotificationUIManager... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remove stale TODO Created 11 years, 2 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/browser/profile.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/notifications/notification_ui_manager.cc
===================================================================
--- chrome/browser/notifications/notification_ui_manager.cc (revision 0)
+++ chrome/browser/notifications/notification_ui_manager.cc (revision 0)
@@ -0,0 +1,77 @@
+// 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/stl_util-inl.h"
+#include "chrome/browser/notifications/balloon_collection.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/renderer_host/site_instance.h"
+
+// A class which represents a notification waiting to be shown.
+class QueuedNotification {
+ public:
+ QueuedNotification(const Notification& notification, Profile* profile)
+ : notification_(notification),
+ profile_(profile) {
+ }
+
+ const Notification& notification() const { return notification_; }
+ Profile* profile() const { return profile_; }
+
+ private:
+ // The notification to be shown.
+ Notification notification_;
+
+ // Non owned pointer to the user's profile.
+ Profile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(QueuedNotification);
+};
+
+NotificationUIManager::NotificationUIManager()
+ : balloon_collection_(NULL) {
+}
+
+NotificationUIManager::~NotificationUIManager() {
+ STLDeleteElements(&show_queue_);
+}
+
+// static
+NotificationUIManager* NotificationUIManager::Create() {
+ BalloonCollectionImpl* balloons = new BalloonCollectionImpl();
+ NotificationUIManager* instance = new NotificationUIManager();
+ instance->Initialize(balloons);
+ balloons->set_space_change_listener(instance);
+ return instance;
+}
+
+void NotificationUIManager::Add(const Notification& notification,
+ Profile* profile) {
+ LOG(INFO) << "Added notification. URL: "
+ << notification.content_url().spec().c_str();
+ show_queue_.push_back(
+ new QueuedNotification(notification, profile));
+ CheckAndShowNotifications();
+}
+
+void NotificationUIManager::CheckAndShowNotifications() {
+ // TODO(johnnyg): http://crbug.com/25061 - Check for user idle/presentation.
+ ShowNotifications();
+}
+
+void NotificationUIManager::ShowNotifications() {
+ while (!show_queue_.empty() && balloon_collection_->HasSpace()) {
+ scoped_ptr<QueuedNotification> queued_notification(show_queue_.front());
+ show_queue_.pop_front();
+ balloon_collection_->Add(queued_notification->notification(),
+ queued_notification->profile());
+ }
+}
+
+void NotificationUIManager::OnBalloonSpaceChanged() {
+ CheckAndShowNotifications();
+}
Property changes on: chrome\browser\notifications\notification_ui_manager.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/notifications/notification_ui_manager.h ('k') | chrome/browser/profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698