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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/notifications/notification_ui_manager.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/notifications/notification_ui_manager.h"
6
7 #include "base/logging.h"
8 #include "base/scoped_ptr.h"
9 #include "base/singleton.h"
10 #include "chrome/browser/notifications/notification.h"
11 #include "chrome/browser/renderer_host/site_instance.h"
12
13 class QueuedNotification {
14 public:
15 QueuedNotification(const Notification& notification,
16 Profile* profile,
17 SiteInstance* site_instance)
18 : notification_(notification),
19 profile_(profile),
20 site_instance_(site_instance) {
21 }
22
23 const Notification& notification() const {
24 return notification_;
25 }
26
27 Profile* profile() const {
28 return profile_;
29 }
30
31 SiteInstance* site_instance() const {
32 return site_instance_;
33 }
34
35 private:
36 Notification notification_;
37 Profile* profile_;
38 SiteInstance* site_instance_;
39 DISALLOW_COPY_AND_ASSIGN(QueuedNotification);
40 };
41
42 void Clear(NotificationDeque* notifications) {
43 while (!notifications->empty()) {
44 NotificationDeque::reverse_iterator it =
45 notifications->rbegin();
46 QueuedNotification* removed = *it;
47 notifications->pop_back();
48 delete removed;
49 }
50 }
51
52 // static
53 NotificationUIManager* NotificationUIManager::Create() {
54 BalloonCollection* collection = new BalloonCollection();
55 NotificationUIManager* instance = new NotificationUIManager();
56 instance->Initialize(collection);
57 collection->AddObserver(instance);
58 return instance;
59 }
60
61 void NotificationUIManager::Initialize(
62 BalloonCollectionInterface *balloon_collection) {
63 balloon_collection_.reset(balloon_collection);
64 }
65
66 NotificationUIManager::~NotificationUIManager() {
67 Clear(&show_queue_);
68 }
69
70 void NotificationUIManager::Add(const Notification& notification,
71 Profile* profile,
72 SiteInstance* site_instance) {
73 LOG(INFO) << "Added notification. URL: "
74 << notification.content_url().spec().c_str();
75 show_queue_.push_back(
76 new QueuedNotification(notification, profile, site_instance));
77 CheckAndShowNotifications();
78 }
79
80 void NotificationUIManager::CheckAndShowNotifications() {
81 // TODO(johnnyg): check for screen-saver / presentation mode
82 ShowNotifications();
83 }
84
85 void NotificationUIManager::ShowNotifications() {
86 while (!show_queue_.empty() && balloon_collection_->HasSpace()) {
87 QueuedNotification* queued_notification = show_queue_.front();
88 show_queue_.pop_front();
89 balloon_collection_->Add(queued_notification->notification(),
90 queued_notification->profile(),
91 queued_notification->site_instance());
92 delete queued_notification;
93 }
94 }
95
96 void NotificationUIManager::OnBalloonSpaceChanged() {
97 CheckAndShowNotifications();
98 if (balloons_observer_) {
99 balloons_observer_->OnBalloonSpaceChanged();
100 }
101 }
OLDNEW
« 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