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/strings/nullable_string16.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 9 #include "content/browser/notifications/platform_notification_context_impl.h" | 11 #include "content/browser/notifications/platform_notification_context_impl.h" |
| 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 11 #include "content/browser/service_worker/service_worker_registration.h" | 13 #include "content/browser/service_worker/service_worker_registration.h" |
| 12 #include "content/browser/service_worker/service_worker_storage.h" | 14 #include "content/browser/service_worker/service_worker_storage.h" |
| 13 #include "content/common/service_worker/service_worker_messages.h" | 15 #include "content/common/service_worker/service_worker_messages.h" |
| 14 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/storage_partition.h" | 18 #include "content/public/browser/storage_partition.h" |
| 17 #include "content/public/common/platform_notification_data.h" | 19 #include "content/public/common/platform_notification_data.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 } | 198 } |
| 197 | 199 |
| 198 // ----------------------------------------------------------------------------- | 200 // ----------------------------------------------------------------------------- |
| 199 | 201 |
| 200 // Dispatches the notificationclick event on |service_worker|. Must be called on | 202 // Dispatches the notificationclick event on |service_worker|. Must be called on |
| 201 // the IO thread, and with the worker running. | 203 // the IO thread, and with the worker running. |
| 202 void DispatchNotificationClickEventOnWorker( | 204 void DispatchNotificationClickEventOnWorker( |
| 203 const scoped_refptr<ServiceWorkerVersion>& service_worker, | 205 const scoped_refptr<ServiceWorkerVersion>& service_worker, |
| 204 const NotificationDatabaseData& notification_database_data, | 206 const NotificationDatabaseData& notification_database_data, |
| 205 int action_index, | 207 int action_index, |
| 208 const base::NullableString16& reply, | |
| 206 const ServiceWorkerVersion::StatusCallback& callback) { | 209 const ServiceWorkerVersion::StatusCallback& callback) { |
| 207 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 210 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 208 int request_id = service_worker->StartRequest( | 211 int request_id = service_worker->StartRequest( |
| 209 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback); | 212 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback); |
| 210 service_worker->DispatchSimpleEvent< | 213 service_worker->DispatchSimpleEvent< |
| 211 ServiceWorkerHostMsg_NotificationClickEventFinished>( | 214 ServiceWorkerHostMsg_NotificationClickEventFinished>( |
| 212 request_id, | 215 request_id, |
| 213 ServiceWorkerMsg_NotificationClickEvent( | 216 ServiceWorkerMsg_NotificationClickEvent( |
| 214 request_id, notification_database_data.notification_id, | 217 request_id, notification_database_data.notification_id, |
| 215 notification_database_data.notification_data, action_index)); | 218 notification_database_data.notification_data, action_index, |
| 219 reply.is_null() ? base::ASCIIToUTF16("") : reply.string())); | |
|
Peter Beverloo
2016/10/11 14:22:56
Why don't we just pass the NullableString16 over I
awdf
2016/10/11 15:51:27
Thinking about it, I'm not 100% sure the differenc
awdf
2016/10/12 13:26:42
Done (As discussed on the doc, the difference can
| |
| 216 } | 220 } |
| 217 | 221 |
| 218 // Dispatches the notification click event on the |service_worker_registration|. | 222 // Dispatches the notification click event on the |service_worker_registration|. |
| 219 void DoDispatchNotificationClickEvent( | 223 void DoDispatchNotificationClickEvent( |
| 220 int action_index, | 224 int action_index, |
| 225 const base::NullableString16& reply, | |
| 221 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | 226 const NotificationDispatchCompleteCallback& dispatch_complete_callback, |
| 222 const scoped_refptr<PlatformNotificationContext>& notification_context, | 227 const scoped_refptr<PlatformNotificationContext>& notification_context, |
| 223 const ServiceWorkerRegistration* service_worker_registration, | 228 const ServiceWorkerRegistration* service_worker_registration, |
| 224 const NotificationDatabaseData& notification_database_data) { | 229 const NotificationDatabaseData& notification_database_data) { |
| 225 ServiceWorkerVersion::StatusCallback status_callback = base::Bind( | 230 ServiceWorkerVersion::StatusCallback status_callback = base::Bind( |
| 226 &ServiceWorkerNotificationEventFinished, dispatch_complete_callback); | 231 &ServiceWorkerNotificationEventFinished, dispatch_complete_callback); |
| 227 service_worker_registration->active_version()->RunAfterStartWorker( | 232 service_worker_registration->active_version()->RunAfterStartWorker( |
| 228 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, | 233 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, |
| 229 base::Bind( | 234 base::Bind( |
| 230 &DispatchNotificationClickEventOnWorker, | 235 &DispatchNotificationClickEventOnWorker, |
| 231 make_scoped_refptr(service_worker_registration->active_version()), | 236 make_scoped_refptr(service_worker_registration->active_version()), |
| 232 notification_database_data, action_index, status_callback), | 237 notification_database_data, action_index, reply, status_callback), |
| 233 status_callback); | 238 status_callback); |
| 234 } | 239 } |
| 235 | 240 |
| 236 // ----------------------------------------------------------------------------- | 241 // ----------------------------------------------------------------------------- |
| 237 | 242 |
| 238 // Called when the notification data has been deleted to finish the notification | 243 // Called when the notification data has been deleted to finish the notification |
| 239 // close event. | 244 // close event. |
| 240 void OnPersistentNotificationDataDeleted( | 245 void OnPersistentNotificationDataDeleted( |
| 241 ServiceWorkerStatusCode service_worker_status, | 246 ServiceWorkerStatusCode service_worker_status, |
| 242 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | 247 const NotificationDispatchCompleteCallback& dispatch_complete_callback, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 | 358 |
| 354 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {} | 359 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {} |
| 355 | 360 |
| 356 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {} | 361 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {} |
| 357 | 362 |
| 358 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( | 363 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( |
| 359 BrowserContext* browser_context, | 364 BrowserContext* browser_context, |
| 360 const std::string& notification_id, | 365 const std::string& notification_id, |
| 361 const GURL& origin, | 366 const GURL& origin, |
| 362 int action_index, | 367 int action_index, |
| 368 const base::NullableString16& reply, | |
| 363 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { | 369 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { |
| 364 DispatchNotificationEvent( | 370 DispatchNotificationEvent( |
| 365 browser_context, notification_id, origin, | 371 browser_context, notification_id, origin, |
| 366 base::Bind(&DoDispatchNotificationClickEvent, action_index, | 372 base::Bind(&DoDispatchNotificationClickEvent, action_index, reply, |
| 367 dispatch_complete_callback), | 373 dispatch_complete_callback), |
| 368 dispatch_complete_callback); | 374 dispatch_complete_callback); |
| 369 } | 375 } |
| 370 | 376 |
| 371 void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent( | 377 void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent( |
| 372 BrowserContext* browser_context, | 378 BrowserContext* browser_context, |
| 373 const std::string& notification_id, | 379 const std::string& notification_id, |
| 374 const GURL& origin, | 380 const GURL& origin, |
| 375 bool by_user, | 381 bool by_user, |
| 376 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { | 382 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { |
| 377 DispatchNotificationEvent( | 383 DispatchNotificationEvent( |
| 378 browser_context, notification_id, origin, | 384 browser_context, notification_id, origin, |
| 379 base::Bind(&DoDispatchNotificationCloseEvent, notification_id, by_user, | 385 base::Bind(&DoDispatchNotificationCloseEvent, notification_id, by_user, |
| 380 dispatch_complete_callback), | 386 dispatch_complete_callback), |
| 381 dispatch_complete_callback); | 387 dispatch_complete_callback); |
| 382 } | 388 } |
| 383 | 389 |
| 384 } // namespace content | 390 } // namespace content |
| OLD | NEW |