OLD | NEW |
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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 245 |
246 std::vector<NotificationDatabaseData> notification_datas; | 246 std::vector<NotificationDatabaseData> notification_datas; |
247 | 247 |
248 NotificationDatabase::Status status = | 248 NotificationDatabase::Status status = |
249 database_->ReadAllNotificationDataForServiceWorkerRegistration( | 249 database_->ReadAllNotificationDataForServiceWorkerRegistration( |
250 origin, service_worker_registration_id, ¬ification_datas); | 250 origin, service_worker_registration_id, ¬ification_datas); |
251 | 251 |
252 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.ReadForServiceWorkerResult", | 252 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.ReadForServiceWorkerResult", |
253 status, NotificationDatabase::STATUS_COUNT); | 253 status, NotificationDatabase::STATUS_COUNT); |
254 | 254 |
255 std::vector<std::string> obsolete_notifications; | |
256 | |
257 if (status == NotificationDatabase::STATUS_OK) { | 255 if (status == NotificationDatabase::STATUS_OK) { |
258 if (synchronization_supported) { | 256 if (synchronization_supported) { |
| 257 // Filter out notifications that are not actually on display anymore. |
| 258 // TODO(miguelg) synchronize the database if there are inconsistencies. |
259 for (auto it = notification_datas.begin(); | 259 for (auto it = notification_datas.begin(); |
260 it != notification_datas.end();) { | 260 it != notification_datas.end();) { |
261 // The database is only used for persistent notifications. | 261 // The database is only used for persistent notifications. |
262 DCHECK(NotificationIdGenerator::IsPersistentNotification( | 262 DCHECK(NotificationIdGenerator::IsPersistentNotification( |
263 it->notification_id)); | 263 it->notification_id)); |
264 if (displayed_notifications->count(it->notification_id)) { | 264 if (displayed_notifications->count(it->notification_id)) { |
265 ++it; | 265 ++it; |
266 } else { | 266 } else { |
267 obsolete_notifications.push_back(it->notification_id); | |
268 it = notification_datas.erase(it); | 267 it = notification_datas.erase(it); |
269 } | 268 } |
270 } | 269 } |
271 } | 270 } |
272 | 271 |
273 BrowserThread::PostTask( | 272 BrowserThread::PostTask( |
274 BrowserThread::IO, FROM_HERE, | 273 BrowserThread::IO, FROM_HERE, |
275 base::Bind(callback, true /* success */, notification_datas)); | 274 base::Bind(callback, true /* success */, notification_datas)); |
276 | |
277 // Remove notifications that are not actually on display anymore. | |
278 for (const auto& it : obsolete_notifications) | |
279 database_->DeleteNotificationData(it, origin); | |
280 return; | 275 return; |
281 } | 276 } |
282 | 277 |
283 // Blow away the database if reading data failed due to corruption. | 278 // Blow away the database if reading data failed due to corruption. |
284 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) | 279 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) |
285 DestroyDatabase(); | 280 DestroyDatabase(); |
286 | 281 |
287 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 282 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
288 base::Bind(callback, false /* success */, | 283 base::Bind(callback, false /* success */, |
289 std::vector<NotificationDatabaseData>())); | 284 std::vector<NotificationDatabaseData>())); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 534 |
540 return path_.Append(kPlatformNotificationsDirectory); | 535 return path_.Append(kPlatformNotificationsDirectory); |
541 } | 536 } |
542 | 537 |
543 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( | 538 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( |
544 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 539 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
545 task_runner_ = task_runner; | 540 task_runner_ = task_runner; |
546 } | 541 } |
547 | 542 |
548 } // namespace content | 543 } // namespace content |
OLD | NEW |