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 "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" |
| 11 #include "content/browser/service_worker/service_worker_registration.h" | 11 #include "content/browser/service_worker/service_worker_registration.h" |
| 12 #include "content/browser/service_worker/service_worker_storage.h" | 12 #include "content/browser/service_worker/service_worker_storage.h" |
| 13 #include "content/common/service_worker/service_worker_messages.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/notification_database_data.h" | |
| 17 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
| 18 #include "content/public/common/platform_notification_data.h" | 17 #include "content/public/common/platform_notification_data.h" |
| 19 | 18 |
| 20 namespace content { | 19 namespace content { |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 using NotificationClickDispatchCompleteCallback = | 22 using NotificationDispatchCompleteCallback = |
| 24 NotificationEventDispatcher::NotificationClickDispatchCompleteCallback; | 23 NotificationEventDispatcher::NotificationDispatchCompleteCallback; |
| 24 using NotificationActionCallback = | |
| 25 base::Callback<void(const ServiceWorkerRegistration*, | |
| 26 const NotificationDatabaseData&)>; | |
| 27 using CurriedNotificationActionCallback = | |
| 28 base::Callback<void(scoped_refptr<PlatformNotificationContext>, | |
| 29 const ServiceWorkerRegistration*, | |
| 30 const NotificationDatabaseData&)>; | |
| 25 | 31 |
| 26 // To be called when the notificationclick event has finished executing. Will | 32 // To be called when a notification event has finished executing. Will post a |
| 27 // post a task to call |dispatch_complete_callback| on the UI thread. | 33 // task to call |dispatch_complete_callback| on the UI thread. |
| 28 void NotificationClickEventFinished( | 34 void NotificationEventFinished( |
| 29 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback, | 35 const NotificationDispatchCompleteCallback& dispatch_complete_callback, |
| 30 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, | 36 PersistentNotificationStatus status) { |
| 31 ServiceWorkerStatusCode service_worker_status) { | |
| 32 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 37 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 33 | 38 |
| 39 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 40 base::Bind(dispatch_complete_callback, status)); | |
| 41 } | |
| 42 | |
| 43 // To be called when a notification event has finished with a | |
| 44 // ServiceWorkerStatusCode result. Will call NotificationEventFinished with a | |
| 45 // PersistentNotificationStatus derived from the service worker status. | |
| 46 void ServiceWorkerNotificationEventFinished( | |
| 47 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | |
| 48 ServiceWorkerStatusCode service_worker_status) { | |
| 34 #if defined(OS_ANDROID) | 49 #if defined(OS_ANDROID) |
| 35 // This LOG(INFO) deliberately exists to help track down the cause of | 50 // This LOG(INFO) deliberately exists to help track down the cause of |
| 36 // https://crbug.com/534537, where notifications sometimes do not react to | 51 // https://crbug.com/534537, where notifications sometimes do not react to |
| 37 // the user clicking on them. It should be removed once that's fixed. | 52 // the user clicking on them. It should be removed once that's fixed. |
| 38 LOG(INFO) << "The notificationclick event has finished: " | 53 LOG(INFO) << "The notification event has finished: " << service_worker_status; |
| 39 << service_worker_status; | |
| 40 #endif | 54 #endif |
| 41 | 55 |
| 42 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS; | 56 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS; |
| 43 switch (service_worker_status) { | 57 switch (service_worker_status) { |
| 44 case SERVICE_WORKER_OK: | 58 case SERVICE_WORKER_OK: |
| 45 // Success status was initialized above. | 59 // Success status was initialized above. |
| 46 break; | 60 break; |
| 47 case SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED: | 61 case SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED: |
| 48 status = PERSISTENT_NOTIFICATION_STATUS_EVENT_WAITUNTIL_REJECTED; | 62 status = PERSISTENT_NOTIFICATION_STATUS_EVENT_WAITUNTIL_REJECTED; |
| 49 break; | 63 break; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 62 case SERVICE_WORKER_ERROR_TIMEOUT: | 76 case SERVICE_WORKER_ERROR_TIMEOUT: |
| 63 case SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED: | 77 case SERVICE_WORKER_ERROR_SCRIPT_EVALUATE_FAILED: |
| 64 case SERVICE_WORKER_ERROR_DISK_CACHE: | 78 case SERVICE_WORKER_ERROR_DISK_CACHE: |
| 65 case SERVICE_WORKER_ERROR_REDUNDANT: | 79 case SERVICE_WORKER_ERROR_REDUNDANT: |
| 66 case SERVICE_WORKER_ERROR_DISALLOWED: | 80 case SERVICE_WORKER_ERROR_DISALLOWED: |
| 67 case SERVICE_WORKER_ERROR_DISABLED_WORKER: | 81 case SERVICE_WORKER_ERROR_DISABLED_WORKER: |
| 68 case SERVICE_WORKER_ERROR_MAX_VALUE: | 82 case SERVICE_WORKER_ERROR_MAX_VALUE: |
| 69 status = PERSISTENT_NOTIFICATION_STATUS_SERVICE_WORKER_ERROR; | 83 status = PERSISTENT_NOTIFICATION_STATUS_SERVICE_WORKER_ERROR; |
| 70 break; | 84 break; |
| 71 } | 85 } |
| 72 | 86 NotificationEventFinished(dispatch_complete_callback, status); |
| 73 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 74 base::Bind(dispatch_complete_callback, status)); | |
| 75 } | 87 } |
| 76 | 88 |
| 77 // Dispatches the notificationclick event on |service_worker|. Most be called on | 89 // Dispatches the notificationclick event on |service_worker|. Must be called on |
| 78 // the IO thread, and with the worker running. | 90 // the IO thread, and with the worker running. |
| 79 void DispatchNotificationClickEventOnWorker( | 91 void DispatchNotificationClickEventOnWorker( |
| 80 const scoped_refptr<ServiceWorkerVersion>& service_worker, | 92 const scoped_refptr<ServiceWorkerVersion>& service_worker, |
| 81 const NotificationDatabaseData& notification_database_data, | 93 const NotificationDatabaseData& notification_database_data, |
| 82 int action_index, | 94 int action_index, |
| 83 const ServiceWorkerVersion::StatusCallback& callback) { | 95 const ServiceWorkerVersion::StatusCallback& callback) { |
| 84 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 96 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 85 int request_id = service_worker->StartRequest( | 97 int request_id = service_worker->StartRequest( |
| 86 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback); | 98 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback); |
| 87 service_worker->DispatchSimpleEvent< | 99 service_worker->DispatchSimpleEvent< |
| 88 ServiceWorkerHostMsg_NotificationClickEventFinished>( | 100 ServiceWorkerHostMsg_NotificationClickEventFinished>( |
| 89 request_id, | 101 request_id, |
| 90 ServiceWorkerMsg_NotificationClickEvent( | 102 ServiceWorkerMsg_NotificationClickEvent( |
| 91 request_id, notification_database_data.notification_id, | 103 request_id, notification_database_data.notification_id, |
| 92 notification_database_data.notification_data, action_index)); | 104 notification_database_data.notification_data, action_index)); |
| 93 } | 105 } |
| 94 | 106 |
| 95 // Dispatches the notificationclick on |service_worker_registration| if the | 107 // Dispatches the notificationclose event on |service_worker|. Must be called on |
| 96 // registration was available. Must be called on the IO thread. | 108 // the IO thread, and with the worker running. |
| 97 void DispatchNotificationClickEventOnRegistration( | 109 void DispatchNotificationCloseEventOnWorker( |
| 110 const scoped_refptr<ServiceWorkerVersion>& service_worker, | |
| 98 const NotificationDatabaseData& notification_database_data, | 111 const NotificationDatabaseData& notification_database_data, |
| 99 int action_index, | 112 const ServiceWorkerVersion::StatusCallback& callback) { |
| 100 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback, | 113 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 114 int request_id = service_worker->StartRequest( | |
| 115 ServiceWorkerMetrics::EventType::NOTIFICATION_CLOSE, callback); | |
| 116 service_worker->DispatchSimpleEvent< | |
| 117 ServiceWorkerHostMsg_NotificationCloseEventFinished>( | |
| 118 request_id, ServiceWorkerMsg_NotificationCloseEvent( | |
| 119 request_id, notification_database_data.notification_id, | |
| 120 notification_database_data.notification_data)); | |
| 121 } | |
| 122 | |
| 123 // Dispatches the given notification action event on | |
| 124 // |service_worker_registration| if the registration was available. Must be | |
| 125 // called on the IO thread. | |
| 126 void DispatchNotificationEventOnRegistration( | |
| 127 const NotificationDatabaseData& notification_database_data, | |
| 128 const scoped_refptr<PlatformNotificationContext> notification_context, | |
| 129 const NotificationActionCallback& dispatch_event_action, | |
| 130 const NotificationDispatchCompleteCallback& dispatch_error_callback, | |
| 101 ServiceWorkerStatusCode service_worker_status, | 131 ServiceWorkerStatusCode service_worker_status, |
| 102 const scoped_refptr<ServiceWorkerRegistration>& | 132 const scoped_refptr<ServiceWorkerRegistration>& |
| 103 service_worker_registration) { | 133 service_worker_registration) { |
| 104 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 134 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 105 #if defined(OS_ANDROID) | 135 #if defined(OS_ANDROID) |
| 106 // This LOG(INFO) deliberately exists to help track down the cause of | 136 // This LOG(INFO) deliberately exists to help track down the cause of |
| 107 // https://crbug.com/534537, where notifications sometimes do not react to | 137 // https://crbug.com/534537, where notifications sometimes do not react to |
| 108 // the user clicking on them. It should be removed once that's fixed. | 138 // the user clicking on them. It should be removed once that's fixed. |
| 109 LOG(INFO) << "Trying to dispatch notification for SW with status: " | 139 LOG(INFO) << "Trying to dispatch notification for SW with status: " |
| 110 << service_worker_status << " action_index: " << action_index; | 140 << service_worker_status; |
| 111 #endif | 141 #endif |
| 112 if (service_worker_status == SERVICE_WORKER_OK) { | 142 if (service_worker_status == SERVICE_WORKER_OK) { |
| 113 ServiceWorkerVersion::StatusCallback dispatch_event_callback = | 143 DCHECK(service_worker_registration->active_version()); |
| 114 base::Bind(&NotificationClickEventFinished, dispatch_complete_callback, | |
| 115 service_worker_registration); | |
| 116 | 144 |
| 117 DCHECK(service_worker_registration->active_version()); | 145 dispatch_event_action.Run(service_worker_registration.get(), |
| 118 service_worker_registration->active_version()->RunAfterStartWorker( | 146 notification_database_data); |
| 119 base::Bind( | |
| 120 &DispatchNotificationClickEventOnWorker, | |
| 121 make_scoped_refptr(service_worker_registration->active_version()), | |
| 122 notification_database_data, action_index, dispatch_event_callback), | |
| 123 dispatch_event_callback); | |
| 124 return; | 147 return; |
| 125 } | 148 } |
| 126 | 149 |
| 127 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS; | 150 PersistentNotificationStatus status = PERSISTENT_NOTIFICATION_STATUS_SUCCESS; |
| 128 switch (service_worker_status) { | 151 switch (service_worker_status) { |
| 129 case SERVICE_WORKER_ERROR_NOT_FOUND: | 152 case SERVICE_WORKER_ERROR_NOT_FOUND: |
| 130 status = PERSISTENT_NOTIFICATION_STATUS_NO_SERVICE_WORKER; | 153 status = PERSISTENT_NOTIFICATION_STATUS_NO_SERVICE_WORKER; |
| 131 break; | 154 break; |
| 132 case SERVICE_WORKER_ERROR_FAILED: | 155 case SERVICE_WORKER_ERROR_FAILED: |
| 133 case SERVICE_WORKER_ERROR_ABORT: | 156 case SERVICE_WORKER_ERROR_ABORT: |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 149 case SERVICE_WORKER_ERROR_DISABLED_WORKER: | 172 case SERVICE_WORKER_ERROR_DISABLED_WORKER: |
| 150 case SERVICE_WORKER_ERROR_MAX_VALUE: | 173 case SERVICE_WORKER_ERROR_MAX_VALUE: |
| 151 status = PERSISTENT_NOTIFICATION_STATUS_SERVICE_WORKER_ERROR; | 174 status = PERSISTENT_NOTIFICATION_STATUS_SERVICE_WORKER_ERROR; |
| 152 break; | 175 break; |
| 153 case SERVICE_WORKER_OK: | 176 case SERVICE_WORKER_OK: |
| 154 NOTREACHED(); | 177 NOTREACHED(); |
| 155 break; | 178 break; |
| 156 } | 179 } |
| 157 | 180 |
| 158 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 181 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 159 base::Bind(dispatch_complete_callback, status)); | 182 base::Bind(dispatch_error_callback, status)); |
| 160 } | 183 } |
| 161 | 184 |
| 162 // Finds the ServiceWorkerRegistration associated with the |origin| and | 185 // Finds the ServiceWorkerRegistration associated with the |origin| and |
| 163 // |service_worker_registration_id|. Must be called on the IO thread. | 186 // |service_worker_registration_id|. Must be called on the IO thread. |
| 164 void FindServiceWorkerRegistration( | 187 void FindServiceWorkerRegistration( |
| 165 const GURL& origin, | 188 const GURL& origin, |
| 166 int action_index, | |
| 167 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback, | |
| 168 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, | 189 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, |
| 190 scoped_refptr<PlatformNotificationContext> notification_context, | |
| 191 const NotificationActionCallback& notification_action_callback, | |
| 192 const NotificationDispatchCompleteCallback& dispatch_error_callback, | |
| 169 bool success, | 193 bool success, |
| 170 const NotificationDatabaseData& notification_database_data) { | 194 const NotificationDatabaseData& notification_database_data) { |
| 171 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 195 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 172 | 196 |
| 173 #if defined(OS_ANDROID) | 197 #if defined(OS_ANDROID) |
| 174 // This LOG(INFO) deliberately exists to help track down the cause of | 198 // This LOG(INFO) deliberately exists to help track down the cause of |
| 175 // https://crbug.com/534537, where notifications sometimes do not react to | 199 // https://crbug.com/534537, where notifications sometimes do not react to |
| 176 // the user clicking on them. It should be removed once that's fixed. | 200 // the user clicking on them. It should be removed once that's fixed. |
| 177 LOG(INFO) << "Lookup for ServiceWoker Registration: success:" << success | 201 LOG(INFO) << "Lookup for ServiceWoker Registration"; |
| 178 << " action_index: " << action_index; | |
| 179 #endif | 202 #endif |
| 180 if (!success) { | 203 if (!success) { |
| 181 BrowserThread::PostTask( | 204 BrowserThread::PostTask( |
| 182 BrowserThread::UI, FROM_HERE, | 205 BrowserThread::UI, FROM_HERE, |
| 183 base::Bind(dispatch_complete_callback, | 206 base::Bind(dispatch_error_callback, |
| 184 PERSISTENT_NOTIFICATION_STATUS_DATABASE_ERROR)); | 207 PERSISTENT_NOTIFICATION_STATUS_DATABASE_ERROR)); |
| 185 return; | 208 return; |
| 186 } | 209 } |
| 187 | 210 |
| 188 service_worker_context->FindReadyRegistrationForId( | 211 service_worker_context->FindReadyRegistrationForId( |
| 189 notification_database_data.service_worker_registration_id, origin, | 212 notification_database_data.service_worker_registration_id, origin, |
| 190 base::Bind(&DispatchNotificationClickEventOnRegistration, | 213 base::Bind(&DispatchNotificationEventOnRegistration, |
| 191 notification_database_data, action_index, | 214 notification_database_data, notification_context, |
| 192 dispatch_complete_callback)); | 215 notification_action_callback, dispatch_error_callback)); |
| 193 } | 216 } |
| 194 | 217 |
| 195 // Reads the data associated with the |persistent_notification_id| belonging to | 218 // Reads the data associated with the |persistent_notification_id| belonging to |
| 196 // |origin| from the notification context. | 219 // |origin| from the notification context. |
| 197 void ReadNotificationDatabaseData( | 220 void ReadNotificationDatabaseData( |
| 198 int64_t persistent_notification_id, | 221 int64_t persistent_notification_id, |
| 199 const GURL& origin, | 222 const GURL& origin, |
| 200 int action_index, | |
| 201 const NotificationClickDispatchCompleteCallback& dispatch_complete_callback, | |
| 202 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, | 223 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context, |
| 203 scoped_refptr<PlatformNotificationContextImpl> notification_context) { | 224 scoped_refptr<PlatformNotificationContext> notification_context, |
| 225 const NotificationActionCallback& notification_read_callback, | |
| 226 const NotificationDispatchCompleteCallback& dispatch_error_callback) { | |
| 204 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 227 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 205 notification_context->ReadNotificationData( | 228 notification_context->ReadNotificationData( |
| 206 persistent_notification_id, origin, | 229 persistent_notification_id, origin, |
| 207 base::Bind(&FindServiceWorkerRegistration, origin, action_index, | 230 base::Bind(&FindServiceWorkerRegistration, origin, service_worker_context, |
| 208 dispatch_complete_callback, service_worker_context)); | 231 notification_context, notification_read_callback, |
| 232 dispatch_error_callback)); | |
| 233 } | |
| 234 | |
| 235 // Dispatches the notification click event on the |service_worker_registration|. | |
| 236 void DoDispatchNotificationClickEvent( | |
| 237 int action_index, | |
| 238 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | |
| 239 const scoped_refptr<PlatformNotificationContext> notification_context, | |
| 240 const ServiceWorkerRegistration* service_worker_registration, | |
| 241 const NotificationDatabaseData& notification_database_data) { | |
| 242 ServiceWorkerVersion::StatusCallback status_callback = base::Bind( | |
| 243 &ServiceWorkerNotificationEventFinished, dispatch_complete_callback); | |
| 244 service_worker_registration->active_version()->RunAfterStartWorker( | |
| 245 base::Bind( | |
| 246 &DispatchNotificationClickEventOnWorker, | |
| 247 make_scoped_refptr(service_worker_registration->active_version()), | |
| 248 notification_database_data, action_index, status_callback), | |
| 249 status_callback); | |
| 250 } | |
| 251 | |
| 252 // Called when the notification data has been deleted to finish the notification | |
| 253 // close event. | |
| 254 void OnPersistentNotificationDataDeleted( | |
| 255 ServiceWorkerStatusCode service_worker_status, | |
| 256 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | |
| 257 bool success) { | |
| 258 if (service_worker_status != SERVICE_WORKER_OK) { | |
| 259 ServiceWorkerNotificationEventFinished(dispatch_complete_callback, | |
| 260 service_worker_status); | |
| 261 return; | |
| 262 } | |
| 263 NotificationEventFinished( | |
| 264 dispatch_complete_callback, | |
| 265 success ? PERSISTENT_NOTIFICATION_STATUS_SUCCESS | |
| 266 : PERSISTENT_NOTIFICATION_STATUS_DATABASE_ERROR); | |
| 267 } | |
| 268 | |
| 269 // Called when the persistent notification close event has been handled | |
| 270 // to remove the notification from the database. | |
| 271 void OnDidDispatchNotificationCloseEvent( | |
|
Nina
2016/01/27 18:48:58
Should we rename this to OnMaybeDidDispatchNotific
| |
| 272 const int64_t notification_id, | |
| 273 const GURL& origin, | |
| 274 scoped_refptr<PlatformNotificationContext> notification_context, | |
| 275 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | |
| 276 ServiceWorkerStatusCode status_code) { | |
| 277 notification_context->DeleteNotificationData( | |
| 278 notification_id, origin, | |
| 279 base::Bind(&OnPersistentNotificationDataDeleted, status_code, | |
| 280 dispatch_complete_callback)); | |
| 281 } | |
| 282 | |
| 283 // Actually dispatches the notification close event on the service worker | |
| 284 // registration. | |
| 285 void DoDispatchNotificationCloseEvent( | |
| 286 bool by_user, | |
| 287 const NotificationDispatchCompleteCallback& dispatch_complete_callback, | |
| 288 scoped_refptr<PlatformNotificationContext> notification_context, | |
| 289 const ServiceWorkerRegistration* service_worker_registration, | |
| 290 const NotificationDatabaseData& notification_database_data) { | |
| 291 const ServiceWorkerVersion::StatusCallback dispatch_event_callback = | |
| 292 base::Bind(&OnDidDispatchNotificationCloseEvent, | |
| 293 notification_database_data.notification_id, | |
| 294 notification_database_data.origin, notification_context, | |
| 295 dispatch_complete_callback); | |
| 296 if (by_user) { | |
| 297 service_worker_registration->active_version()->RunAfterStartWorker( | |
| 298 base::Bind( | |
| 299 &DispatchNotificationCloseEventOnWorker, | |
| 300 make_scoped_refptr(service_worker_registration->active_version()), | |
| 301 notification_database_data, dispatch_event_callback), | |
| 302 dispatch_event_callback); | |
| 303 } else { | |
| 304 dispatch_event_callback.Run(ServiceWorkerStatusCode::SERVICE_WORKER_OK); | |
| 305 } | |
| 209 } | 306 } |
| 210 | 307 |
| 211 } // namespace | 308 } // namespace |
| 212 | 309 |
| 213 // static | 310 // static |
| 214 NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() { | 311 NotificationEventDispatcher* NotificationEventDispatcher::GetInstance() { |
| 215 return NotificationEventDispatcherImpl::GetInstance(); | 312 return NotificationEventDispatcherImpl::GetInstance(); |
| 216 } | 313 } |
| 217 | 314 |
| 218 NotificationEventDispatcherImpl* | 315 NotificationEventDispatcherImpl* |
| 219 NotificationEventDispatcherImpl::GetInstance() { | 316 NotificationEventDispatcherImpl::GetInstance() { |
| 220 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 317 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 221 return base::Singleton<NotificationEventDispatcherImpl>::get(); | 318 return base::Singleton<NotificationEventDispatcherImpl>::get(); |
| 222 } | 319 } |
| 223 | 320 |
| 224 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {} | 321 // Dispatches any notification event. The actual, specific event dispatch should |
| 225 | 322 // be done by the |notification_action_callback|. |
| 226 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {} | 323 void DispatchNotificationEvent( |
| 227 | |
| 228 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( | |
| 229 BrowserContext* browser_context, | 324 BrowserContext* browser_context, |
| 230 int64_t persistent_notification_id, | 325 int64_t persistent_notification_id, |
| 231 const GURL& origin, | 326 const GURL& origin, |
| 232 int action_index, | 327 const CurriedNotificationActionCallback& notification_action_callback, |
| 233 const NotificationClickDispatchCompleteCallback& | 328 const NotificationDispatchCompleteCallback& notification_error_callback) { |
| 234 dispatch_complete_callback) { | |
| 235 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 329 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 236 DCHECK_GT(persistent_notification_id, 0); | 330 DCHECK_GT(persistent_notification_id, 0); |
| 237 DCHECK(origin.is_valid()); | 331 DCHECK(origin.is_valid()); |
| 238 | 332 |
| 239 StoragePartition* partition = | 333 StoragePartition* partition = |
| 240 BrowserContext::GetStoragePartitionForSite(browser_context, origin); | 334 BrowserContext::GetStoragePartitionForSite(browser_context, origin); |
| 241 | 335 |
| 242 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = | 336 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = |
| 243 static_cast<ServiceWorkerContextWrapper*>( | 337 static_cast<ServiceWorkerContextWrapper*>( |
| 244 partition->GetServiceWorkerContext()); | 338 partition->GetServiceWorkerContext()); |
| 245 scoped_refptr<PlatformNotificationContextImpl> notification_context = | 339 scoped_refptr<PlatformNotificationContext> notification_context = |
| 246 static_cast<PlatformNotificationContextImpl*>( | 340 partition->GetPlatformNotificationContext(); |
| 247 partition->GetPlatformNotificationContext()); | |
| 248 | 341 |
| 249 BrowserThread::PostTask( | 342 BrowserThread::PostTask( |
| 250 BrowserThread::IO, FROM_HERE, | 343 BrowserThread::IO, FROM_HERE, |
| 251 base::Bind(&ReadNotificationDatabaseData, persistent_notification_id, | 344 base::Bind(&ReadNotificationDatabaseData, persistent_notification_id, |
| 252 origin, action_index, dispatch_complete_callback, | 345 origin, service_worker_context, notification_context, |
| 253 service_worker_context, notification_context)); | 346 base::Bind(notification_action_callback, notification_context), |
| 347 notification_error_callback)); | |
| 348 } | |
| 349 | |
| 350 NotificationEventDispatcherImpl::NotificationEventDispatcherImpl() {} | |
| 351 | |
| 352 NotificationEventDispatcherImpl::~NotificationEventDispatcherImpl() {} | |
| 353 | |
| 354 void NotificationEventDispatcherImpl::DispatchNotificationClickEvent( | |
| 355 BrowserContext* browser_context, | |
| 356 int64_t persistent_notification_id, | |
| 357 const GURL& origin, | |
| 358 int action_index, | |
| 359 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { | |
| 360 DispatchNotificationEvent( | |
| 361 browser_context, persistent_notification_id, origin, | |
| 362 base::Bind(&DoDispatchNotificationClickEvent, action_index, | |
| 363 dispatch_complete_callback), | |
| 364 dispatch_complete_callback); | |
| 365 } | |
| 366 | |
| 367 void NotificationEventDispatcherImpl::DispatchNotificationCloseEvent( | |
| 368 BrowserContext* browser_context, | |
| 369 int64_t persistent_notification_id, | |
| 370 const GURL& origin, | |
| 371 bool by_user, | |
| 372 const NotificationDispatchCompleteCallback& dispatch_complete_callback) { | |
| 373 DispatchNotificationEvent(browser_context, persistent_notification_id, origin, | |
| 374 base::Bind(&DoDispatchNotificationCloseEvent, | |
| 375 by_user, dispatch_complete_callback), | |
| 376 dispatch_complete_callback); | |
| 254 } | 377 } |
| 255 | 378 |
| 256 } // namespace content | 379 } // namespace content |
| OLD | NEW |