Index: chrome/browser/notifications/platform_notification_service_impl.cc |
diff --git a/chrome/browser/notifications/platform_notification_service_impl.cc b/chrome/browser/notifications/platform_notification_service_impl.cc |
index 5b0608c155a0a2065aad0aefb5f6124dc46a1d5d..a68fd7a57bbb1fe0662424f69a697fda92d40b97 100644 |
--- a/chrome/browser/notifications/platform_notification_service_impl.cc |
+++ b/chrome/browser/notifications/platform_notification_service_impl.cc |
@@ -36,6 +36,10 @@ |
#include "extensions/common/permissions/permissions_data.h" |
#endif |
+#if defined(OS_ANDROID) |
+#include "base/strings/string_number_conversions.h" |
+#endif |
+ |
using content::BrowserThread; |
using message_center::NotifierId; |
@@ -61,20 +65,16 @@ PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
void PlatformNotificationServiceImpl::OnPersistentNotificationClick( |
content::BrowserContext* browser_context, |
- int64 service_worker_registration_id, |
- const std::string& notification_id, |
+ int64_t persistent_notification_id, |
const GURL& origin, |
- const content::PlatformNotificationData& notification_data, |
const base::Callback<void(content::PersistentNotificationStatus)>& |
callback) const { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
content::NotificationEventDispatcher::GetInstance() |
->DispatchNotificationClickEvent( |
browser_context, |
+ persistent_notification_id, |
origin, |
- service_worker_registration_id, |
- notification_id, |
- notification_data, |
callback); |
} |
@@ -218,7 +218,7 @@ void PlatformNotificationServiceImpl::DisplayNotification( |
void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
content::BrowserContext* browser_context, |
- int64 service_worker_registration_id, |
+ int64_t persistent_notification_id, |
const GURL& origin, |
const SkBitmap& icon, |
const content::PlatformNotificationData& notification_data) { |
@@ -228,14 +228,15 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
DCHECK(profile); |
PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( |
- browser_context, |
- service_worker_registration_id, |
- origin, |
- notification_data); |
+ browser_context, persistent_notification_id, origin); |
Notification notification = CreateNotificationFromData( |
profile, origin, icon, notification_data, delegate); |
+ // TODO(peter): Remove this mapping when we have reliable id generation for |
+ // the message_center::Notification objects. |
+ persistent_notifications_[persistent_notification_id] = notification.id(); |
+ |
GetNotificationUIManager()->Add(notification, profile); |
profile->GetHostContentSettingsMap()->UpdateLastUsage( |
@@ -244,14 +245,30 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
void PlatformNotificationServiceImpl::ClosePersistentNotification( |
content::BrowserContext* browser_context, |
- const std::string& persistent_notification_id) { |
+ int64_t persistent_notification_id) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Profile* profile = Profile::FromBrowserContext(browser_context); |
DCHECK(profile); |
+ auto iter = persistent_notifications_.find(persistent_notification_id); |
+ if (iter == persistent_notifications_.end()) { |
+#if defined(OS_ANDROID) |
+ // TODO(peter): Remove this conversion when the notification ids are being |
+ // generated by the caller of this method. |
+ std::string textual_persistent_notification_id = |
+ base::Int64ToString(persistent_notification_id); |
+ GetNotificationUIManager()->CancelById( |
+ textual_persistent_notification_id, |
+ NotificationUIManager::GetProfileID(profile)); |
+#endif |
+ return; |
+ } |
+ |
GetNotificationUIManager()->CancelById( |
- persistent_notification_id, NotificationUIManager::GetProfileID(profile)); |
+ iter->second, NotificationUIManager::GetProfileID(profile)); |
+ |
+ persistent_notifications_.erase(iter); |
} |
Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |