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

Side by Side Diff: ui/message_center/notification_list.cc

Issue 11229022: Move ash/system/web_notification message_center to ui/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again. Created 8 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
« no previous file with comments | « ui/message_center/notification_list.h ('k') | ui/resources/ui_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/system/web_notification/web_notification_list.h" 5 #include "ui/message_center/notification_list.h"
6 6
7 namespace message_center { 7 namespace message_center {
8 8
9 const size_t WebNotificationList::kMaxVisibleMessageCenterNotifications = 100; 9 const size_t NotificationList::kMaxVisibleMessageCenterNotifications = 100;
10 const size_t WebNotificationList::kMaxVisiblePopupNotifications = 5; 10 const size_t NotificationList::kMaxVisiblePopupNotifications = 5;
11 11
12 WebNotificationList::WebNotificationList(Delegate* delegate) 12 NotificationList::Notification::Notification() : is_read(false),
13 shown_as_popup(false) {
14 }
15
16 NotificationList::Notification::~Notification() {
17 }
18
19 NotificationList::NotificationList(Delegate* delegate)
13 : delegate_(delegate), 20 : delegate_(delegate),
14 message_center_visible_(false), 21 message_center_visible_(false),
15 unread_count_(0) { 22 unread_count_(0) {
16 } 23 }
17 24
18 WebNotificationList::~WebNotificationList() { 25 NotificationList::~NotificationList() {
19 } 26 }
20 27
21 void WebNotificationList::SetMessageCenterVisible(bool visible) { 28 void NotificationList::SetMessageCenterVisible(bool visible) {
22 if (message_center_visible_ == visible) 29 if (message_center_visible_ == visible)
23 return; 30 return;
24 message_center_visible_ = visible; 31 message_center_visible_ = visible;
25 if (!visible) { 32 if (!visible) {
26 // When the list is hidden, clear the unread count, and mark all 33 // When the list is hidden, clear the unread count, and mark all
27 // notifications as read and shown. 34 // notifications as read and shown.
28 unread_count_ = 0; 35 unread_count_ = 0;
29 for (Notifications::iterator iter = notifications_.begin(); 36 for (Notifications::iterator iter = notifications_.begin();
30 iter != notifications_.end(); ++iter) { 37 iter != notifications_.end(); ++iter) {
31 iter->is_read = true; 38 iter->is_read = true;
32 iter->shown_as_popup = true; 39 iter->shown_as_popup = true;
33 } 40 }
34 } 41 }
35 } 42 }
36 43
37 void WebNotificationList::AddNotification(const std::string& id, 44 void NotificationList::AddNotification(const std::string& id,
38 const string16& title, 45 const string16& title,
39 const string16& message, 46 const string16& message,
40 const string16& display_source, 47 const string16& display_source,
41 const std::string& extension_id) { 48 const std::string& extension_id) {
42 WebNotification notification; 49 Notification notification;
43 notification.id = id; 50 notification.id = id;
44 notification.title = title; 51 notification.title = title;
45 notification.message = message; 52 notification.message = message;
46 notification.display_source = display_source; 53 notification.display_source = display_source;
47 notification.extension_id = extension_id; 54 notification.extension_id = extension_id;
48 PushNotification(notification); 55 PushNotification(notification);
49 } 56 }
50 57
51 void WebNotificationList::UpdateNotificationMessage(const std::string& old_id, 58 void NotificationList::UpdateNotificationMessage(const std::string& old_id,
52 const std::string& new_id, 59 const std::string& new_id,
53 const string16& title, 60 const string16& title,
54 const string16& message) { 61 const string16& message) {
55 Notifications::iterator iter = GetNotification(old_id); 62 Notifications::iterator iter = GetNotification(old_id);
56 if (iter == notifications_.end()) 63 if (iter == notifications_.end())
57 return; 64 return;
58 // Copy and update notification, then move it to the front of the list. 65 // Copy and update notification, then move it to the front of the list.
59 WebNotification notification(*iter); 66 Notification notification(*iter);
60 notification.id = new_id; 67 notification.id = new_id;
61 notification.title = title; 68 notification.title = title;
62 notification.message = message; 69 notification.message = message;
63 EraseNotification(iter); 70 EraseNotification(iter);
64 PushNotification(notification); 71 PushNotification(notification);
65 } 72 }
66 73
67 bool WebNotificationList::RemoveNotification(const std::string& id) { 74 bool NotificationList::RemoveNotification(const std::string& id) {
68 Notifications::iterator iter = GetNotification(id); 75 Notifications::iterator iter = GetNotification(id);
69 if (iter == notifications_.end()) 76 if (iter == notifications_.end())
70 return false; 77 return false;
71 EraseNotification(iter); 78 EraseNotification(iter);
72 return true; 79 return true;
73 } 80 }
74 81
75 void WebNotificationList::RemoveAllNotifications() { 82 void NotificationList::RemoveAllNotifications() {
76 notifications_.clear(); 83 notifications_.clear();
77 } 84 }
78 85
79 void WebNotificationList::SendRemoveNotificationsBySource( 86 void NotificationList::SendRemoveNotificationsBySource(
80 const std::string& id) { 87 const std::string& id) {
81 Notifications::iterator source_iter = GetNotification(id); 88 Notifications::iterator source_iter = GetNotification(id);
82 if (source_iter == notifications_.end()) 89 if (source_iter == notifications_.end())
83 return; 90 return;
84 string16 display_source = source_iter->display_source; 91 string16 display_source = source_iter->display_source;
85 for (Notifications::iterator loopiter = notifications_.begin(); 92 for (Notifications::iterator loopiter = notifications_.begin();
86 loopiter != notifications_.end(); ) { 93 loopiter != notifications_.end(); ) {
87 Notifications::iterator curiter = loopiter++; 94 Notifications::iterator curiter = loopiter++;
88 if (curiter->display_source == display_source) 95 if (curiter->display_source == display_source)
89 delegate_->SendRemoveNotification(curiter->id); 96 delegate_->SendRemoveNotification(curiter->id);
90 } 97 }
91 } 98 }
92 99
93 void WebNotificationList::SendRemoveNotificationsByExtension( 100 void NotificationList::SendRemoveNotificationsByExtension(
94 const std::string& id) { 101 const std::string& id) {
95 Notifications::iterator source_iter = GetNotification(id); 102 Notifications::iterator source_iter = GetNotification(id);
96 if (source_iter == notifications_.end()) 103 if (source_iter == notifications_.end())
97 return; 104 return;
98 std::string extension_id = source_iter->extension_id; 105 std::string extension_id = source_iter->extension_id;
99 for (Notifications::iterator loopiter = notifications_.begin(); 106 for (Notifications::iterator loopiter = notifications_.begin();
100 loopiter != notifications_.end(); ) { 107 loopiter != notifications_.end(); ) {
101 Notifications::iterator curiter = loopiter++; 108 Notifications::iterator curiter = loopiter++;
102 if (curiter->extension_id == extension_id) 109 if (curiter->extension_id == extension_id)
103 delegate_->SendRemoveNotification(curiter->id); 110 delegate_->SendRemoveNotification(curiter->id);
104 } 111 }
105 } 112 }
106 113
107 bool WebNotificationList::SetNotificationImage(const std::string& id, 114 bool NotificationList::SetNotificationImage(const std::string& id,
108 const gfx::ImageSkia& image) { 115 const gfx::ImageSkia& image) {
109 Notifications::iterator iter = GetNotification(id); 116 Notifications::iterator iter = GetNotification(id);
110 if (iter == notifications_.end()) 117 if (iter == notifications_.end())
111 return false; 118 return false;
112 iter->image = image; 119 iter->image = image;
113 return true; 120 return true;
114 } 121 }
115 122
116 bool WebNotificationList::HasNotification(const std::string& id) { 123 bool NotificationList::HasNotification(const std::string& id) {
117 return GetNotification(id) != notifications_.end(); 124 return GetNotification(id) != notifications_.end();
118 } 125 }
119 126
120 bool WebNotificationList::HasPopupNotifications() { 127 bool NotificationList::HasPopupNotifications() {
121 return !notifications_.empty() && !notifications_.front().shown_as_popup; 128 return !notifications_.empty() && !notifications_.front().shown_as_popup;
122 } 129 }
123 130
124 void WebNotificationList::GetPopupNotifications( 131 void NotificationList::GetPopupNotifications(
125 WebNotificationList::Notifications* notifications) { 132 NotificationList::Notifications* notifications) {
126 Notifications::iterator first, last; 133 Notifications::iterator first, last;
127 GetPopupIterators(first, last); 134 GetPopupIterators(first, last);
128 notifications->clear(); 135 notifications->clear();
129 for (Notifications::iterator iter = first; iter != last; ++iter) 136 for (Notifications::iterator iter = first; iter != last; ++iter)
130 notifications->push_back(*iter); 137 notifications->push_back(*iter);
131 } 138 }
132 139
133 void WebNotificationList::MarkPopupsAsShown() { 140 void NotificationList::MarkPopupsAsShown() {
134 Notifications::iterator first, last; 141 Notifications::iterator first, last;
135 GetPopupIterators(first, last); 142 GetPopupIterators(first, last);
136 for (Notifications::iterator iter = first; iter != last; ++iter) 143 for (Notifications::iterator iter = first; iter != last; ++iter)
137 iter->shown_as_popup = true; 144 iter->shown_as_popup = true;
138 } 145 }
139 146
140 WebNotificationList::Notifications::iterator 147 NotificationList::Notifications::iterator NotificationList::GetNotification(
141 WebNotificationList::GetNotification(
142 const std::string& id) { 148 const std::string& id) {
143 for (Notifications::iterator iter = notifications_.begin(); 149 for (Notifications::iterator iter = notifications_.begin();
144 iter != notifications_.end(); ++iter) { 150 iter != notifications_.end(); ++iter) {
145 if (iter->id == id) 151 if (iter->id == id)
146 return iter; 152 return iter;
147 } 153 }
148 return notifications_.end(); 154 return notifications_.end();
149 } 155 }
150 156
151 void WebNotificationList::EraseNotification( 157 void NotificationList::EraseNotification(Notifications::iterator iter) {
152 WebNotificationList::Notifications::iterator iter) {
153 if (!message_center_visible_ && !iter->is_read) 158 if (!message_center_visible_ && !iter->is_read)
154 --unread_count_; 159 --unread_count_;
155 notifications_.erase(iter); 160 notifications_.erase(iter);
156 } 161 }
157 162
158 void WebNotificationList::PushNotification(WebNotification& notification) { 163 void NotificationList::PushNotification(Notification& notification) {
159 // Ensure that notification.id is unique by erasing any existing 164 // Ensure that notification.id is unique by erasing any existing
160 // notification with the same id (shouldn't normally happen). 165 // notification with the same id (shouldn't normally happen).
161 Notifications::iterator iter = GetNotification(notification.id); 166 Notifications::iterator iter = GetNotification(notification.id);
162 if (iter != notifications_.end()) 167 if (iter != notifications_.end())
163 EraseNotification(iter); 168 EraseNotification(iter);
164 // Add the notification to the front (top) of the list and mark it 169 // Add the notification to the front (top) of the list and mark it
165 // unread and unshown. 170 // unread and unshown.
166 if (!message_center_visible_) { 171 if (!message_center_visible_) {
167 ++unread_count_; 172 ++unread_count_;
168 notification.is_read = false; 173 notification.is_read = false;
169 notification.shown_as_popup = false; 174 notification.shown_as_popup = false;
170 } 175 }
171 notifications_.push_front(notification); 176 notifications_.push_front(notification);
172 } 177 }
173 178
174 void WebNotificationList::GetPopupIterators(Notifications::iterator& first, 179 void NotificationList::GetPopupIterators(Notifications::iterator& first,
175 Notifications::iterator& last) { 180 Notifications::iterator& last) {
176 size_t popup_count = 0; 181 size_t popup_count = 0;
177 first = notifications_.begin(); 182 first = notifications_.begin();
178 last = first; 183 last = first;
179 while (last != notifications_.end()) { 184 while (last != notifications_.end()) {
180 if (last->shown_as_popup) 185 if (last->shown_as_popup)
181 break; 186 break;
182 ++last; 187 ++last;
183 if (popup_count < kMaxVisiblePopupNotifications) 188 if (popup_count < kMaxVisiblePopupNotifications)
184 ++popup_count; 189 ++popup_count;
185 else 190 else
186 ++first; 191 ++first;
187 } 192 }
188 } 193 }
189 194
190 } // namespace message_center 195 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/notification_list.h ('k') | ui/resources/ui_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698