Commit e50bfa20 authored by miguelg's avatar miguelg Committed by Commit bot

Fix a couple of notification TODOs

Delete obsolete notifiations from the database
Stop silently ignoring notifications without an ID

BUG=596161

Review-Url: https://codereview.chromium.org/2671603005
Cr-Commit-Position: refs/heads/master@{#448721}
parent 87434c43
......@@ -328,11 +328,6 @@ NotificationDatabase::ReadAllNotificationDataInternal(
continue;
}
// Silently ignore the notification if it doesn't have an ID assigned.
// TODO(peter): Remove this clause when Chrome 55 has branched.
if (notification_database_data.notification_id.empty())
continue;
notification_data_vector->push_back(notification_database_data);
}
......
......@@ -252,10 +252,10 @@ void PlatformNotificationContextImpl::
UMA_HISTOGRAM_ENUMERATION("Notifications.Database.ReadForServiceWorkerResult",
status, NotificationDatabase::STATUS_COUNT);
std::vector<std::string> obsolete_notifications;
if (status == NotificationDatabase::STATUS_OK) {
if (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();) {
// The database is only used for persistent notifications.
......@@ -264,6 +264,7 @@ void PlatformNotificationContextImpl::
if (displayed_notifications->count(it->notification_id)) {
++it;
} else {
obsolete_notifications.push_back(it->notification_id);
it = notification_datas.erase(it);
}
}
......@@ -272,6 +273,10 @@ void PlatformNotificationContextImpl::
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(callback, true /* success */, notification_datas));
// Remove notifications that are not actually on display anymore.
for (const auto& it : obsolete_notifications)
database_->DeleteNotificationData(it, origin);
return;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment