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 "build/build_config.h" | 9 #include "build/build_config.h" |
| 9 #include "content/browser/notifications/platform_notification_context_impl.h" | 10 #include "content/browser/notifications/platform_notification_context_impl.h" |
| 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 11 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 11 #include "content/browser/service_worker/service_worker_registration.h" | 12 #include "content/browser/service_worker/service_worker_registration.h" |
| 12 #include "content/browser/service_worker/service_worker_storage.h" | 13 #include "content/browser/service_worker/service_worker_storage.h" |
| 13 #include "content/common/service_worker/service_worker_messages.h" | |
| 14 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
| 17 #include "content/public/common/platform_notification_data.h" | 17 #include "content/public/common/platform_notification_data.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 using NotificationDispatchCompleteCallback = | 22 using NotificationDispatchCompleteCallback = |
| 23 NotificationEventDispatcher::NotificationDispatchCompleteCallback; | 23 NotificationEventDispatcher::NotificationDispatchCompleteCallback; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 base::NullableString16& reply, |
| 207 const ServiceWorkerVersion::StatusCallback& callback) { | 207 const ServiceWorkerVersion::StatusCallback& callback) { |
| 208 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 208 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 209 int request_id = service_worker->StartRequest( | 209 int request_id = service_worker->StartRequest( |
| 210 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback); | 210 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback); |
| 211 service_worker->DispatchSimpleEvent< | 211 |
| 212 ServiceWorkerHostMsg_NotificationClickEventFinished>( | 212 base::Optional<base::string16> optional_reply; |
|
awdf
2017/02/13 07:04:42
Is Optional<string> preferable to NullableString i
Peter Beverloo
2017/02/13 14:14:33
It's necessary for Mojo, but since base::Optional
| |
| 213 request_id, | 213 if (!reply.is_null()) |
| 214 ServiceWorkerMsg_NotificationClickEvent( | 214 optional_reply = reply.string(); |
| 215 request_id, notification_database_data.notification_id, | 215 |
| 216 notification_database_data.notification_data, action_index, reply)); | 216 service_worker->event_dispatcher()->DispatchNotificationClickEvent( |
| 217 notification_database_data.notification_id, | |
| 218 notification_database_data.notification_data, action_index, | |
| 219 optional_reply, base::Bind(&ServiceWorkerVersion::OnSimpleEventFinished, | |
| 220 service_worker, request_id)); | |
|
Peter Beverloo
2017/02/10 03:21:28
Err, this and line 288 need to use base::Unretaine
Peter Beverloo
2017/02/10 16:41:06
Done.
| |
| 217 } | 221 } |
| 218 | 222 |
| 219 // Dispatches the notification click event on the |service_worker_registration|. | 223 // Dispatches the notification click event on the |service_worker_registration|. |
| 220 void DoDispatchNotificationClickEvent( | 224 void DoDispatchNotificationClickEvent( |
| 221 int action_index, | 225 int action_index, |
| 222 const base::NullableString16& reply, | 226 const base::NullableString16& reply, |
| 223 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | 227 const NotificationDispatchCompleteCallback& dispatch_complete_callback, |
| 224 const scoped_refptr<PlatformNotificationContext>& notification_context, | 228 const scoped_refptr<PlatformNotificationContext>& notification_context, |
| 225 const ServiceWorkerRegistration* service_worker_registration, | 229 const ServiceWorkerRegistration* service_worker_registration, |
| 226 const NotificationDatabaseData& notification_database_data) { | 230 const NotificationDatabaseData& notification_database_data) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 | 274 |
| 271 // Dispatches the notificationclose event on |service_worker|. Must be called on | 275 // Dispatches the notificationclose event on |service_worker|. Must be called on |
| 272 // the IO thread, and with the worker running. | 276 // the IO thread, and with the worker running. |
| 273 void DispatchNotificationCloseEventOnWorker( | 277 void DispatchNotificationCloseEventOnWorker( |
| 274 const scoped_refptr<ServiceWorkerVersion>& service_worker, | 278 const scoped_refptr<ServiceWorkerVersion>& service_worker, |
| 275 const NotificationDatabaseData& notification_database_data, | 279 const NotificationDatabaseData& notification_database_data, |
| 276 const ServiceWorkerVersion::StatusCallback& callback) { | 280 const ServiceWorkerVersion::StatusCallback& callback) { |
| 277 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 281 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 278 int request_id = service_worker->StartRequest( | 282 int request_id = service_worker->StartRequest( |
| 279 ServiceWorkerMetrics::EventType::NOTIFICATION_CLOSE, callback); | 283 ServiceWorkerMetrics::EventType::NOTIFICATION_CLOSE, callback); |
| 280 service_worker->DispatchSimpleEvent< | 284 |
| 281 ServiceWorkerHostMsg_NotificationCloseEventFinished>( | 285 service_worker->event_dispatcher()->DispatchNotificationCloseEvent( |
| 282 request_id, ServiceWorkerMsg_NotificationCloseEvent( | 286 notification_database_data.notification_id, |
| 283 request_id, notification_database_data.notification_id, | 287 notification_database_data.notification_data, |
| 284 notification_database_data.notification_data)); | 288 base::Bind(&ServiceWorkerVersion::OnSimpleEventFinished, service_worker, |
| 289 request_id)); | |
| 285 } | 290 } |
| 286 | 291 |
| 287 // Actually dispatches the notification close event on the service worker | 292 // Actually dispatches the notification close event on the service worker |
| 288 // registration. | 293 // registration. |
| 289 void DoDispatchNotificationCloseEvent( | 294 void DoDispatchNotificationCloseEvent( |
| 290 const std::string& notification_id, | 295 const std::string& notification_id, |
| 291 bool by_user, | 296 bool by_user, |
| 292 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | 297 const NotificationDispatchCompleteCallback& dispatch_complete_callback, |
| 293 const scoped_refptr<PlatformNotificationContext>& notification_context, | 298 const scoped_refptr<PlatformNotificationContext>& notification_context, |
| 294 const ServiceWorkerRegistration* service_worker_registration, | 299 const ServiceWorkerRegistration* service_worker_registration, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 bool by_user, | 383 bool by_user, |
| 379 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { | 384 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { |
| 380 DispatchNotificationEvent( | 385 DispatchNotificationEvent( |
| 381 browser_context, notification_id, origin, | 386 browser_context, notification_id, origin, |
| 382 base::Bind(&DoDispatchNotificationCloseEvent, notification_id, by_user, | 387 base::Bind(&DoDispatchNotificationCloseEvent, notification_id, by_user, |
| 383 dispatch_complete_callback), | 388 dispatch_complete_callback), |
| 384 dispatch_complete_callback); | 389 dispatch_complete_callback); |
| 385 } | 390 } |
| 386 | 391 |
| 387 } // namespace content | 392 } // namespace content |
| OLD | NEW |