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

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

Issue 2223943002: Eagerly delete replaced notifications from the database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Eagerly delete replaced notifications from the database Created 4 years, 4 months 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 8ee48789abec0d3f0bf85566ce38077e7da4ef08..f986fa8a6ea6ba03b5b47f99d24005c2d7d9f223 100644
--- a/content/browser/notifications/platform_notification_context_impl.cc
+++ b/content/browser/notifications/platform_notification_context_impl.cc
@@ -239,6 +239,31 @@ void PlatformNotificationContextImpl::DoWriteNotificationData(
const WriteResultCallback& callback) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
+ // Eagerly delete data for replaced notifications from the database.
+ if (!database_data.notification_data.tag.empty()) {
+ std::set<int64_t> deleted_notification_set;
+ NotificationDatabase::Status delete_status =
+ database_->DeleteAllNotificationDataForOrigin(
+ origin, database_data.notification_data.tag,
+ &deleted_notification_set);
+
+ UMA_HISTOGRAM_ENUMERATION("Notifications.Database.DeleteBeforeWriteResult",
+ delete_status,
+ NotificationDatabase::STATUS_COUNT);
+
+ // Unless the database was corrupted following this change, there is no
+ // reason to bail out here in event of failure because the notification
+ // display logic will handle notification replacement for the user.
+ if (delete_status == NotificationDatabase::STATUS_ERROR_CORRUPTED) {
+ DestroyDatabase();
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, false /* success */, 0 /* notification_id */));
+ return;
+ }
+ }
+
int64_t notification_id = 0;
NotificationDatabase::Status status =
database_->WriteNotificationData(origin, database_data, &notification_id);

Powered by Google App Engine
This is Rietveld 408576698