Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/notifications/notification_event_dispatcher_impl.h" | 5 #include "content/browser/notifications/notification_event_dispatcher_impl.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/optional.h" | 8 #include "base/optional.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "content/browser/notifications/notification_message_filter.h" | |
| 10 #include "content/browser/notifications/platform_notification_context_impl.h" | 11 #include "content/browser/notifications/platform_notification_context_impl.h" |
| 12 #include "content/browser/renderer_host/render_process_host_impl.h" | |
| 11 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 13 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 12 #include "content/browser/service_worker/service_worker_registration.h" | 14 #include "content/browser/service_worker/service_worker_registration.h" |
| 13 #include "content/browser/service_worker/service_worker_storage.h" | 15 #include "content/browser/service_worker/service_worker_storage.h" |
| 16 #include "content/common/platform_notification_messages.h" | |
| 14 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/render_process_host.h" | |
| 16 #include "content/public/browser/storage_partition.h" | 20 #include "content/public/browser/storage_partition.h" |
| 17 #include "content/public/common/platform_notification_data.h" | 21 #include "content/public/common/platform_notification_data.h" |
| 18 | 22 |
| 19 namespace content { | 23 namespace content { |
| 20 namespace { | 24 namespace { |
| 21 | 25 |
| 22 using NotificationDispatchCompleteCallback = | 26 using NotificationDispatchCompleteCallback = |
| 23 NotificationEventDispatcher::NotificationDispatchCompleteCallback; | 27 NotificationEventDispatcher::NotificationDispatchCompleteCallback; |
| 24 using NotificationOperationCallback = | 28 using NotificationOperationCallback = |
| 25 base::Callback<void(const ServiceWorkerRegistration*, | 29 base::Callback<void(const ServiceWorkerRegistration*, |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() { | 353 NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() { |
| 350 return NotificationEventDispatcherImpl::GetInstance(); | 354 return NotificationEventDispatcherImpl::GetInstance(); |
| 351 } | 355 } |
| 352 | 356 |
| 353 NotificationEventDispatcherImpl* | 357 NotificationEventDispatcherImpl* |
| 354 NotificationEventDispatcherImpl::GetInstance() { | 358 NotificationEventDispatcherImpl::GetInstance() { |
| 355 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 359 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 356 return base::Singleton<NotificationEventDispatcherImpl>::get(); | 360 return base::Singleton<NotificationEventDispatcherImpl>::get(); |
| 357 } | 361 } |
| 358 | 362 |
| 359 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {} | 363 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() = default; |
| 360 | 364 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() = default; |
| 361 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {} | |
| 362 | 365 |
| 363 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( | 366 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( |
| 364 BrowserContext* browser_context, | 367 BrowserContext* browser_context, |
| 365 const std::string& notification_id, | 368 const std::string& notification_id, |
| 366 const GURL& origin, | 369 const GURL& origin, |
| 367 int action_index, | 370 int action_index, |
| 368 const base::NullableString16& reply, | 371 const base::NullableString16& reply, |
| 369 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { | 372 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { |
| 370 DispatchNotificationEvent( | 373 DispatchNotificationEvent( |
| 371 browser_context, notification_id, origin, | 374 browser_context, notification_id, origin, |
| 372 base::Bind(&DoDispatchNotificationClickEvent, action_index, reply, | 375 base::Bind(&DoDispatchNotificationClickEvent, action_index, reply, |
| 373 dispatch_complete_callback), | 376 dispatch_complete_callback), |
| 374 dispatch_complete_callback); | 377 dispatch_complete_callback); |
| 375 } | 378 } |
| 376 | 379 |
| 377 void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent( | 380 void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent( |
| 378 BrowserContext* browser_context, | 381 BrowserContext* browser_context, |
| 379 const std::string& notification_id, | 382 const std::string& notification_id, |
| 380 const GURL& origin, | 383 const GURL& origin, |
| 381 bool by_user, | 384 bool by_user, |
| 382 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { | 385 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { |
| 383 DispatchNotificationEvent( | 386 DispatchNotificationEvent( |
| 384 browser_context, notification_id, origin, | 387 browser_context, notification_id, origin, |
| 385 base::Bind(&DoDispatchNotificationCloseEvent, notification_id, by_user, | 388 base::Bind(&DoDispatchNotificationCloseEvent, notification_id, by_user, |
| 386 dispatch_complete_callback), | 389 dispatch_complete_callback), |
| 387 dispatch_complete_callback); | 390 dispatch_complete_callback); |
| 388 } | 391 } |
| 389 | 392 |
| 393 void NotificationEventDispatcherImpl::RegisterNonPersistentNotification( | |
| 394 const std::string& notification_id, | |
| 395 int renderer_id, | |
| 396 int non_persistent_id) { | |
| 397 notification_renderers_[notification_id] = renderer_id; | |
| 398 notification_ids_[notification_id] = non_persistent_id; | |
| 399 } | |
| 400 | |
| 401 void NotificationEventDispatcherImpl::DispatchNonPersistentShowEvent( | |
| 402 const std::string& notification_id) { | |
| 403 if (!notification_renderers_.count(notification_id)) | |
| 404 return; | |
| 405 DCHECK(notification_ids_.count(notification_id)); | |
| 406 | |
| 407 RenderProcessHost* sender = | |
| 408 RenderProcessHost::FromID(notification_renderers_[notification_id]); | |
| 409 if (!sender) | |
| 410 return; | |
| 411 | |
| 412 sender->Send( | |
| 413 new PlatformNotificationMsg_DidShow(notification_ids_[notification_id])); | |
| 414 } | |
| 415 | |
| 416 void NotificationEventDispatcherImpl::DispatchNonPersistentClickEvent( | |
| 417 const std::string& notification_id) { | |
| 418 if (!notification_renderers_.count(notification_id)) | |
| 419 return; | |
| 420 DCHECK(notification_ids_.count(notification_id)); | |
| 421 | |
| 422 RenderProcessHost* sender = | |
| 423 RenderProcessHost::FromID(notification_renderers_[notification_id]); | |
| 424 if (!sender) | |
| 425 return; | |
| 426 sender->Send( | |
| 427 new PlatformNotificationMsg_DidClick(notification_ids_[notification_id])); | |
| 428 } | |
| 429 | |
| 430 void NotificationEventDispatcherImpl::DispatchNonPersistentCloseEvent( | |
| 431 const std::string& notification_id) { | |
| 432 if (!notification_renderers_.count(notification_id)) | |
| 433 return; | |
| 434 DCHECK(notification_ids_.count(notification_id)); | |
| 435 | |
| 436 RenderProcessHost* sender = | |
| 437 RenderProcessHost::FromID(notification_renderers_[notification_id]); | |
| 438 if (!sender) | |
| 439 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.
| |
| 440 sender->Send( | |
| 441 new PlatformNotificationMsg_DidClose(notification_ids_[notification_id])); | |
| 442 | |
| 443 static_cast<RenderProcessHostImpl*>(sender) | |
| 444 ->notification_message_filter() | |
| 445 ->DidCloseNotification(notification_id); | |
| 446 } | |
| 447 | |
| 448 void NotificationEventDispatcherImpl::RendererGone(int renderer_id) { | |
| 449 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.
| |
| 450 iter != notification_renderers_.end();) { | |
| 451 if (iter->second == renderer_id) { | |
| 452 notification_ids_.erase(iter->first); | |
| 453 iter = notification_renderers_.erase(iter); | |
| 454 } else { | |
| 455 iter++; | |
| 456 } | |
| 457 } | |
| 458 } | |
| 459 | |
| 390 } // namespace content | 460 } // namespace content |
| OLD | NEW |