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

Side by Side Diff: chrome/browser/notifications/notification_ui_manager.cc

Issue 363003: Implement cancel() API on a Notification object so that script can cancel or ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/notifications/notification_ui_manager.h" 5 #include "chrome/browser/notifications/notification_ui_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "chrome/browser/notifications/balloon_collection.h" 10 #include "chrome/browser/notifications/balloon_collection.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 void NotificationUIManager::Add(const Notification& notification, 52 void NotificationUIManager::Add(const Notification& notification,
53 Profile* profile) { 53 Profile* profile) {
54 LOG(INFO) << "Added notification. URL: " 54 LOG(INFO) << "Added notification. URL: "
55 << notification.content_url().spec().c_str(); 55 << notification.content_url().spec().c_str();
56 show_queue_.push_back( 56 show_queue_.push_back(
57 new QueuedNotification(notification, profile)); 57 new QueuedNotification(notification, profile));
58 CheckAndShowNotifications(); 58 CheckAndShowNotifications();
59 } 59 }
60 60
61 bool NotificationUIManager::Cancel(const Notification& notification) {
62 // First look through the notifications that haven't been shown.
63 NotificationDeque::iterator iter;
64 for (iter = show_queue_.begin(); iter != show_queue_.end(); ++iter) {
65 if (notification.IsSame((*iter)->notification())) {
66 show_queue_.erase(iter);
67 return true;
68 }
69 }
70 return balloon_collection_->Remove(notification);
71 }
72
61 void NotificationUIManager::CheckAndShowNotifications() { 73 void NotificationUIManager::CheckAndShowNotifications() {
62 // TODO(johnnyg): http://crbug.com/25061 - Check for user idle/presentation. 74 // TODO(johnnyg): http://crbug.com/25061 - Check for user idle/presentation.
63 ShowNotifications(); 75 ShowNotifications();
64 } 76 }
65 77
66 void NotificationUIManager::ShowNotifications() { 78 void NotificationUIManager::ShowNotifications() {
67 while (!show_queue_.empty() && balloon_collection_->HasSpace()) { 79 while (!show_queue_.empty() && balloon_collection_->HasSpace()) {
68 scoped_ptr<QueuedNotification> queued_notification(show_queue_.front()); 80 scoped_ptr<QueuedNotification> queued_notification(show_queue_.front());
69 show_queue_.pop_front(); 81 show_queue_.pop_front();
70 balloon_collection_->Add(queued_notification->notification(), 82 balloon_collection_->Add(queued_notification->notification(),
71 queued_notification->profile()); 83 queued_notification->profile());
72 } 84 }
73 } 85 }
74 86
75 void NotificationUIManager::OnBalloonSpaceChanged() { 87 void NotificationUIManager::OnBalloonSpaceChanged() {
76 CheckAndShowNotifications(); 88 CheckAndShowNotifications();
77 } 89 }
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notification_ui_manager.h ('k') | chrome/browser/renderer_host/render_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698