OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/message_center/notification_list.h" | 5 #include "ui/message_center/notification_list.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 void NotificationList::GetPopupNotifications( | 228 void NotificationList::GetPopupNotifications( |
229 NotificationList::Notifications* notifications) { | 229 NotificationList::Notifications* notifications) { |
230 typedef std::pair<Notifications::iterator, Notifications::iterator> | 230 typedef std::pair<Notifications::iterator, Notifications::iterator> |
231 NotificationRange; | 231 NotificationRange; |
232 // In the popup, latest should come earlier. | 232 // In the popup, latest should come earlier. |
233 std::list<NotificationRange> iters; | 233 std::list<NotificationRange> iters; |
234 for (int i = ui::notifications::DEFAULT_PRIORITY; | 234 for (int i = ui::notifications::DEFAULT_PRIORITY; |
235 i <= ui::notifications::MAX_PRIORITY; ++i) { | 235 i <= ui::notifications::MAX_PRIORITY; ++i) { |
236 Notifications::iterator first, last; | 236 Notifications::iterator first, last; |
237 GetPopupIterators(i, first, last); | 237 GetPopupIterators(i, &first, &last); |
238 if (first != last) | 238 if (first != last) |
239 iters.push_back(make_pair(first, last)); | 239 iters.push_back(make_pair(first, last)); |
240 } | 240 } |
241 notifications->clear(); | 241 notifications->clear(); |
242 while (!iters.empty()) { | 242 while (!iters.empty()) { |
243 std::list<NotificationRange>::iterator max_iter = iters.begin(); | 243 std::list<NotificationRange>::iterator max_iter = iters.begin(); |
244 std::list<NotificationRange>::iterator iter = max_iter; | 244 std::list<NotificationRange>::iterator iter = max_iter; |
245 iter++; | 245 iter++; |
246 for (; iter != iters.end(); ++iter) { | 246 for (; iter != iters.end(); ++iter) { |
247 if (max_iter->first->timestamp < iter->first->timestamp) | 247 if (max_iter->first->timestamp < iter->first->timestamp) |
248 max_iter = iter; | 248 max_iter = iter; |
249 } | 249 } |
250 notifications->push_back(*(max_iter->first)); | 250 notifications->push_back(*(max_iter->first)); |
251 ++(max_iter->first); | 251 ++(max_iter->first); |
252 if (max_iter->first == max_iter->second) | 252 if (max_iter->first == max_iter->second) |
253 iters.erase(max_iter); | 253 iters.erase(max_iter); |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 void NotificationList::MarkPopupsAsShown(int priority) { | 257 void NotificationList::MarkPopupsAsShown(int priority) { |
258 Notifications::iterator first, last; | 258 Notifications::iterator first, last; |
259 GetPopupIterators(priority, first, last); | 259 GetPopupIterators(priority, &first, &last); |
260 for (Notifications::iterator iter = first; iter != last; ++iter) | 260 for (Notifications::iterator iter = first; iter != last; ++iter) |
261 iter->shown_as_popup = true; | 261 iter->shown_as_popup = true; |
262 } | 262 } |
263 | 263 |
264 void NotificationList::SetQuietMode(bool quiet_mode) { | 264 void NotificationList::SetQuietMode(bool quiet_mode) { |
265 SetQuietModeInternal(quiet_mode); | 265 SetQuietModeInternal(quiet_mode); |
266 quiet_mode_timer_.reset(); | 266 quiet_mode_timer_.reset(); |
267 } | 267 } |
268 | 268 |
269 void NotificationList::EnterQuietModeWithExpire( | 269 void NotificationList::EnterQuietModeWithExpire( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 if (notification.priority > ui::notifications::MIN_PRIORITY) | 360 if (notification.priority > ui::notifications::MIN_PRIORITY) |
361 ++unread_count_; | 361 ++unread_count_; |
362 notification.is_read = false; | 362 notification.is_read = false; |
363 notification.shown_as_popup = false; | 363 notification.shown_as_popup = false; |
364 } | 364 } |
365 } | 365 } |
366 notifications_[notification.priority].push_front(notification); | 366 notifications_[notification.priority].push_front(notification); |
367 } | 367 } |
368 | 368 |
369 void NotificationList::GetPopupIterators(int priority, | 369 void NotificationList::GetPopupIterators(int priority, |
370 Notifications::iterator& first, | 370 Notifications::iterator* first, |
371 Notifications::iterator& last) { | 371 Notifications::iterator* last) { |
372 Notifications& notifications = notifications_[priority]; | 372 Notifications& notifications = notifications_[priority]; |
373 // No popups for LOW/MIN priority. | 373 // No popups for LOW/MIN priority. |
374 if (priority < ui::notifications::DEFAULT_PRIORITY) { | 374 if (priority < ui::notifications::DEFAULT_PRIORITY) { |
375 first = notifications.end(); | 375 *first = notifications.end(); |
376 last = notifications.end(); | 376 *last = notifications.end(); |
377 return; | 377 return; |
378 } | 378 } |
379 | 379 |
380 size_t popup_count = 0; | 380 size_t popup_count = 0; |
381 first = notifications.begin(); | 381 *first = notifications.begin(); |
382 last = first; | 382 *last = *first; |
383 while (last != notifications.end()) { | 383 while (*last != notifications.end()) { |
384 if (last->shown_as_popup) | 384 if ((*last)->shown_as_popup) |
385 break; | 385 break; |
386 ++last; | 386 ++(*last); |
387 popup_count++; | 387 |
388 // No limits for HIGH/MAX priority. | 388 // Checking limits. No limits for HIGH/MAX priority. DEFAULT priority |
| 389 // will return at most kMaxVisiblePopupNotifications entries. If the |
| 390 // popup entries are more, older entries are used. see crbug.com/165768 |
389 if (priority == ui::notifications::DEFAULT_PRIORITY && | 391 if (priority == ui::notifications::DEFAULT_PRIORITY && |
390 popup_count >= kMaxVisiblePopupNotifications) { | 392 popup_count >= kMaxVisiblePopupNotifications) { |
391 break; | 393 ++(*first); |
| 394 } else { |
| 395 ++popup_count; |
392 } | 396 } |
393 } | 397 } |
394 } | 398 } |
395 | 399 |
396 } // namespace message_center | 400 } // namespace message_center |
OLD | NEW |