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

Unified Diff: content/browser/notifications/platform_notification_context_impl.cc

Issue 2534443002: Use notification display service to collect persistent notifications. (Closed)
Patch Set: revert unit test Created 4 years 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 side-by-side diff with in-line comments
Download patch
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..775bc9b8f94e610afa34e423280def1190362b70 100644
--- a/content/browser/notifications/platform_notification_context_impl.cc
+++ b/content/browser/notifications/platform_notification_context_impl.cc
@@ -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 &&
Peter Beverloo 2016/12/02 13:43:34 Why would |service| be NULL?
Miguel Garcia 2016/12/06 12:01:18 It's null in some context_unittests like PlatformN
+ service->GetDisplayedPersistentNotifications(browser_context_,
+ &displayed_notifications);
+
std::vector<NotificationDatabaseData> notification_datas;
NotificationDatabase::Status status =
@@ -212,6 +223,17 @@ 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.
+ for (auto it = notification_datas.begin();
+ it != notification_datas.end();) {
+ if (displayed_notifications.count(it->notification_id))
+ ++it;
+ else
+ it = notification_datas.erase(it);
+ }
Peter Beverloo 2016/12/02 13:43:34 We'll want to synchronize the database if there ar
Miguel Garcia 2016/12/06 12:01:18 Done.
+ }
+
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(callback, true /* success */, notification_datas));

Powered by Google App Engine
This is Rietveld 408576698