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

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: Make callback paramters const-ref 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
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..54a5906f30d45a1722757e318e94aba0d4df2478 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(
Michael van Ouwerkerk 2016/01/15 16:44:03 nit: add some documentation like the other functio
Marijn Kruisselbrink 2016/01/15 23:48:49 Done
+ const scoped_refptr<ServiceWorkerVersion>& service_worker,
+ const base::Callback<void(ServiceWorkerStatusCode)>& callback,
johnme 2016/01/15 16:52:58 Nit: may as well use `const ServiceWorkerVersion::
Marijn Kruisselbrink 2016/01/15 23:48:49 Agreed; not sure why the code in DispatchNotificat
+ int request_id) {
Michael van Ouwerkerk 2016/01/15 16:44:03 nit: DCHECK_CURRENTLY_ON like all other functions
Marijn Kruisselbrink 2016/01/15 23:48:49 Done
+ TRACE_EVENT1("ServiceWorker",
+ "NotificationEventDispatcherImpl::OnNotificationClickEventReply",
+ "Request id", request_id);
+ service_worker->FinishRequest(request_id);
johnme 2016/01/15 16:52:58 Please NOTREACHED() if this returns false.
Marijn Kruisselbrink 2016/01/15 23:48:49 Done
+ callback.Run(SERVICE_WORKER_OK);
johnme 2016/01/15 16:52:58 The previous code did the following: scoped_refpt
Marijn Kruisselbrink 2016/01/15 23:48:49 If I understand it correctly, the old code made su
johnme 2016/01/18 16:31:05 You're right - the (somewhat awkward) pattern is f
+}
+
+void DispatchNotificationClickEventOnWorker(
Michael van Ouwerkerk 2016/01/15 16:44:03 nit: add some documentation like the other functio
Marijn Kruisselbrink 2016/01/15 23:48:49 Done
+ const scoped_refptr<ServiceWorkerVersion>& service_worker,
+ const NotificationDatabaseData& notification_database_data,
+ int action_index,
+ const base::Callback<void(ServiceWorkerStatusCode)>& callback) {
Michael van Ouwerkerk 2016/01/15 16:44:03 nit: DCHECK_CURRENTLY_ON like all other functions
johnme 2016/01/15 16:52:58 Ditto `const ServiceWorkerVersion::StatusCallback&
Marijn Kruisselbrink 2016/01/15 23:48:49 Done
+ 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(
johnme 2016/01/15 16:52:58 Is it ok to call RunAfterStartWorker (and hence St
Marijn Kruisselbrink 2016/01/15 23:48:49 Good question; I don't think the side effects will
+ dispatch_event_callback,
Michael van Ouwerkerk 2016/01/15 16:44:03 nit: I would expect the error callback argument to
Marijn Kruisselbrink 2016/01/15 23:48:49 Changed this order in https://codereview.chromium.
+ base::Bind(
+ &DispatchNotificationClickEventOnWorker,
+ make_scoped_refptr(service_worker_registration->active_version()),
+ notification_database_data, action_index, dispatch_event_callback));
return;
}

Powered by Google App Engine
This is Rietveld 408576698