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

Side by Side Diff: content/browser/notifications/platform_notification_context_impl.cc

Issue 2868793003: RE-add the ability to delete notification ids unknown by the display service. (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/notifications/platform_notification_context_impl.h" 5 #include "content/browser/notifications/platform_notification_context_impl.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 std::vector<NotificationDatabaseData> notification_datas; 275 std::vector<NotificationDatabaseData> notification_datas;
276 276
277 NotificationDatabase::Status status = 277 NotificationDatabase::Status status =
278 database_->ReadAllNotificationDataForServiceWorkerRegistration( 278 database_->ReadAllNotificationDataForServiceWorkerRegistration(
279 origin, service_worker_registration_id, &notification_datas); 279 origin, service_worker_registration_id, &notification_datas);
280 280
281 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.ReadForServiceWorkerResult", 281 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.ReadForServiceWorkerResult",
282 status, NotificationDatabase::STATUS_COUNT); 282 status, NotificationDatabase::STATUS_COUNT);
283 283
284 std::vector<std::string> obsolete_notifications;
285
284 if (status == NotificationDatabase::STATUS_OK) { 286 if (status == NotificationDatabase::STATUS_OK) {
285 if (supports_synchronization) { 287 if (supports_synchronization) {
286 // Filter out notifications that are not actually on display anymore.
287 // TODO(miguelg) synchronize the database if there are inconsistencies.
288 for (auto it = notification_datas.begin(); 288 for (auto it = notification_datas.begin();
289 it != notification_datas.end();) { 289 it != notification_datas.end();) {
290 // The database is only used for persistent notifications. 290 // The database is only used for persistent notifications.
291 DCHECK(NotificationIdGenerator::IsPersistentNotification( 291 DCHECK(NotificationIdGenerator::IsPersistentNotification(
292 it->notification_id)); 292 it->notification_id));
293 if (displayed_notifications->count(it->notification_id)) { 293 if (displayed_notifications->count(it->notification_id)) {
294 ++it; 294 ++it;
295 } else { 295 } else {
296 obsolete_notifications.push_back(it->notification_id);
296 it = notification_datas.erase(it); 297 it = notification_datas.erase(it);
297 } 298 }
298 } 299 }
299 } 300 }
300 301
301 BrowserThread::PostTask( 302 BrowserThread::PostTask(
302 BrowserThread::IO, FROM_HERE, 303 BrowserThread::IO, FROM_HERE,
303 base::Bind(callback, true /* success */, notification_datas)); 304 base::Bind(callback, true /* success */, notification_datas));
305
306 // Remove notifications that are not actually on display anymore.
307 for (const auto& it : obsolete_notifications)
308 database_->DeleteNotificationData(it, origin);
304 return; 309 return;
305 } 310 }
306 311
307 // Blow away the database if reading data failed due to corruption. 312 // Blow away the database if reading data failed due to corruption.
308 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) 313 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED)
309 DestroyDatabase(); 314 DestroyDatabase();
310 315
311 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 316 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
312 base::Bind(callback, false /* success */, 317 base::Bind(callback, false /* success */,
313 std::vector<NotificationDatabaseData>())); 318 std::vector<NotificationDatabaseData>()));
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 568
564 return path_.Append(kPlatformNotificationsDirectory); 569 return path_.Append(kPlatformNotificationsDirectory);
565 } 570 }
566 571
567 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( 572 void PlatformNotificationContextImpl::SetTaskRunnerForTesting(
568 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { 573 const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
569 task_runner_ = task_runner; 574 task_runner_ = task_runner;
570 } 575 }
571 576
572 } // namespace content 577 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698