Chromium Code Reviews| Index: content/browser/notifications/notification_event_dispatcher_impl.cc |
| diff --git a/content/browser/notifications/notification_event_dispatcher_impl.cc b/content/browser/notifications/notification_event_dispatcher_impl.cc |
| index ae529c283b3d34f796ecaa6b3e9fe810ff583880..7cf2e2b1ecb131f92650af25b20f725ea7ea32ee 100644 |
| --- a/content/browser/notifications/notification_event_dispatcher_impl.cc |
| +++ b/content/browser/notifications/notification_event_dispatcher_impl.cc |
| @@ -7,12 +7,16 @@ |
| #include "base/callback.h" |
| #include "base/optional.h" |
| #include "build/build_config.h" |
| +#include "content/browser/notifications/notification_message_filter.h" |
| #include "content/browser/notifications/platform_notification_context_impl.h" |
| +#include "content/browser/renderer_host/render_process_host_impl.h" |
| #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| #include "content/browser/service_worker/service_worker_registration.h" |
| #include "content/browser/service_worker/service_worker_storage.h" |
| +#include "content/common/platform_notification_messages.h" |
| #include "content/public/browser/browser_context.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/storage_partition.h" |
| #include "content/public/common/platform_notification_data.h" |
| @@ -356,9 +360,8 @@ NotificationEventDispatcherImpl::GetInstance() { |
| return base::Singleton<NotificationEventDispatcherImpl>::get(); |
| } |
| -NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {} |
| - |
| -NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {} |
| +NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() = default; |
| +NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() = default; |
| void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( |
| BrowserContext* browser_context, |
| @@ -387,4 +390,71 @@ void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent( |
| dispatch_complete_callback); |
| } |
| +void NotificationEventDispatcherImpl::RegisterNonPersistentNotification( |
| + const std::string& notification_id, |
| + int renderer_id, |
| + int non_persistent_id) { |
| + notification_renderers_[notification_id] = renderer_id; |
| + notification_ids_[notification_id] = non_persistent_id; |
| +} |
| + |
| +void NotificationEventDispatcherImpl::DispatchNonPersistentShowEvent( |
| + const std::string& notification_id) { |
| + if (!notification_renderers_.count(notification_id)) |
| + return; |
| + DCHECK(notification_ids_.count(notification_id)); |
| + |
| + RenderProcessHost* sender = |
| + RenderProcessHost::FromID(notification_renderers_[notification_id]); |
| + if (!sender) |
| + return; |
| + |
| + sender->Send( |
| + new PlatformNotificationMsg_DidShow(notification_ids_[notification_id])); |
| +} |
| + |
| +void NotificationEventDispatcherImpl::DispatchNonPersistentClickEvent( |
| + const std::string& notification_id) { |
| + if (!notification_renderers_.count(notification_id)) |
| + return; |
| + DCHECK(notification_ids_.count(notification_id)); |
| + |
| + RenderProcessHost* sender = |
| + RenderProcessHost::FromID(notification_renderers_[notification_id]); |
| + if (!sender) |
| + return; |
| + sender->Send( |
| + new PlatformNotificationMsg_DidClick(notification_ids_[notification_id])); |
| +} |
| + |
| +void NotificationEventDispatcherImpl::DispatchNonPersistentCloseEvent( |
| + const std::string& notification_id) { |
| + if (!notification_renderers_.count(notification_id)) |
| + return; |
| + DCHECK(notification_ids_.count(notification_id)); |
| + |
| + RenderProcessHost* sender = |
| + RenderProcessHost::FromID(notification_renderers_[notification_id]); |
| + if (!sender) |
| + return; |
|
Peter Beverloo
2017/05/31 17:52:42
It may be good to describe when this case (and the
Miguel Garcia
2017/06/01 17:00:53
Done.
|
| + sender->Send( |
| + new PlatformNotificationMsg_DidClose(notification_ids_[notification_id])); |
| + |
| + static_cast<RenderProcessHostImpl*>(sender) |
| + ->notification_message_filter() |
| + ->DidCloseNotification(notification_id); |
| +} |
| + |
| +void NotificationEventDispatcherImpl::RendererGone(int renderer_id) { |
| + for (auto iter = notification_renderers_.begin(); |
|
Peter Beverloo
2017/05/31 17:52:43
Assuming you go with the pair solution, include //
Miguel Garcia
2017/06/01 17:00:53
Acknowledged.
|
| + iter != notification_renderers_.end();) { |
| + if (iter->second == renderer_id) { |
| + notification_ids_.erase(iter->first); |
| + iter = notification_renderers_.erase(iter); |
| + } else { |
| + iter++; |
| + } |
| + } |
| +} |
| + |
| } // namespace content |