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 db6f1361a16d6ca41bf25abf7a2883ee0e552741..f2a9a2a4097af87e7ee17e8012597a982f07d818 100644 |
| --- a/content/browser/notifications/platform_notification_context_impl.cc |
| +++ b/content/browser/notifications/platform_notification_context_impl.cc |
| @@ -11,7 +11,9 @@ |
| #include "content/browser/notifications/notification_database.h" |
| #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/content_browser_client.h" |
| #include "content/public/browser/notification_database_data.h" |
| +#include "content/public/browser/platform_notification_service.h" |
| using base::DoNothing; |
| @@ -24,8 +26,10 @@ const base::FilePath::CharType kPlatformNotificationsDirectory[] = |
| PlatformNotificationContextImpl::PlatformNotificationContextImpl( |
| const base::FilePath& path, |
| + BrowserContext* browser_context, |
| const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context) |
| : path_(path), |
| + browser_context_(browser_context), |
| service_worker_context_(service_worker_context) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| } |
| @@ -43,6 +47,30 @@ PlatformNotificationContextImpl::~PlatformNotificationContextImpl() { |
| 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->GetDisplayedPersistentNotifications(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.size()) { |
|
johnme
2015/05/14 15:22:32
Until you implement GetDisplayedPersistentNotifica
Peter Beverloo
2015/05/14 16:03:35
Supporting the Android case is covered by |notific
|
| + prune_database_on_open_ = true; |
| + } |
| + } |
| + |
| BrowserThread::PostTask( |
| BrowserThread::IO, |
| FROM_HERE, |
| @@ -323,6 +351,11 @@ void PlatformNotificationContextImpl::OpenDatabase( |
| return; |
| } |
| + if (prune_database_on_open_) { |
| + prune_database_on_open_ = false; |
| + DestroyDatabase(); |
|
johnme
2015/05/14 15:22:32
- Shouldn't this go after `database_.reset(new Not
Peter Beverloo
2015/05/14 16:03:35
Done
johnme
2015/05/14 16:40:51
I'm talking about when DestroyDatabase returns fal
|
| + } |
| + |
| database_.reset(new NotificationDatabase(GetDatabasePath())); |
| NotificationDatabase::Status status = |
| database_->Open(true /* create_if_missing */); |