Chromium Code Reviews| 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 | |
| 255 if (status == NotificationDatabase::STATUS_OK) { | 257 if (status == NotificationDatabase::STATUS_OK) { |
| 256 if (synchronization_supported) { | 258 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); | |
| 267 it = notification_datas.erase(it); | 268 it = notification_datas.erase(it); |
| 268 } | 269 } |
| 269 } | 270 } |
| 270 } | 271 } |
| 271 | 272 |
| 272 BrowserThread::PostTask( | 273 BrowserThread::PostTask( |
| 273 BrowserThread::IO, FROM_HERE, | 274 BrowserThread::IO, FROM_HERE, |
| 274 base::Bind(callback, true /* success */, notification_datas)); | 275 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); | |
|
Peter Beverloo
2017/02/03 18:57:56
This won't actually work (and would need a test) -
| |
| 275 return; | 280 return; |
| 276 } | 281 } |
| 277 | 282 |
| 278 // Blow away the database if reading data failed due to corruption. | 283 // Blow away the database if reading data failed due to corruption. |
| 279 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) | 284 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) |
| 280 DestroyDatabase(); | 285 DestroyDatabase(); |
| 281 | 286 |
| 282 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 287 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 283 base::Bind(callback, false /* success */, | 288 base::Bind(callback, false /* success */, |
| 284 std::vector<NotificationDatabaseData>())); | 289 std::vector<NotificationDatabaseData>())); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 | 539 |
| 535 return path_.Append(kPlatformNotificationsDirectory); | 540 return path_.Append(kPlatformNotificationsDirectory); |
| 536 } | 541 } |
| 537 | 542 |
| 538 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( | 543 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( |
| 539 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 544 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 540 task_runner_ = task_runner; | 545 task_runner_ = task_runner; |
| 541 } | 546 } |
| 542 | 547 |
| 543 } // namespace content | 548 } // namespace content |
| OLD | NEW |