Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: content/browser/notifications/notification_event_dispatcher_impl.cc

Issue 1575283003: Move notification click event dispatching out of ServiceWorkerVersion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@swversion-ipc-refactor
Patch Set: rebase and use DispatchSimpleEvent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 06e2cc030ec2e6b204f2aa1be758a86298a5276e..06b822243795bf553b45c8367782d95a309661d9 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"
@@ -73,6 +74,24 @@ void NotificationClickEventFinished(
base::Bind(dispatch_complete_callback, status));
}
+// Dispatches the notificationclick event on |service_worker|. Most be called on
+// the IO thread, and with the worker running.
+void DispatchNotificationClickEventOnWorker(
+ const scoped_refptr<ServiceWorkerVersion>& service_worker,
+ const NotificationDatabaseData& notification_database_data,
+ int action_index,
+ const ServiceWorkerVersion::StatusCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ int request_id = service_worker->StartRequest(
+ ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK, callback);
+ service_worker->DispatchSimpleEvent<
+ ServiceWorkerHostMsg_NotificationClickEventFinished>(
+ request_id,
+ ServiceWorkerMsg_NotificationClickEvent(
+ request_id, notification_database_data.notification_id,
+ notification_database_data.notification_data, action_index));
+}
+
// Dispatches the notificationclick on |service_worker_registration| if the
// registration was available. Must be called on the IO thread.
void DispatchNotificationClickEventOnRegistration(
@@ -91,15 +110,17 @@ void DispatchNotificationClickEventOnRegistration(
<< service_worker_status << " action_index: " << action_index;
#endif
if (service_worker_status == SERVICE_WORKER_OK) {
- base::Callback<void(ServiceWorkerStatusCode)> dispatch_event_callback =
+ ServiceWorkerVersion::StatusCallback dispatch_event_callback =
base::Bind(&NotificationClickEventFinished, dispatch_complete_callback,
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(
+ base::Bind(
+ &DispatchNotificationClickEventOnWorker,
+ make_scoped_refptr(service_worker_registration->active_version()),
+ notification_database_data, action_index, dispatch_event_callback),
+ dispatch_event_callback);
return;
}
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698