| 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();
|
| + }
|
| +}
|
|
|