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

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

Issue 14320008: Fixes crash for operations on non-existing notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 7 years, 8 months 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 | « no previous file | no next file » | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/message_center_impl.h" 5 #include "ui/message_center/message_center_impl.h"
6 6
7 #include "base/observer_list.h" 7 #include "base/observer_list.h"
8 #include "ui/message_center/message_center_observer.h" 8 #include "ui/message_center/message_center_observer.h"
9 #include "ui/message_center/notification.h" 9 #include "ui/message_center/notification.h"
10 #include "ui/message_center/notification_list.h" 10 #include "ui/message_center/notification_list.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 const string16& message, 105 const string16& message,
106 const base::DictionaryValue* optional_fields) { 106 const base::DictionaryValue* optional_fields) {
107 notification_list_->UpdateNotificationMessage( 107 notification_list_->UpdateNotificationMessage(
108 old_id, new_id, title, message, optional_fields); 108 old_id, new_id, title, message, optional_fields);
109 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 109 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
110 OnNotificationUpdated(new_id)); 110 OnNotificationUpdated(new_id));
111 } 111 }
112 112
113 void MessageCenterImpl::RemoveNotification(const std::string& id, 113 void MessageCenterImpl::RemoveNotification(const std::string& id,
114 bool by_user) { 114 bool by_user) {
115 if (!HasNotification(id))
116 return;
117
115 // In many cases |id| is a reference to an existing notification instance 118 // In many cases |id| is a reference to an existing notification instance
116 // but the instance can be destructed in RemoveNotification(). Hence 119 // but the instance can be destructed in RemoveNotification(). Hence
117 // copies the id explicitly here. 120 // copies the id explicitly here.
118 std::string copied_id(id); 121 std::string copied_id(id);
119 notification_list_->RemoveNotification(copied_id); 122 notification_list_->RemoveNotification(copied_id);
120 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 123 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
121 OnNotificationRemoved(copied_id, by_user)); 124 OnNotificationRemoved(copied_id, by_user));
122 } 125 }
123 126
124 void MessageCenterImpl::RemoveAllNotifications(bool by_user) { 127 void MessageCenterImpl::RemoveAllNotifications(bool by_user) {
(...skipping 25 matching lines...) Expand all
150 const gfx::Image& image) { 153 const gfx::Image& image) {
151 if (notification_list_->SetNotificationImage(notification_id, image)) { 154 if (notification_list_->SetNotificationImage(notification_id, image)) {
152 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 155 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
153 OnNotificationUpdated(notification_id)); 156 OnNotificationUpdated(notification_id));
154 } 157 }
155 } 158 }
156 159
157 void MessageCenterImpl::SetNotificationButtonIcon( 160 void MessageCenterImpl::SetNotificationButtonIcon(
158 const std::string& notification_id, int button_index, 161 const std::string& notification_id, int button_index,
159 const gfx::Image& image) { 162 const gfx::Image& image) {
163 if (!HasNotification(notification_id))
164 return;
160 if (notification_list_->SetNotificationButtonIcon(notification_id, 165 if (notification_list_->SetNotificationButtonIcon(notification_id,
161 button_index, image)) { 166 button_index, image)) {
162 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 167 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
163 OnNotificationUpdated(notification_id)); 168 OnNotificationUpdated(notification_id));
164 } 169 }
165 } 170 }
166 171
167 void MessageCenterImpl::DisableNotificationsByExtension( 172 void MessageCenterImpl::DisableNotificationsByExtension(
168 const std::string& id) { 173 const std::string& id) {
169 if (delegate_) 174 if (delegate_)
(...skipping 28 matching lines...) Expand all
198 delegate_->ShowSettings(id); 203 delegate_->ShowSettings(id);
199 } 204 }
200 205
201 void MessageCenterImpl::ShowNotificationSettingsDialog( 206 void MessageCenterImpl::ShowNotificationSettingsDialog(
202 gfx::NativeView context) { 207 gfx::NativeView context) {
203 if (delegate_) 208 if (delegate_)
204 delegate_->ShowSettingsDialog(context); 209 delegate_->ShowSettingsDialog(context);
205 } 210 }
206 211
207 void MessageCenterImpl::ExpandNotification(const std::string& id) { 212 void MessageCenterImpl::ExpandNotification(const std::string& id) {
213 if (!HasNotification(id))
214 return;
208 notification_list_->MarkNotificationAsExpanded(id); 215 notification_list_->MarkNotificationAsExpanded(id);
209 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 216 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
210 OnNotificationUpdated(id)); 217 OnNotificationUpdated(id));
211 } 218 }
212 219
213 void MessageCenterImpl::ClickOnNotification(const std::string& id) { 220 void MessageCenterImpl::ClickOnNotification(const std::string& id) {
221 if (!HasNotification(id))
222 return;
214 if (HasPopupNotifications()) 223 if (HasPopupNotifications())
215 MarkSinglePopupAsShown(id, true); 224 MarkSinglePopupAsShown(id, true);
216 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 225 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
217 OnNotificationClicked(id)); 226 OnNotificationClicked(id));
218 } 227 }
219 228
220 void MessageCenterImpl::ClickOnNotificationButton(const std::string& id, 229 void MessageCenterImpl::ClickOnNotificationButton(const std::string& id,
221 int button_index) { 230 int button_index) {
231 if (!HasNotification(id))
232 return;
222 if (HasPopupNotifications()) 233 if (HasPopupNotifications())
223 MarkSinglePopupAsShown(id, true); 234 MarkSinglePopupAsShown(id, true);
224 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 235 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
225 OnNotificationButtonClicked(id, button_index)); 236 OnNotificationButtonClicked(id, button_index));
226 } 237 }
227 238
228 void MessageCenterImpl::MarkSinglePopupAsShown(const std::string& id, 239 void MessageCenterImpl::MarkSinglePopupAsShown(const std::string& id,
229 bool mark_notification_as_read) { 240 bool mark_notification_as_read) {
241 if (!HasNotification(id))
242 return;
230 notification_list_->MarkSinglePopupAsShown(id, mark_notification_as_read); 243 notification_list_->MarkSinglePopupAsShown(id, mark_notification_as_read);
231 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_, 244 FOR_EACH_OBSERVER(MessageCenterObserver, observer_list_,
232 OnNotificationUpdated(id)); 245 OnNotificationUpdated(id));
233 } 246 }
234 247
235 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) { 248 void MessageCenterImpl::SetQuietMode(bool in_quiet_mode) {
236 notification_list_->SetQuietMode(in_quiet_mode); 249 notification_list_->SetQuietMode(in_quiet_mode);
237 } 250 }
238 251
239 void MessageCenterImpl::EnterQuietModeWithExpire( 252 void MessageCenterImpl::EnterQuietModeWithExpire(
240 const base::TimeDelta& expires_in) { 253 const base::TimeDelta& expires_in) {
241 notification_list_->EnterQuietModeWithExpire(expires_in); 254 notification_list_->EnterQuietModeWithExpire(expires_in);
242 } 255 }
243 256
244 } // namespace message_center 257 } // namespace message_center
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698