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

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

Issue 1904163002: Move Web Notifications to use Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@skbitmap-blink
Patch Set: it works \o/ Created 4 years, 8 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 032d50362f57014fb42049d7baf0f094b9e8b7d0..dfb90365e7520f68ce7a56d8c6e1ca68aea88192 100644
--- a/content/browser/notifications/notification_event_dispatcher_impl.cc
+++ b/content/browser/notifications/notification_event_dispatcher_impl.cc
@@ -5,16 +5,20 @@
#include "content/browser/notifications/notification_event_dispatcher_impl.h"
#include "base/callback.h"
+#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "content/browser/notifications/platform_notification_context_impl.h"
+#include "content/browser/notifications/type_converters.h"
#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/common/notification_service_worker_client.mojom.h"
+#include "content/common/service_worker/service_worker_type_converters.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/platform_notification_data.h"
+#include "third_party/WebKit/public/platform/modules/notifications/notification.mojom.h"
namespace content {
namespace {
@@ -198,6 +202,21 @@ void ReadNotificationDatabaseData(
// -----------------------------------------------------------------------------
+// Called when a notification event has finished. Marks the request as finished
+// and will finalize the |callback| with the |status| code.
+void DidDispatchNotificationEvent(
+ const scoped_refptr<ServiceWorkerVersion>& service_worker,
+ int request_id,
+ const ServiceWorkerVersion::StatusCallback& callback,
+ mojom::ServiceWorkerEventStatus status) {
+ if (!service_worker->FinishRequest(
+ request_id, status == mojom::ServiceWorkerEventStatus::COMPLETED)) {
+ return;
+ }
+
+ callback.Run(mojo::ConvertTo<ServiceWorkerStatusCode>(status));
+}
+
// Dispatches the notificationclick event on |service_worker|. Must be called on
// the IO thread, and with the worker running.
void DispatchNotificationClickEventOnWorker(
@@ -208,12 +227,23 @@ void DispatchNotificationClickEventOnWorker(
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));
+
+ blink::mojom::NotificationPtr notification =
+ blink::mojom::Notification::From(
+ notification_database_data.notification_data);
+
+ // TODO(peter): Use the NotificationIdGenerator for creating the id.
+ notification->id =
+ base::Int64ToString(notification_database_data.notification_id);
+
+ base::WeakPtr<mojom::NotificationServiceWorkerClient> client =
+ service_worker
+ ->GetMojoServiceForRequest<mojom::NotificationServiceWorkerClient>(
+ request_id);
+
+ client->Click(std::move(notification), action_index,
+ base::Bind(&DidDispatchNotificationEvent, service_worker,
+ request_id, callback));
}
// Dispatches the notification click event on the |service_worker_registration|.
@@ -276,11 +306,23 @@ void DispatchNotificationCloseEventOnWorker(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
int request_id = service_worker->StartRequest(
ServiceWorkerMetrics::EventType::NOTIFICATION_CLOSE, callback);
- service_worker->DispatchSimpleEvent<
- ServiceWorkerHostMsg_NotificationCloseEventFinished>(
- request_id, ServiceWorkerMsg_NotificationCloseEvent(
- request_id, notification_database_data.notification_id,
- notification_database_data.notification_data));
+
+ blink::mojom::NotificationPtr notification =
+ blink::mojom::Notification::From(
+ notification_database_data.notification_data);
+
+ // TODO(peter): Use the NotificationIdGenerator in this case too.
+ notification->id =
+ base::Int64ToString(notification_database_data.notification_id);
+
+ base::WeakPtr<mojom::NotificationServiceWorkerClient> client =
+ service_worker
+ ->GetMojoServiceForRequest<mojom::NotificationServiceWorkerClient>(
+ request_id);
+
+ client->Close(std::move(notification),
+ base::Bind(&DidDispatchNotificationEvent, service_worker,
+ request_id, callback));
}
// Actually dispatches the notification close event on the service worker

Powered by Google App Engine
This is Rietveld 408576698