Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: content/browser/notifications/notification_event_dispatcher_impl.cc

Issue 2916383004: Revert of Minimize the delegate dependencies for non persistent notifications. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "content/browser/notifications/platform_notification_context_impl.h" 10 #include "content/browser/notifications/platform_notification_context_impl.h"
12 #include "content/browser/renderer_host/render_process_host_impl.h"
13 #include "content/browser/service_worker/service_worker_context_wrapper.h" 11 #include "content/browser/service_worker/service_worker_context_wrapper.h"
14 #include "content/browser/service_worker/service_worker_registration.h" 12 #include "content/browser/service_worker/service_worker_registration.h"
15 #include "content/browser/service_worker/service_worker_storage.h" 13 #include "content/browser/service_worker/service_worker_storage.h"
16 #include "content/common/platform_notification_messages.h"
17 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/render_process_host.h"
20 #include "content/public/browser/storage_partition.h" 16 #include "content/public/browser/storage_partition.h"
21 #include "content/public/common/platform_notification_data.h" 17 #include "content/public/common/platform_notification_data.h"
22 18
23 namespace content { 19 namespace content {
24 namespace { 20 namespace {
25 21
26 using NotificationDispatchCompleteCallback = 22 using NotificationDispatchCompleteCallback =
27 NotificationEventDispatcher::NotificationDispatchCompleteCallback; 23 NotificationEventDispatcher::NotificationDispatchCompleteCallback;
28 using NotificationOperationCallback = 24 using NotificationOperationCallback =
29 base::Callback<void(const ServiceWorkerRegistration*, 25 base::Callback<void(const ServiceWorkerRegistration*,
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() { 349 NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() {
354 return NotificationEventDispatcherImpl::GetInstance(); 350 return NotificationEventDispatcherImpl::GetInstance();
355 } 351 }
356 352
357 NotificationEventDispatcherImpl* 353 NotificationEventDispatcherImpl*
358 NotificationEventDispatcherImpl::GetInstance() { 354 NotificationEventDispatcherImpl::GetInstance() {
359 DCHECK_CURRENTLY_ON(BrowserThread::UI); 355 DCHECK_CURRENTLY_ON(BrowserThread::UI);
360 return base::Singleton<NotificationEventDispatcherImpl>::get(); 356 return base::Singleton<NotificationEventDispatcherImpl>::get();
361 } 357 }
362 358
363 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() = default; 359 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {}
364 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() = default; 360
361 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {}
365 362
366 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( 363 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent(
367 BrowserContext* browser_context, 364 BrowserContext* browser_context,
368 const std::string& notification_id, 365 const std::string& notification_id,
369 const GURL& origin, 366 const GURL& origin,
370 int action_index, 367 int action_index,
371 const base::NullableString16& reply, 368 const base::NullableString16& reply,
372 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { 369 const NotificationDispatchCompleteCallback& dispatch_complete_callback) {
373 DispatchNotificationEvent( 370 DispatchNotificationEvent(
374 browser_context, notification_id, origin, 371 browser_context, notification_id, origin,
375 base::Bind(&DoDispatchNotificationClickEvent, action_index, reply, 372 base::Bind(&DoDispatchNotificationClickEvent, action_index, reply,
376 dispatch_complete_callback), 373 dispatch_complete_callback),
377 dispatch_complete_callback); 374 dispatch_complete_callback);
378 } 375 }
379 376
380 void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent( 377 void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent(
381 BrowserContext* browser_context, 378 BrowserContext* browser_context,
382 const std::string& notification_id, 379 const std::string& notification_id,
383 const GURL& origin, 380 const GURL& origin,
384 bool by_user, 381 bool by_user,
385 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { 382 const NotificationDispatchCompleteCallback& dispatch_complete_callback) {
386 DispatchNotificationEvent( 383 DispatchNotificationEvent(
387 browser_context, notification_id, origin, 384 browser_context, notification_id, origin,
388 base::Bind(&DoDispatchNotificationCloseEvent, notification_id, by_user, 385 base::Bind(&DoDispatchNotificationCloseEvent, notification_id, by_user,
389 dispatch_complete_callback), 386 dispatch_complete_callback),
390 dispatch_complete_callback); 387 dispatch_complete_callback);
391 } 388 }
392 389
393 void NotificationEventDispatcherImpl::RegisterNonPersistentNotification(
394 const std::string& notification_id,
395 int renderer_id,
396 int non_persistent_id) {
397 renderer_ids_[notification_id] = renderer_id;
398 non_persistent_ids_[notification_id] = non_persistent_id;
399 }
400
401 void NotificationEventDispatcherImpl::DispatchNonPersistentShowEvent(
402 const std::string& notification_id) {
403 if (!renderer_ids_.count(notification_id))
404 return;
405 DCHECK(non_persistent_ids_.count(notification_id));
406
407 RenderProcessHost* sender =
408 RenderProcessHost::FromID(renderer_ids_[notification_id]);
409 if (!sender)
410 return;
411
412 sender->Send(new PlatformNotificationMsg_DidShow(
413 non_persistent_ids_[notification_id]));
414 }
415
416 void NotificationEventDispatcherImpl::DispatchNonPersistentClickEvent(
417 const std::string& notification_id) {
418 if (!renderer_ids_.count(notification_id))
419 return;
420 DCHECK(non_persistent_ids_.count(notification_id));
421
422 RenderProcessHost* sender =
423 RenderProcessHost::FromID(renderer_ids_[notification_id]);
424
425 // This can happen when a notification is clicked by the user but the
426 // renderer does not exist any more, for example because the tab has been
427 // closed.
428 if (!sender)
429 return;
430 sender->Send(new PlatformNotificationMsg_DidClick(
431 non_persistent_ids_[notification_id]));
432 }
433
434 void NotificationEventDispatcherImpl::DispatchNonPersistentCloseEvent(
435 const std::string& notification_id) {
436 if (!renderer_ids_.count(notification_id))
437 return;
438 DCHECK(non_persistent_ids_.count(notification_id));
439
440 RenderProcessHost* sender =
441 RenderProcessHost::FromID(renderer_ids_[notification_id]);
442
443 // This can happen when a notification is closed by the user but the
444 // renderer does not exist any more, for example because the tab has been
445 // closed.
446 if (!sender)
447 return;
448 sender->Send(new PlatformNotificationMsg_DidClose(
449 non_persistent_ids_[notification_id]));
450
451 static_cast<RenderProcessHostImpl*>(sender)
452 ->notification_message_filter()
453 ->DidCloseNotification(notification_id);
454 }
455
456 void NotificationEventDispatcherImpl::RendererGone(int renderer_id) {
457 for (auto iter = renderer_ids_.begin(); iter != renderer_ids_.end();) {
458 if (iter->second == renderer_id) {
459 non_persistent_ids_.erase(iter->first);
460 iter = renderer_ids_.erase(iter);
461 } else {
462 iter++;
463 }
464 }
465 }
466
467 } // namespace content 390 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698