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

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

Issue 11414215: Add CloseAllByProfile to NotificationUIManager and call before destroyng a Profile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac Created 8 years 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) 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 "chrome/browser/notifications/notification_ui_manager_impl.h" 5 #include "chrome/browser/notifications/notification_ui_manager_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 89
90 VLOG(1) << "Added notification. URL: " 90 VLOG(1) << "Added notification. URL: "
91 << notification.content_url().spec(); 91 << notification.content_url().spec();
92 show_queue_.push_back( 92 show_queue_.push_back(
93 new QueuedNotification(notification, profile)); 93 new QueuedNotification(notification, profile));
94 CheckAndShowNotifications(); 94 CheckAndShowNotifications();
95 } 95 }
96 96
97 bool NotificationUIManagerImpl::CancelById(const std::string& id) { 97 bool NotificationUIManagerImpl::CancelById(const std::string& id) {
98 // See if this ID hasn't been shown yet. 98 // See if this ID hasn't been shown yet.
99 NotificationDeque::iterator iter; 99 for (NotificationDeque::iterator iter = show_queue_.begin();
100 for (iter = show_queue_.begin(); iter != show_queue_.end(); ++iter) { 100 iter != show_queue_.end(); ++iter) {
101 if ((*iter)->notification().notification_id() == id) { 101 if ((*iter)->notification().notification_id() == id) {
102 show_queue_.erase(iter); 102 show_queue_.erase(iter);
103 return true; 103 return true;
104 } 104 }
105 } 105 }
106 // If it has been shown, remove it from the balloon collections. 106 // If it has been shown, remove it from the balloon collections.
107 return balloon_collection_->RemoveById(id); 107 return balloon_collection_->RemoveById(id);
108 } 108 }
109 109
110 bool NotificationUIManagerImpl::CancelAllBySourceOrigin(const GURL& source) { 110 bool NotificationUIManagerImpl::CancelAllBySourceOrigin(const GURL& source) {
111 // Same pattern as CancelById, but more complicated than the above 111 // Same pattern as CancelById, but more complicated than the above
112 // because there may be multiple notifications from the same source. 112 // because there may be multiple notifications from the same source.
113 bool removed = false; 113 bool removed = false;
114 NotificationDeque::iterator iter; 114 for (NotificationDeque::iterator loopiter = show_queue_.begin();
115 for (iter = show_queue_.begin(); iter != show_queue_.end();) { 115 loopiter != show_queue_.end(); ) {
116 if ((*iter)->notification().origin_url() == source) { 116 NotificationDeque::iterator curiter = loopiter++;
117 iter = show_queue_.erase(iter); 117 if ((*curiter)->notification().origin_url() == source) {
118 show_queue_.erase(curiter);
118 removed = true; 119 removed = true;
119 } else {
120 ++iter;
121 } 120 }
122 } 121 }
122 return balloon_collection_->RemoveBySourceOrigin(source) || removed;
123 }
123 124
124 return balloon_collection_->RemoveBySourceOrigin(source) || removed; 125 bool NotificationUIManagerImpl::CancelAllByProfile(Profile* profile) {
126 // Same pattern as CancelAllBySourceOrigin.
127 bool removed = false;
128 for (NotificationDeque::iterator loopiter = show_queue_.begin();
129 loopiter != show_queue_.end(); ) {
130 NotificationDeque::iterator curiter = loopiter++;
131 if ((*curiter)->profile() == profile) {
132 show_queue_.erase(curiter);
133 removed = true;
134 }
135 }
136 return balloon_collection_->RemoveByProfile(profile) || removed;
125 } 137 }
126 138
127 void NotificationUIManagerImpl::CancelAll() { 139 void NotificationUIManagerImpl::CancelAll() {
128 STLDeleteElements(&show_queue_); 140 STLDeleteElements(&show_queue_);
129 balloon_collection_->RemoveAll(); 141 balloon_collection_->RemoveAll();
130 } 142 }
131 143
132 BalloonCollection* NotificationUIManagerImpl::balloon_collection() { 144 BalloonCollection* NotificationUIManagerImpl::balloon_collection() {
133 return balloon_collection_.get(); 145 return balloon_collection_.get();
134 } 146 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 bool NotificationUIManagerImpl::TryReplacement( 190 bool NotificationUIManagerImpl::TryReplacement(
179 const Notification& notification) { 191 const Notification& notification) {
180 const GURL& origin = notification.origin_url(); 192 const GURL& origin = notification.origin_url();
181 const string16& replace_id = notification.replace_id(); 193 const string16& replace_id = notification.replace_id();
182 194
183 if (replace_id.empty()) 195 if (replace_id.empty())
184 return false; 196 return false;
185 197
186 // First check the queue of pending notifications for replacement. 198 // First check the queue of pending notifications for replacement.
187 // Then check the list of notifications already being shown. 199 // Then check the list of notifications already being shown.
188 NotificationDeque::iterator iter; 200 for (NotificationDeque::const_iterator iter = show_queue_.begin();
189 for (iter = show_queue_.begin(); iter != show_queue_.end(); ++iter) { 201 iter != show_queue_.end(); ++iter) {
190 if (origin == (*iter)->notification().origin_url() && 202 if (origin == (*iter)->notification().origin_url() &&
191 replace_id == (*iter)->notification().replace_id()) { 203 replace_id == (*iter)->notification().replace_id()) {
192 (*iter)->Replace(notification); 204 (*iter)->Replace(notification);
193 return true; 205 return true;
194 } 206 }
195 } 207 }
196 208
197 BalloonCollection::Balloons::iterator balloon_iter; 209 const BalloonCollection::Balloons& balloons =
198 BalloonCollection::Balloons balloons =
199 balloon_collection_->GetActiveBalloons(); 210 balloon_collection_->GetActiveBalloons();
200 for (balloon_iter = balloons.begin(); 211 for (BalloonCollection::Balloons::const_iterator iter = balloons.begin();
201 balloon_iter != balloons.end(); 212 iter != balloons.end(); ++iter) {
202 ++balloon_iter) { 213 if (origin == (*iter)->notification().origin_url() &&
203 if (origin == (*balloon_iter)->notification().origin_url() && 214 replace_id == (*iter)->notification().replace_id()) {
204 replace_id == (*balloon_iter)->notification().replace_id()) { 215 (*iter)->Update(notification);
205 (*balloon_iter)->Update(notification);
206 return true; 216 return true;
207 } 217 }
208 } 218 }
209 219
210 return false; 220 return false;
211 } 221 }
212 222
213 BalloonCollection::PositionPreference 223 BalloonCollection::PositionPreference
214 NotificationUIManagerImpl::GetPositionPreference() const { 224 NotificationUIManagerImpl::GetPositionPreference() const {
215 LOG(INFO) << "Current position preference: " << position_pref_.GetValue(); 225 LOG(INFO) << "Current position preference: " << position_pref_.GetValue();
216 226
217 return static_cast<BalloonCollection::PositionPreference>( 227 return static_cast<BalloonCollection::PositionPreference>(
218 position_pref_.GetValue()); 228 position_pref_.GetValue());
219 } 229 }
220 230
221 void NotificationUIManagerImpl::SetPositionPreference( 231 void NotificationUIManagerImpl::SetPositionPreference(
222 BalloonCollection::PositionPreference preference) { 232 BalloonCollection::PositionPreference preference) {
223 LOG(INFO) << "Setting position preference: " << preference; 233 LOG(INFO) << "Setting position preference: " << preference;
224 position_pref_.SetValue(static_cast<int>(preference)); 234 position_pref_.SetValue(static_cast<int>(preference));
225 balloon_collection_->SetPositionPreference(preference); 235 balloon_collection_->SetPositionPreference(preference);
226 } 236 }
227 237
228 void NotificationUIManagerImpl::GetQueuedNotificationsForTesting( 238 void NotificationUIManagerImpl::GetQueuedNotificationsForTesting(
229 std::vector<const Notification*>* notifications) { 239 std::vector<const Notification*>* notifications) {
230 NotificationDeque::const_iterator queued_iter; 240 for (NotificationDeque::const_iterator iter = show_queue_.begin();
231 for (queued_iter = show_queue_.begin(); queued_iter != show_queue_.end(); 241 iter != show_queue_.end(); ++iter) {
232 ++queued_iter) { 242 notifications->push_back(&(*iter)->notification());
233 notifications->push_back(&(*queued_iter)->notification());
234 } 243 }
235 } 244 }
236 245
237 void NotificationUIManagerImpl::Observe( 246 void NotificationUIManagerImpl::Observe(
238 int type, 247 int type,
239 const content::NotificationSource& source, 248 const content::NotificationSource& source,
240 const content::NotificationDetails& details) { 249 const content::NotificationDetails& details) {
241 if (type == chrome::NOTIFICATION_APP_TERMINATING) { 250 if (type == chrome::NOTIFICATION_APP_TERMINATING) {
242 CancelAll(); 251 CancelAll();
243 } else { 252 } else {
244 NOTREACHED(); 253 NOTREACHED();
245 } 254 }
246 } 255 }
247 256
248 void NotificationUIManagerImpl::OnDesktopNotificationPositionChanged() { 257 void NotificationUIManagerImpl::OnDesktopNotificationPositionChanged() {
249 balloon_collection_->SetPositionPreference( 258 balloon_collection_->SetPositionPreference(
250 static_cast<BalloonCollection::PositionPreference>( 259 static_cast<BalloonCollection::PositionPreference>(
251 position_pref_.GetValue())); 260 position_pref_.GetValue()));
252 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698