| 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 114f5caf15ab585db2a20ee968cee75327df1942..7b1472ac7d62e6cf12000c86bb5b7f3d667b9a75 100644
|
| --- a/chrome/browser/notifications/platform_notification_service_impl.cc
|
| +++ b/chrome/browser/notifications/platform_notification_service_impl.cc
|
| @@ -10,14 +10,12 @@
|
| #include "base/command_line.h"
|
| #include "base/metrics/histogram_macros.h"
|
| #include "base/metrics/user_metrics_action.h"
|
| -#include "base/strings/string_number_conversions.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "build/build_config.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
|
| #include "chrome/browser/notifications/notification_display_service_factory.h"
|
| #include "chrome/browser/notifications/notification_object_proxy.h"
|
| -#include "chrome/browser/notifications/notification_ui_manager.h"
|
| #include "chrome/browser/notifications/persistent_notification_delegate.h"
|
| #include "chrome/browser/permissions/permission_manager.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| @@ -36,7 +34,6 @@
|
| #include "content/public/browser/desktop_notification_delegate.h"
|
| #include "content/public/browser/notification_event_dispatcher.h"
|
| #include "content/public/browser/permission_type.h"
|
| -#include "content/public/browser/platform_notification_context.h"
|
| #include "content/public/browser/storage_partition.h"
|
| #include "content/public/browser/user_metrics.h"
|
| #include "content/public/common/notification_resources.h"
|
| @@ -63,7 +60,6 @@
|
|
|
| using content::BrowserContext;
|
| using content::BrowserThread;
|
| -using content::PlatformNotificationContext;
|
| using message_center::NotifierId;
|
|
|
| class ProfileAttributesEntry;
|
| @@ -112,7 +108,7 @@ PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {}
|
|
|
| void PlatformNotificationServiceImpl::OnPersistentNotificationClick(
|
| BrowserContext* browser_context,
|
| - int64_t persistent_notification_id,
|
| + const std::string& notification_id,
|
| const GURL& origin,
|
| int action_index) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| @@ -147,7 +143,7 @@ void PlatformNotificationServiceImpl::OnPersistentNotificationClick(
|
|
|
| content::NotificationEventDispatcher::GetInstance()
|
| ->DispatchNotificationClickEvent(
|
| - browser_context, persistent_notification_id, origin, action_index,
|
| + browser_context, notification_id, origin, action_index,
|
| base::Bind(
|
| &PlatformNotificationServiceImpl::OnClickEventDispatchComplete,
|
| base::Unretained(this)));
|
| @@ -155,13 +151,13 @@ void PlatformNotificationServiceImpl::OnPersistentNotificationClick(
|
|
|
| void PlatformNotificationServiceImpl::OnPersistentNotificationClose(
|
| BrowserContext* browser_context,
|
| - int64_t persistent_notification_id,
|
| + const std::string& notification_id,
|
| const GURL& origin,
|
| bool by_user) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
| // If we programatically closed this notification, don't dispatch any event.
|
| - if (closed_notifications_.erase(persistent_notification_id) != 0)
|
| + if (closed_notifications_.erase(notification_id) != 0)
|
| return;
|
|
|
| if (by_user) {
|
| @@ -173,7 +169,7 @@ void PlatformNotificationServiceImpl::OnPersistentNotificationClose(
|
| }
|
| content::NotificationEventDispatcher::GetInstance()
|
| ->DispatchNotificationCloseEvent(
|
| - browser_context, persistent_notification_id, origin, by_user,
|
| + browser_context, notification_id, origin, by_user,
|
| base::Bind(
|
| &PlatformNotificationServiceImpl::OnCloseEventDispatchComplete,
|
| base::Unretained(this)));
|
| @@ -271,6 +267,7 @@ PlatformNotificationServiceImpl::CheckPermissionOnIOThread(
|
|
|
| void PlatformNotificationServiceImpl::DisplayNotification(
|
| BrowserContext* browser_context,
|
| + const std::string& notification_id,
|
| const GURL& origin,
|
| const content::PlatformNotificationData& notification_data,
|
| const content::NotificationResources& notification_resources,
|
| @@ -289,8 +286,8 @@ void PlatformNotificationServiceImpl::DisplayNotification(
|
| DCHECK_EQ(0u, notification_data.actions.size());
|
| DCHECK_EQ(0u, notification_resources.action_icons.size());
|
|
|
| - NotificationObjectProxy* proxy =
|
| - new NotificationObjectProxy(browser_context, std::move(delegate));
|
| + NotificationObjectProxy* proxy = new NotificationObjectProxy(
|
| + browser_context, notification_id, std::move(delegate));
|
| Notification notification = CreateNotificationFromData(
|
| profile, GURL() /* service_worker_scope */, origin, notification_data,
|
| notification_resources, proxy);
|
| @@ -316,7 +313,7 @@ void PlatformNotificationServiceImpl::DisplayNotification(
|
|
|
| void PlatformNotificationServiceImpl::DisplayPersistentNotification(
|
| BrowserContext* browser_context,
|
| - int64_t persistent_notification_id,
|
| + const std::string& notification_id,
|
| const GURL& service_worker_scope,
|
| const GURL& origin,
|
| const content::PlatformNotificationData& notification_data,
|
| @@ -336,21 +333,14 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification(
|
| // supplied buttons, available in |notification_data.actions|.
|
| int settings_button_index = notification_data.actions.size();
|
| PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate(
|
| - browser_context, persistent_notification_id, origin,
|
| - settings_button_index);
|
| + browser_context, notification_id, origin, settings_button_index);
|
|
|
| Notification notification = CreateNotificationFromData(
|
| profile, service_worker_scope, origin, notification_data,
|
| notification_resources, 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();
|
| -
|
| GetNotificationDisplayService(profile)->Display(
|
| - NotificationCommon::PERSISTENT,
|
| - base::Int64ToString(delegate->persistent_notification_id()),
|
| - notification);
|
| + NotificationCommon::PERSISTENT, notification_id, notification);
|
| content::RecordAction(
|
| base::UserMetricsAction("Notifications.Persistent.Shown"));
|
|
|
| @@ -360,36 +350,16 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification(
|
|
|
| void PlatformNotificationServiceImpl::ClosePersistentNotification(
|
| BrowserContext* browser_context,
|
| - int64_t persistent_notification_id) {
|
| + const std::string& notification_id) {
|
| DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
|
| Profile* profile = Profile::FromBrowserContext(browser_context);
|
| DCHECK(profile);
|
|
|
| - closed_notifications_.insert(persistent_notification_id);
|
| -
|
| -#if defined(OS_ANDROID)
|
| - bool cancel_by_persistent_id = true;
|
| -#else
|
| - bool cancel_by_persistent_id =
|
| - GetNotificationDisplayService(profile)->SupportsNotificationCenter();
|
| -#endif
|
| -
|
| - if (cancel_by_persistent_id) {
|
| - // TODO(peter): Remove this conversion when the notification ids are being
|
| - // generated by the caller of this method.
|
| - GetNotificationDisplayService(profile)->Close(
|
| - NotificationCommon::PERSISTENT,
|
| - base::Int64ToString(persistent_notification_id));
|
| - } else {
|
| - auto iter = persistent_notifications_.find(persistent_notification_id);
|
| - if (iter == persistent_notifications_.end())
|
| - return;
|
| - GetNotificationDisplayService(profile)->Close(
|
| - NotificationCommon::PERSISTENT, iter->second);
|
| - }
|
| + closed_notifications_.insert(notification_id);
|
|
|
| - persistent_notifications_.erase(persistent_notification_id);
|
| + GetNotificationDisplayService(profile)->Close(NotificationCommon::PERSISTENT,
|
| + notification_id);
|
| }
|
|
|
| bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications(
|
| @@ -444,9 +414,8 @@ Notification PlatformNotificationServiceImpl::CreateNotificationFromData(
|
| message_center::NOTIFICATION_TYPE_SIMPLE, notification_data.title,
|
| notification_data.body,
|
| gfx::Image::CreateFrom1xBitmap(notification_resources.notification_icon),
|
| - message_center::NotifierId(origin), base::UTF8ToUTF16(origin.host()),
|
| - origin, notification_data.tag, message_center::RichNotificationData(),
|
| - delegate);
|
| + NotifierId(origin), base::UTF8ToUTF16(origin.host()), origin,
|
| + notification_data.tag, message_center::RichNotificationData(), delegate);
|
|
|
| notification.set_service_worker_scope(service_worker_scope);
|
| notification.set_context_message(
|
|
|