Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 194 base::Bind(&AppNotificationManager::HandleLoadResults, | 207 base::Bind(&AppNotificationManager::HandleLoadResults, |
| 195 this, result.release())); | 208 this, result.release())); |
| 196 } | 209 } |
| 197 | 210 |
| 198 void AppNotificationManager::HandleLoadResults(NotificationMap* map) { | 211 void AppNotificationManager::HandleLoadResults(NotificationMap* map) { |
| 199 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 212 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 200 DCHECK(map); | 213 DCHECK(map); |
| 201 DCHECK(!loaded()); | 214 DCHECK(!loaded()); |
| 202 notifications_.reset(map); | 215 notifications_.reset(map); |
| 203 | 216 |
| 204 // Generate STATE_CHAGNED notifications for extensions that have at | |
| 205 // least one notification loaded. | |
| 206 NotificationMap::const_iterator i; | |
| 207 for (i = map->begin(); i != map->end(); ++i) { | |
| 208 const std::string& id = i->first; | |
| 209 if (i->second.empty()) | |
| 210 continue; | |
| 211 content::NotificationService::current()->Notify( | |
| 212 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | |
|
asargent_no_longer_on_chrome
2011/10/24 19:09:17
I think removing this code block means that in the
Munjal (Google)
2011/10/24 21:44:11
I thought that since Add now generates STATE_CHANG
Munjal (Google)
2011/10/24 21:46:25
Actually, you are right. We do not call Add in thi
Munjal (Google)
2011/10/24 21:55:22
Done.
| |
| 213 content::Source<Profile>(profile_), | |
| 214 content::Details<const std::string>(&id)); | |
| 215 } | |
| 216 | |
| 217 // Generate MANAGER_LOADED notification. | 217 // Generate MANAGER_LOADED notification. |
| 218 content::NotificationService::current()->Notify( | 218 content::NotificationService::current()->Notify( |
| 219 chrome::NOTIFICATION_APP_NOTIFICATION_MANAGER_LOADED, | 219 chrome::NOTIFICATION_APP_NOTIFICATION_MANAGER_LOADED, |
| 220 content::Source<AppNotificationManager>(this), | 220 content::Source<AppNotificationManager>(this), |
| 221 content::NotificationService::NoDetails()); | 221 content::NotificationService::NoDetails()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void AppNotificationManager::SaveOnFileThread(const std::string& extension_id, | 224 void AppNotificationManager::SaveOnFileThread(const std::string& extension_id, |
| 225 AppNotificationList* list) { | 225 AppNotificationList* list) { |
| 226 // Own the |list|. | 226 // Own the |list|. |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 AppNotificationList& list = GetAllInternal(extension_id); | 432 AppNotificationList& list = GetAllInternal(extension_id); |
| 433 RemoveByGuid(&list, guid); | 433 RemoveByGuid(&list, guid); |
| 434 | 434 |
| 435 if (storage_.get()) { | 435 if (storage_.get()) { |
| 436 BrowserThread::PostTask( | 436 BrowserThread::PostTask( |
| 437 BrowserThread::FILE, | 437 BrowserThread::FILE, |
| 438 FROM_HERE, | 438 FROM_HERE, |
| 439 base::Bind(&AppNotificationManager::SaveOnFileThread, | 439 base::Bind(&AppNotificationManager::SaveOnFileThread, |
| 440 this, extension_id, CopyAppNotificationList(list))); | 440 this, extension_id, CopyAppNotificationList(list))); |
| 441 } | 441 } |
| 442 | |
| 443 content::NotificationService::current()->Notify( | |
| 444 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | |
| 445 content::Source<Profile>(profile_), | |
| 446 content::Details<const std::string>(&extension_id)); | |
| 442 } | 447 } |
| 443 | 448 |
| 444 // static | 449 // static |
| 445 SyncData AppNotificationManager::CreateSyncDataFromNotification( | 450 SyncData AppNotificationManager::CreateSyncDataFromNotification( |
| 446 const AppNotification& notification) { | 451 const AppNotification& notification) { |
| 447 DCHECK(!notification.is_local()); | 452 DCHECK(!notification.is_local()); |
| 448 sync_pb::EntitySpecifics specifics; | 453 sync_pb::EntitySpecifics specifics; |
| 449 sync_pb::AppNotificationSpecifics* notif_specifics = | 454 sync_pb::AppNotificationSpecifics* notif_specifics = |
| 450 specifics.MutableExtension(sync_pb::app_notification); | 455 specifics.MutableExtension(sync_pb::app_notification); |
| 451 notif_specifics->set_app_id(notification.extension_id()); | 456 notif_specifics->set_app_id(notification.extension_id()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 473 | 478 |
| 474 AppNotification* notification = new AppNotification( | 479 AppNotification* notification = new AppNotification( |
| 475 false, specifics.guid(), specifics.app_id(), | 480 false, specifics.guid(), specifics.app_id(), |
| 476 specifics.title(), specifics.body_text()); | 481 specifics.title(), specifics.body_text()); |
| 477 if (specifics.has_link_text()) | 482 if (specifics.has_link_text()) |
| 478 notification->set_link_text(specifics.link_text()); | 483 notification->set_link_text(specifics.link_text()); |
| 479 if (specifics.has_link_url()) | 484 if (specifics.has_link_url()) |
| 480 notification->set_link_url(GURL(specifics.link_url())); | 485 notification->set_link_url(GURL(specifics.link_url())); |
| 481 return notification; | 486 return notification; |
| 482 } | 487 } |
| OLD | NEW |