| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 59     return; | 59     return; | 
| 60   } | 60   } | 
| 61 | 61 | 
| 62   VLOG(1) << "Added notification. URL: " | 62   VLOG(1) << "Added notification. URL: " | 
| 63           << notification.content_url().spec(); | 63           << notification.content_url().spec(); | 
| 64   show_queue_.push_back( | 64   show_queue_.push_back( | 
| 65       new QueuedNotification(notification, profile)); | 65       new QueuedNotification(notification, profile)); | 
| 66   CheckAndShowNotifications(); | 66   CheckAndShowNotifications(); | 
| 67 } | 67 } | 
| 68 | 68 | 
| 69 bool NotificationUIManager::Cancel(const Notification& notification) { | 69 bool NotificationUIManager::CancelById(const std::string& id) { | 
| 70   // First look through the notifications that haven't been shown.  If not | 70   // See if this ID hasn't been shown yet. | 
| 71   // found there, call to the active balloon collection to tear it down. |  | 
| 72   NotificationDeque::iterator iter; | 71   NotificationDeque::iterator iter; | 
| 73   for (iter = show_queue_.begin(); iter != show_queue_.end(); ++iter) { | 72   for (iter = show_queue_.begin(); iter != show_queue_.end(); ++iter) { | 
| 74     if (notification.IsSame((*iter)->notification())) { | 73     if ((*iter)->notification().notification_id() == id) { | 
| 75       show_queue_.erase(iter); | 74       show_queue_.erase(iter); | 
| 76       return true; | 75       return true; | 
| 77     } | 76     } | 
| 78   } | 77   } | 
| 79   return balloon_collection_->Remove(notification); | 78   // If it has been shown, remove it from the balloon collections. | 
|  | 79   return balloon_collection_->RemoveById(id); | 
|  | 80 } | 
|  | 81 | 
|  | 82 bool NotificationUIManager::CancelAllBySourceOrigin(const GURL& source) { | 
|  | 83   // Same pattern as CancelById, but more complicated than the above | 
|  | 84   // because there may be multiple notifications from the same source. | 
|  | 85   bool removed = false; | 
|  | 86   NotificationDeque::iterator iter; | 
|  | 87   for (iter = show_queue_.begin(); iter != show_queue_.end(); ++iter) { | 
|  | 88     if ((*iter)->notification().origin_url() == source) { | 
|  | 89       iter = show_queue_.erase(iter); | 
|  | 90       removed = true; | 
|  | 91     } else { | 
|  | 92       ++iter; | 
|  | 93     } | 
|  | 94   } | 
|  | 95 | 
|  | 96   return balloon_collection_->RemoveBySourceOrigin(source) || removed; | 
| 80 } | 97 } | 
| 81 | 98 | 
| 82 void NotificationUIManager::CheckAndShowNotifications() { | 99 void NotificationUIManager::CheckAndShowNotifications() { | 
| 83   // TODO(johnnyg): http://crbug.com/25061 - Check for user idle/presentation. | 100   // TODO(johnnyg): http://crbug.com/25061 - Check for user idle/presentation. | 
| 84   ShowNotifications(); | 101   ShowNotifications(); | 
| 85 } | 102 } | 
| 86 | 103 | 
| 87 void NotificationUIManager::ShowNotifications() { | 104 void NotificationUIManager::ShowNotifications() { | 
| 88   while (!show_queue_.empty() && balloon_collection_->HasSpace()) { | 105   while (!show_queue_.empty() && balloon_collection_->HasSpace()) { | 
| 89     scoped_ptr<QueuedNotification> queued_notification(show_queue_.front()); | 106     scoped_ptr<QueuedNotification> queued_notification(show_queue_.front()); | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 123        ++balloon_iter) { | 140        ++balloon_iter) { | 
| 124     if (origin == (*balloon_iter)->notification().origin_url() && | 141     if (origin == (*balloon_iter)->notification().origin_url() && | 
| 125         replace_id == (*balloon_iter)->notification().replace_id()) { | 142         replace_id == (*balloon_iter)->notification().replace_id()) { | 
| 126       (*balloon_iter)->Update(notification); | 143       (*balloon_iter)->Update(notification); | 
| 127       return true; | 144       return true; | 
| 128     } | 145     } | 
| 129   } | 146   } | 
| 130 | 147 | 
| 131   return false; | 148   return false; | 
| 132 } | 149 } | 
| OLD | NEW | 
|---|