| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 std::vector<NotificationDatabaseData>())); | 195 std::vector<NotificationDatabaseData>())); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void PlatformNotificationContextImpl:: | 198 void PlatformNotificationContextImpl:: |
| 199 DoReadAllNotificationDataForServiceWorkerRegistration( | 199 DoReadAllNotificationDataForServiceWorkerRegistration( |
| 200 const GURL& origin, | 200 const GURL& origin, |
| 201 int64_t service_worker_registration_id, | 201 int64_t service_worker_registration_id, |
| 202 const ReadAllResultCallback& callback) { | 202 const ReadAllResultCallback& callback) { |
| 203 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 203 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 204 | 204 |
| 205 PlatformNotificationService* service = |
| 206 GetContentClient()->browser()->GetPlatformNotificationService(); |
| 207 |
| 208 // Ask the underlying implementation what notifications are still being |
| 209 // displayed. |
| 210 std::set<std::string> displayed_notifications; |
| 211 bool notification_synchronization_supported = |
| 212 service && |
| 213 service->GetDisplayedPersistentNotifications(browser_context_, |
| 214 &displayed_notifications); |
| 215 |
| 205 std::vector<NotificationDatabaseData> notification_datas; | 216 std::vector<NotificationDatabaseData> notification_datas; |
| 206 | 217 |
| 207 NotificationDatabase::Status status = | 218 NotificationDatabase::Status status = |
| 208 database_->ReadAllNotificationDataForServiceWorkerRegistration( | 219 database_->ReadAllNotificationDataForServiceWorkerRegistration( |
| 209 origin, service_worker_registration_id, ¬ification_datas); | 220 origin, service_worker_registration_id, ¬ification_datas); |
| 210 | 221 |
| 211 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.ReadForServiceWorkerResult", | 222 UMA_HISTOGRAM_ENUMERATION("Notifications.Database.ReadForServiceWorkerResult", |
| 212 status, NotificationDatabase::STATUS_COUNT); | 223 status, NotificationDatabase::STATUS_COUNT); |
| 213 | 224 |
| 214 if (status == NotificationDatabase::STATUS_OK) { | 225 if (status == NotificationDatabase::STATUS_OK) { |
| 226 if (notification_synchronization_supported) { |
| 227 // Filter out notifications that are not actually on display anymore. |
| 228 for (auto it = notification_datas.begin(); |
| 229 it != notification_datas.end();) { |
| 230 if (displayed_notifications.count(it->notification_id)) |
| 231 ++it; |
| 232 else |
| 233 it = notification_datas.erase(it); |
| 234 } |
| 235 } |
| 236 |
| 215 BrowserThread::PostTask( | 237 BrowserThread::PostTask( |
| 216 BrowserThread::IO, FROM_HERE, | 238 BrowserThread::IO, FROM_HERE, |
| 217 base::Bind(callback, true /* success */, notification_datas)); | 239 base::Bind(callback, true /* success */, notification_datas)); |
| 218 return; | 240 return; |
| 219 } | 241 } |
| 220 | 242 |
| 221 // Blow away the database if reading data failed due to corruption. | 243 // Blow away the database if reading data failed due to corruption. |
| 222 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) | 244 if (status == NotificationDatabase::STATUS_ERROR_CORRUPTED) |
| 223 DestroyDatabase(); | 245 DestroyDatabase(); |
| 224 | 246 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 | 499 |
| 478 return path_.Append(kPlatformNotificationsDirectory); | 500 return path_.Append(kPlatformNotificationsDirectory); |
| 479 } | 501 } |
| 480 | 502 |
| 481 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( | 503 void PlatformNotificationContextImpl::SetTaskRunnerForTesting( |
| 482 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { | 504 const scoped_refptr<base::SequencedTaskRunner>& task_runner) { |
| 483 task_runner_ = task_runner; | 505 task_runner_ = task_runner; |
| 484 } | 506 } |
| 485 | 507 |
| 486 } // namespace content | 508 } // namespace content |
| OLD | NEW |