OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/app_notification_manager.h" | 5 #include "chrome/browser/extensions/app_notification_manager.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 | 103 |
104 SyncAddChange(*linked_item); | 104 SyncAddChange(*linked_item); |
105 | 105 |
106 if (storage_.get()) { | 106 if (storage_.get()) { |
107 BrowserThread::PostTask( | 107 BrowserThread::PostTask( |
108 BrowserThread::FILE, | 108 BrowserThread::FILE, |
109 FROM_HERE, | 109 FROM_HERE, |
110 base::Bind(&AppNotificationManager::SaveOnFileThread, | 110 base::Bind(&AppNotificationManager::SaveOnFileThread, |
111 this, extension_id, CopyAppNotificationList(list))); | 111 this, extension_id, CopyAppNotificationList(list))); |
112 } | 112 } |
113 | |
114 content::NotificationService::current()->Notify( | |
115 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | |
116 content::Source<Profile>(profile_), | |
117 content::Details<const std::string>(&extension_id)); | |
118 | |
113 return true; | 119 return true; |
114 } | 120 } |
115 | 121 |
116 const AppNotificationList* AppNotificationManager::GetAll( | 122 const AppNotificationList* AppNotificationManager::GetAll( |
117 const std::string& extension_id) const { | 123 const std::string& extension_id) const { |
118 if (!loaded()) | 124 if (!loaded()) |
119 return NULL; | 125 return NULL; |
120 if (ContainsKey(*notifications_, extension_id)) | 126 if (ContainsKey(*notifications_, extension_id)) |
121 return &((*notifications_)[extension_id]); | 127 return &((*notifications_)[extension_id]); |
122 return NULL; | 128 return NULL; |
(...skipping 11 matching lines...) Expand all Loading... | |
134 } | 140 } |
135 | 141 |
136 const AppNotification* AppNotificationManager::GetLast( | 142 const AppNotification* AppNotificationManager::GetLast( |
137 const std::string& extension_id) { | 143 const std::string& extension_id) { |
138 if (!loaded()) | 144 if (!loaded()) |
139 return NULL; | 145 return NULL; |
140 NotificationMap::iterator found = notifications_->find(extension_id); | 146 NotificationMap::iterator found = notifications_->find(extension_id); |
141 if (found == notifications_->end()) | 147 if (found == notifications_->end()) |
142 return NULL; | 148 return NULL; |
143 const AppNotificationList& list = found->second; | 149 const AppNotificationList& list = found->second; |
150 if (list.empty()) | |
151 return NULL; | |
144 return list.rbegin()->get(); | 152 return list.rbegin()->get(); |
145 } | 153 } |
146 | 154 |
147 void AppNotificationManager::ClearAll(const std::string& extension_id) { | 155 void AppNotificationManager::ClearAll(const std::string& extension_id) { |
148 if (!loaded()) | 156 if (!loaded()) |
149 return; | 157 return; |
150 NotificationMap::iterator found = notifications_->find(extension_id); | 158 NotificationMap::iterator found = notifications_->find(extension_id); |
151 if (found != notifications_->end()) { | 159 if (found != notifications_->end()) { |
152 SyncClearAllChange(found->second); | 160 SyncClearAllChange(found->second); |
153 notifications_->erase(found); | 161 notifications_->erase(found); |
154 } | 162 } |
155 | 163 |
156 if (storage_.get()) { | 164 if (storage_.get()) { |
157 BrowserThread::PostTask( | 165 BrowserThread::PostTask( |
158 BrowserThread::FILE, | 166 BrowserThread::FILE, |
159 FROM_HERE, | 167 FROM_HERE, |
160 base::Bind(&AppNotificationManager::DeleteOnFileThread, | 168 base::Bind(&AppNotificationManager::DeleteOnFileThread, |
161 this, extension_id)); | 169 this, extension_id)); |
162 } | 170 } |
171 | |
172 content::NotificationService::current()->Notify( | |
173 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | |
174 content::Source<Profile>(profile_), | |
175 content::Details<const std::string>(&extension_id)); | |
163 } | 176 } |
164 | 177 |
165 void AppNotificationManager::Observe( | 178 void AppNotificationManager::Observe( |
166 int type, | 179 int type, |
167 const content::NotificationSource& source, | 180 const content::NotificationSource& source, |
168 const content::NotificationDetails& details) { | 181 const content::NotificationDetails& details) { |
169 CHECK(type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED); | 182 CHECK(type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED); |
170 ClearAll(*content::Details<const std::string>(details).ptr()); | 183 ClearAll(*content::Details<const std::string>(details).ptr()); |
171 } | 184 } |
172 | 185 |
(...skipping 29 matching lines...) Expand all Loading... | |
202 notifications_.reset(map); | 215 notifications_.reset(map); |
203 | 216 |
204 // Generate STATE_CHAGNED notifications for extensions that have at | 217 // Generate STATE_CHAGNED notifications for extensions that have at |
205 // least one notification loaded. | 218 // least one notification loaded. |
206 NotificationMap::const_iterator i; | 219 NotificationMap::const_iterator i; |
207 for (i = map->begin(); i != map->end(); ++i) { | 220 for (i = map->begin(); i != map->end(); ++i) { |
208 const std::string& id = i->first; | 221 const std::string& id = i->first; |
209 if (i->second.empty()) | 222 if (i->second.empty()) |
210 continue; | 223 continue; |
211 content::NotificationService::current()->Notify( | 224 content::NotificationService::current()->Notify( |
212 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | 225 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |
asargent_no_longer_on_chrome
2011/10/24 22:09:15
nit: this should be indented like the next 2 lines
Munjal (Google)
2011/10/24 22:22:55
Done.
| |
213 content::Source<Profile>(profile_), | 226 content::Source<Profile>(profile_), |
214 content::Details<const std::string>(&id)); | 227 content::Details<const std::string>(&id)); |
215 } | 228 } |
216 | 229 |
217 // Generate MANAGER_LOADED notification. | 230 // Generate MANAGER_LOADED notification. |
218 content::NotificationService::current()->Notify( | 231 content::NotificationService::current()->Notify( |
219 chrome::NOTIFICATION_APP_NOTIFICATION_MANAGER_LOADED, | 232 chrome::NOTIFICATION_APP_NOTIFICATION_MANAGER_LOADED, |
220 content::Source<AppNotificationManager>(this), | 233 content::Source<AppNotificationManager>(this), |
221 content::NotificationService::NoDetails()); | 234 content::NotificationService::NoDetails()); |
222 } | 235 } |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 AppNotificationList& list = GetAllInternal(extension_id); | 445 AppNotificationList& list = GetAllInternal(extension_id); |
433 RemoveByGuid(&list, guid); | 446 RemoveByGuid(&list, guid); |
434 | 447 |
435 if (storage_.get()) { | 448 if (storage_.get()) { |
436 BrowserThread::PostTask( | 449 BrowserThread::PostTask( |
437 BrowserThread::FILE, | 450 BrowserThread::FILE, |
438 FROM_HERE, | 451 FROM_HERE, |
439 base::Bind(&AppNotificationManager::SaveOnFileThread, | 452 base::Bind(&AppNotificationManager::SaveOnFileThread, |
440 this, extension_id, CopyAppNotificationList(list))); | 453 this, extension_id, CopyAppNotificationList(list))); |
441 } | 454 } |
455 | |
456 content::NotificationService::current()->Notify( | |
457 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | |
458 content::Source<Profile>(profile_), | |
459 content::Details<const std::string>(&extension_id)); | |
442 } | 460 } |
443 | 461 |
444 // static | 462 // static |
445 SyncData AppNotificationManager::CreateSyncDataFromNotification( | 463 SyncData AppNotificationManager::CreateSyncDataFromNotification( |
446 const AppNotification& notification) { | 464 const AppNotification& notification) { |
447 DCHECK(!notification.is_local()); | 465 DCHECK(!notification.is_local()); |
448 sync_pb::EntitySpecifics specifics; | 466 sync_pb::EntitySpecifics specifics; |
449 sync_pb::AppNotificationSpecifics* notif_specifics = | 467 sync_pb::AppNotificationSpecifics* notif_specifics = |
450 specifics.MutableExtension(sync_pb::app_notification); | 468 specifics.MutableExtension(sync_pb::app_notification); |
451 notif_specifics->set_app_id(notification.extension_id()); | 469 notif_specifics->set_app_id(notification.extension_id()); |
(...skipping 21 matching lines...) Expand all Loading... | |
473 | 491 |
474 AppNotification* notification = new AppNotification( | 492 AppNotification* notification = new AppNotification( |
475 false, specifics.guid(), specifics.app_id(), | 493 false, specifics.guid(), specifics.app_id(), |
476 specifics.title(), specifics.body_text()); | 494 specifics.title(), specifics.body_text()); |
477 if (specifics.has_link_text()) | 495 if (specifics.has_link_text()) |
478 notification->set_link_text(specifics.link_text()); | 496 notification->set_link_text(specifics.link_text()); |
479 if (specifics.has_link_url()) | 497 if (specifics.has_link_url()) |
480 notification->set_link_url(GURL(specifics.link_url())); | 498 notification->set_link_url(GURL(specifics.link_url())); |
481 return notification; | 499 return notification; |
482 } | 500 } |
OLD | NEW |