| 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 "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "content/browser/notifications/platform_notification_context_impl.h" | 9 #include "content/browser/notifications/platform_notification_context_impl.h" |
| 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 | 197 |
| 198 // ----------------------------------------------------------------------------- | 198 // ----------------------------------------------------------------------------- |
| 199 | 199 |
| 200 // Dispatches the notificationclick event on |service_worker|. Must be called on | 200 // Dispatches the notificationclick event on |service_worker|. Must be called on |
| 201 // the IO thread, and with the worker running. | 201 // the IO thread, and with the worker running. |
| 202 void DispatchNotificationClickEventOnWorker( | 202 void DispatchNotificationClickEventOnWorker( |
| 203 const scoped_refptr<ServiceWorkerVersion>& service_worker, | 203 const scoped_refptr<ServiceWorkerVersion>& service_worker, |
| 204 const NotificationDatabaseData& notification_database_data, | 204 const NotificationDatabaseData& notification_database_data, |
| 205 int action_index, | 205 int action_index, |
| 206 const base::NullableString16& reply, |
| 206 const ServiceWorkerVersion::StatusCallback& callback) { | 207 const ServiceWorkerVersion::StatusCallback& callback) { |
| 207 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 208 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 208 int request_id = service_worker->StartRequest( | 209 int request_id = service_worker->StartRequest( |
| 209 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback); | 210 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback); |
| 210 service_worker->DispatchSimpleEvent< | 211 service_worker->DispatchSimpleEvent< |
| 211 ServiceWorkerHostMsg_NotificationClickEventFinished>( | 212 ServiceWorkerHostMsg_NotificationClickEventFinished>( |
| 212 request_id, | 213 request_id, |
| 213 ServiceWorkerMsg_NotificationClickEvent( | 214 ServiceWorkerMsg_NotificationClickEvent( |
| 214 request_id, notification_database_data.notification_id, | 215 request_id, notification_database_data.notification_id, |
| 215 notification_database_data.notification_data, action_index)); | 216 notification_database_data.notification_data, action_index, reply)); |
| 216 } | 217 } |
| 217 | 218 |
| 218 // Dispatches the notification click event on the |service_worker_registration|. | 219 // Dispatches the notification click event on the |service_worker_registration|. |
| 219 void DoDispatchNotificationClickEvent( | 220 void DoDispatchNotificationClickEvent( |
| 220 int action_index, | 221 int action_index, |
| 222 const base::NullableString16& reply, |
| 221 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | 223 const NotificationDispatchCompleteCallback& dispatch_complete_callback, |
| 222 const scoped_refptr<PlatformNotificationContext>& notification_context, | 224 const scoped_refptr<PlatformNotificationContext>& notification_context, |
| 223 const ServiceWorkerRegistration* service_worker_registration, | 225 const ServiceWorkerRegistration* service_worker_registration, |
| 224 const NotificationDatabaseData& notification_database_data) { | 226 const NotificationDatabaseData& notification_database_data) { |
| 225 ServiceWorkerVersion::StatusCallback status_callback = base::Bind( | 227 ServiceWorkerVersion::StatusCallback status_callback = base::Bind( |
| 226 &ServiceWorkerNotificationEventFinished, dispatch_complete_callback); | 228 &ServiceWorkerNotificationEventFinished, dispatch_complete_callback); |
| 227 service_worker_registration->active_version()->RunAfterStartWorker( | 229 service_worker_registration->active_version()->RunAfterStartWorker( |
| 228 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, | 230 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, |
| 229 base::Bind( | 231 base::Bind( |
| 230 &DispatchNotificationClickEventOnWorker, | 232 &DispatchNotificationClickEventOnWorker, |
| 231 make_scoped_refptr(service_worker_registration->active_version()), | 233 make_scoped_refptr(service_worker_registration->active_version()), |
| 232 notification_database_data, action_index, status_callback), | 234 notification_database_data, action_index, reply, status_callback), |
| 233 status_callback); | 235 status_callback); |
| 234 } | 236 } |
| 235 | 237 |
| 236 // ----------------------------------------------------------------------------- | 238 // ----------------------------------------------------------------------------- |
| 237 | 239 |
| 238 // Called when the notification data has been deleted to finish the notification | 240 // Called when the notification data has been deleted to finish the notification |
| 239 // close event. | 241 // close event. |
| 240 void OnPersistentNotificationDataDeleted( | 242 void OnPersistentNotificationDataDeleted( |
| 241 ServiceWorkerStatusCode service_worker_status, | 243 ServiceWorkerStatusCode service_worker_status, |
| 242 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | 244 const NotificationDispatchCompleteCallback& dispatch_complete_callback, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 355 |
| 354 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {} | 356 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {} |
| 355 | 357 |
| 356 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {} | 358 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {} |
| 357 | 359 |
| 358 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( | 360 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( |
| 359 BrowserContext* browser_context, | 361 BrowserContext* browser_context, |
| 360 const std::string& notification_id, | 362 const std::string& notification_id, |
| 361 const GURL& origin, | 363 const GURL& origin, |
| 362 int action_index, | 364 int action_index, |
| 365 const base::NullableString16& reply, |
| 363 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { | 366 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { |
| 364 DispatchNotificationEvent( | 367 DispatchNotificationEvent( |
| 365 browser_context, notification_id, origin, | 368 browser_context, notification_id, origin, |
| 366 base::Bind(&DoDispatchNotificationClickEvent, action_index, | 369 base::Bind(&DoDispatchNotificationClickEvent, action_index, reply, |
| 367 dispatch_complete_callback), | 370 dispatch_complete_callback), |
| 368 dispatch_complete_callback); | 371 dispatch_complete_callback); |
| 369 } | 372 } |
| 370 | 373 |
| 371 void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent( | 374 void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent( |
| 372 BrowserContext* browser_context, | 375 BrowserContext* browser_context, |
| 373 const std::string& notification_id, | 376 const std::string& notification_id, |
| 374 const GURL& origin, | 377 const GURL& origin, |
| 375 bool by_user, | 378 bool by_user, |
| 376 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { | 379 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { |
| 377 DispatchNotificationEvent( | 380 DispatchNotificationEvent( |
| 378 browser_context, notification_id, origin, | 381 browser_context, notification_id, origin, |
| 379 base::Bind(&DoDispatchNotificationCloseEvent, notification_id, by_user, | 382 base::Bind(&DoDispatchNotificationCloseEvent, notification_id, by_user, |
| 380 dispatch_complete_callback), | 383 dispatch_complete_callback), |
| 381 dispatch_complete_callback); | 384 dispatch_complete_callback); |
| 382 } | 385 } |
| 383 | 386 |
| 384 } // namespace content | 387 } // namespace content |
| OLD | NEW |