Index: content/browser/notifications/platform_notification_context_impl.cc |
diff --git a/content/browser/notifications/platform_notification_context_impl.cc b/content/browser/notifications/platform_notification_context_impl.cc |
index fa5c1387e1ccacdb81ebfc43ce707dca5e069afe..c0b5ef2ab1403db8268b5974bc3afee326fb1566 100644 |
--- a/content/browser/notifications/platform_notification_context_impl.cc |
+++ b/content/browser/notifications/platform_notification_context_impl.cc |
@@ -60,8 +60,8 @@ void PlatformNotificationContextImpl::Initialize() { |
std::set<std::string> displayed_notifications; |
bool notification_synchronization_supported = |
- service->GetDisplayedPersistentNotifications(browser_context_, |
- &displayed_notifications); |
+ service->GetDisplayedNotifications(browser_context_, |
+ &displayed_notifications); |
// Synchronize the notifications stored in the database with the set of |
// displaying notifications in |displayed_notifications|. This is necessary |
@@ -202,6 +202,17 @@ void PlatformNotificationContextImpl:: |
const ReadAllResultCallback& callback) { |
DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
+ PlatformNotificationService* service = |
+ GetContentClient()->browser()->GetPlatformNotificationService(); |
+ |
+ // Ask the underlying implementation what notifications are still being |
+ // displayed. |
+ std::set<std::string> displayed_notifications; |
+ bool notification_synchronization_supported = |
+ service && |
+ service->GetDisplayedNotifications(browser_context_, |
+ &displayed_notifications); |
Peter Beverloo
2016/12/06 13:04:02
We're not only calling GetDisplayedNotifications()
|
+ |
std::vector<NotificationDatabaseData> notification_datas; |
NotificationDatabase::Status status = |
@@ -212,6 +223,21 @@ void PlatformNotificationContextImpl:: |
status, NotificationDatabase::STATUS_COUNT); |
if (status == NotificationDatabase::STATUS_OK) { |
+ if (notification_synchronization_supported) { |
+ // Filter out notifications that are not actually on display anymore. |
+ // TODO(miguelg) synchronize the database if there are inconsistencies. |
+ for (auto it = notification_datas.begin(); |
+ it != notification_datas.end();) { |
+ if (NotificationIdGenerator::IsPersistentNotification( |
+ it->notification_id) && |
+ displayed_notifications.count(it->notification_id)) { |
+ ++it; |
+ } else { |
+ it = notification_datas.erase(it); |
+ } |
+ } |
+ } |
+ |
BrowserThread::PostTask( |
BrowserThread::IO, FROM_HERE, |
base::Bind(callback, true /* success */, notification_datas)); |