Index: content/browser/notifications/notification_event_dispatcher_impl.cc |
diff --git a/content/browser/notifications/notification_event_dispatcher_impl.cc b/content/browser/notifications/notification_event_dispatcher_impl.cc |
index d48491ce2b8601fec05914a56db6f459fb435cf5..b905c7e7cc1b680653d42bcdbf09e21cdcceb858 100644 |
--- a/content/browser/notifications/notification_event_dispatcher_impl.cc |
+++ b/content/browser/notifications/notification_event_dispatcher_impl.cc |
@@ -10,6 +10,7 @@ |
#include "content/browser/service_worker/service_worker_context_wrapper.h" |
#include "content/browser/service_worker/service_worker_registration.h" |
#include "content/browser/service_worker/service_worker_storage.h" |
+#include "content/common/service_worker/service_worker_messages.h" |
#include "content/public/browser/browser_context.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/notification_database_data.h" |
@@ -72,6 +73,33 @@ void NotificationClickEventFinished( |
base::Bind(dispatch_complete_callback, status)); |
} |
+void OnNotificationClickEventReply( |
+ scoped_refptr<ServiceWorkerVersion> service_worker, |
nhiroki
2016/01/15 00:23:33
nit: const-ref
Marijn Kruisselbrink
2016/01/15 00:41:50
There was actually a (too) subtle reason why this
|
+ base::Callback<void(ServiceWorkerStatusCode)> callback, |
nhiroki
2016/01/15 00:23:33
ditto.
|
+ int request_id) { |
+ TRACE_EVENT1("ServiceWorker", |
+ "NotificationEventDispatcherImpl::OnNotificationClickEventReply", |
+ "Request id", request_id); |
+ service_worker->FinishRequest(request_id); |
+ callback.Run(SERVICE_WORKER_OK); |
+} |
+ |
+void DispatchNotificationClickEventOnWorker( |
+ const scoped_refptr<ServiceWorkerVersion>& service_worker, |
+ const NotificationDatabaseData& notification_database_data, |
+ int action_index, |
+ const base::Callback<void(ServiceWorkerStatusCode)>& callback) { |
+ int request_id = service_worker->StartRequest( |
+ ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback); |
+ service_worker |
+ ->DispatchEvent<ServiceWorkerHostMsg_NotificationClickEventFinished>( |
+ request_id, |
+ ServiceWorkerMsg_NotificationClickEvent( |
+ request_id, notification_database_data.notification_id, |
+ notification_database_data.notification_data, action_index), |
+ base::Bind(&OnNotificationClickEventReply, service_worker, callback)); |
+} |
+ |
// Dispatches the notificationclick on |service_worker_registration| if the |
// registration was available. Must be called on the IO thread. |
void DispatchNotificationClickEventOnRegistration( |
@@ -95,10 +123,12 @@ void DispatchNotificationClickEventOnRegistration( |
service_worker_registration); |
DCHECK(service_worker_registration->active_version()); |
- service_worker_registration->active_version() |
- ->DispatchNotificationClickEvent( |
- dispatch_event_callback, notification_database_data.notification_id, |
- notification_database_data.notification_data, action_index); |
+ service_worker_registration->active_version()->RunAfterStartWorker( |
+ dispatch_event_callback, |
+ base::Bind( |
+ &DispatchNotificationClickEventOnWorker, |
+ make_scoped_refptr(service_worker_registration->active_version()), |
+ notification_database_data, action_index, dispatch_event_callback)); |
return; |
} |