Chromium Code Reviews| 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 2cf1d983d52598f7617eb996171e03f02a47b8b0..7ea67aef86d52aadeefc0ea5ae98bc1872bfeb5e 100644 |
| --- a/content/browser/notifications/platform_notification_context_impl.cc |
| +++ b/content/browser/notifications/platform_notification_context_impl.cc |
| @@ -57,36 +57,51 @@ void PlatformNotificationContextImpl::Initialize() { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| PlatformNotificationService* service = |
| GetContentClient()->browser()->GetPlatformNotificationService(); |
| - if (service) { |
| - std::set<std::string> displayed_notifications; |
| - |
| - bool notification_synchronization_supported = |
| - service->GetDisplayedNotifications(browser_context_, |
| - &displayed_notifications); |
| - |
| - // Synchronize the notifications stored in the database with the set of |
| - // displaying notifications in |displayed_notifications|. This is necessary |
| - // because flakiness may cause a platform to inform Chrome of a notification |
| - // that has since been closed, or because the platform does not support |
| - // notifications that exceed the lifetime of the browser process. |
| - |
| - // TODO(peter): Synchronizing the actual notifications will be done when the |
| - // persistent notification ids are stable. For M44 we need to support the |
| - // case where there may be no notifications after a Chrome restart. |
| - if (notification_synchronization_supported && |
| - displayed_notifications.empty()) { |
| - prune_database_on_open_ = true; |
| - } |
| + if (!service) { |
|
Peter Beverloo
2017/03/15 18:07:51
Here's an idea: should we maybe just bail out if t
Miguel Garcia
2017/03/16 14:57:42
Done.
Miguel Garcia
2017/03/16 15:57:25
I had to revert this because several tests fail as
|
| + std::unique_ptr<std::set<std::string>> displayed_notifications = |
| + base::MakeUnique<std::set<std::string>>(); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&PlatformNotificationContextImpl::InitializeOnIO, this, |
| + base::Passed(&displayed_notifications), false)); |
| + return; |
| } |
| + service->GetDisplayedNotifications( |
| + browser_context_, |
| + base::Bind(&PlatformNotificationContextImpl::InitializeOnUI, this)); |
| +} |
| +void PlatformNotificationContextImpl::InitializeOnUI( |
| + std::unique_ptr<std::set<std::string>> displayed_notifications, |
| + bool notification_synchronization_supported) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| BrowserThread::PostTask( |
| BrowserThread::IO, FROM_HERE, |
| - base::Bind(&PlatformNotificationContextImpl::InitializeOnIO, this)); |
| + base::Bind(&PlatformNotificationContextImpl::InitializeOnIO, this, |
| + base::Passed(&displayed_notifications), |
| + notification_synchronization_supported)); |
| } |
| -void PlatformNotificationContextImpl::InitializeOnIO() { |
| +void PlatformNotificationContextImpl::InitializeOnIO( |
| + std::unique_ptr<std::set<std::string>> displayed_notifications, |
| + bool notification_synchronization_supported) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + // Synchronize the notifications stored in the database with the set of |
| + // displaying notifications in |displayed_notifications|. This is necessary |
| + // because flakiness may cause a platform to inform Chrome of a notification |
| + // that has since been closed, or because the platform does not support |
| + // notifications that exceed the lifetime of the browser process. |
| + |
| + // TODO(peter): Synchronizing the actual notifications will be done when the |
| + // persistent notification ids are stable. For M44 we need to support the |
| + // case where there may be no notifications after a Chrome restart. |
| + |
| + if (notification_synchronization_supported && |
| + displayed_notifications->empty()) { |
| + prune_database_on_open_ = true; |
| + } |
| + |
| // |service_worker_context_| may be NULL in tests. |
| if (service_worker_context_) |
| service_worker_context_->AddObserver(this); |
| @@ -181,7 +196,25 @@ void PlatformNotificationContextImpl::DoReadNotificationData( |
| } |
| void PlatformNotificationContextImpl:: |
| - SynchronizeDisplayedNotificationsForServiceWorkerRegistration( |
| + SynchronizeDisplayedNotificationsForServiceWorkerRegistrationOnUI( |
| + const GURL& origin, |
| + int64_t service_worker_registration_id, |
| + const ReadAllResultCallback& callback, |
| + std::unique_ptr<std::set<std::string>> notification_ids, |
| + bool sync_supported) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind( |
| + &PlatformNotificationContextImpl:: |
| + SynchronizeDisplayedNotificationsForServiceWorkerRegistrationOnIO, |
| + this, origin, service_worker_registration_id, callback, |
| + base::Passed(¬ification_ids), sync_supported)); |
| +} |
| + |
| +void PlatformNotificationContextImpl:: |
| + SynchronizeDisplayedNotificationsForServiceWorkerRegistrationOnIO( |
| const GURL& origin, |
| int64_t service_worker_registration_id, |
| const ReadAllResultCallback& callback, |
| @@ -212,24 +245,21 @@ void PlatformNotificationContextImpl:: |
| if (!service) { |
| // Rely on the database only |
| - SynchronizeDisplayedNotificationsForServiceWorkerRegistration( |
| + SynchronizeDisplayedNotificationsForServiceWorkerRegistrationOnIO( |
| origin, service_worker_registration_id, callback, |
| std::move(notification_ids), false /* sync_supported */); |
|
Peter Beverloo
2017/03/15 18:07:51
Here too, maybe we should just drop out?
call
Miguel Garcia
2017/03/16 14:57:42
I think we have some tests that rely on this right
|
| return; |
| } |
| - std::set<std::string>* notification_ids_ptr = notification_ids.get(); |
| - |
| - BrowserThread::PostTaskAndReplyWithResult( |
| + BrowserThread::PostTask( |
| BrowserThread::UI, FROM_HERE, |
| - base::Bind(&PlatformNotificationService::GetDisplayedNotifications, |
| - base::Unretained(service), browser_context_, |
| - notification_ids_ptr), |
| base::Bind( |
| - &PlatformNotificationContextImpl:: |
| - SynchronizeDisplayedNotificationsForServiceWorkerRegistration, |
| - this, origin, service_worker_registration_id, callback, |
| - base::Passed(¬ification_ids))); |
| + &PlatformNotificationService::GetDisplayedNotifications, |
| + base::Unretained(service), browser_context_, |
| + base::Bind( |
| + &PlatformNotificationContextImpl:: |
| + SynchronizeDisplayedNotificationsForServiceWorkerRegistrationOnUI, |
| + this, origin, service_worker_registration_id, callback))); |
| } |
| void PlatformNotificationContextImpl:: |