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

Unified Diff: content/renderer/service_worker/service_worker_context_client.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/renderer/service_worker/service_worker_context_client.cc
diff --git a/content/renderer/service_worker/service_worker_context_client.cc b/content/renderer/service_worker/service_worker_context_client.cc
index 52a97a47b250cc946729073c88e9389b3f19f558..07899bea42ce8b8863abb6215eaf564df15ba8bd 100644
--- a/content/renderer/service_worker/service_worker_context_client.cc
+++ b/content/renderer/service_worker/service_worker_context_client.cc
@@ -15,7 +15,6 @@
#include "base/threading/thread_checker.h"
#include "base/threading/thread_local.h"
#include "base/trace_event/trace_event.h"
-#include "content/child/notifications/notification_data_conversions.h"
#include "content/child/request_extra_data.h"
#include "content/child/service_worker/service_worker_dispatcher.h"
#include "content/child/service_worker/service_worker_handle_reference.h"
@@ -39,6 +38,7 @@
#include "content/public/renderer/document_state.h"
#include "content/renderer/background_sync/background_sync_client_impl.h"
#include "content/renderer/devtools/devtools_agent.h"
+#include "content/renderer/notifications/notification_service_worker_client_impl.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/service_worker/embedded_worker_dispatcher.h"
#include "content/renderer/service_worker/service_worker_type_util.h"
@@ -50,7 +50,7 @@
#include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegistration.h"
-#include "third_party/WebKit/public/platform/modules/notifications/WebNotificationData.h"
+#include "third_party/WebKit/public/platform/modules/notifications/notification.mojom-blink.h"
#include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerClientQueryOptions.h"
#include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
#include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerResponse.h"
@@ -171,7 +171,7 @@ struct ServiceWorkerContextClient::WorkerContextData {
IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer>;
using SkipWaitingCallbacksMap =
IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>;
- using SyncEventCallbacksMap =
+ using MojoStatusCallbacksMap =
IDMap<const mojo::Callback<void(mojom::ServiceWorkerEventStatus)>,
IDMapOwnPointer>;
@@ -180,6 +180,20 @@ struct ServiceWorkerContextClient::WorkerContextData {
~WorkerContextData() {
DCHECK(thread_checker.CalledOnValidThread());
+
+ // Mojo callbacks have the contract that they must be called prior to being
+ // destructed. Abort any left-over callbacks stored in this context.
+ AbortPendingMojoCallbacks(&sync_event_callbacks);
+ AbortPendingMojoCallbacks(&notification_click_callbacks);
+ AbortPendingMojoCallbacks(&notification_close_callbacks);
+ }
+
+ void AbortPendingMojoCallbacks(MojoStatusCallbacksMap* map) {
+ for (MojoStatusCallbacksMap::iterator iter(map); !iter.IsAtEnd();
+ iter.Advance()) {
+ const auto* callback = iter.GetCurrentValue();
+ callback->Run(mojom::ServiceWorkerEventStatus::ABORTED);
+ }
}
// Pending callbacks for GetClientDocuments().
@@ -195,7 +209,11 @@ struct ServiceWorkerContextClient::WorkerContextData {
ClaimClientsCallbacksMap claim_clients_callbacks;
// Pending callbacks for Background Sync Events
- SyncEventCallbacksMap sync_event_callbacks;
+ MojoStatusCallbacksMap sync_event_callbacks;
+
+ // Pending callbacks for notification events.
+ MojoStatusCallbacksMap notification_click_callbacks;
+ MojoStatusCallbacksMap notification_close_callbacks;
ServiceRegistryImpl service_registry;
@@ -247,10 +265,6 @@ void ServiceWorkerContextClient::OnMessageReceived(
OnExtendableMessageEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
- IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent,
- OnNotificationClickEvent)
- IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationCloseEvent,
- OnNotificationCloseEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient)
@@ -376,6 +390,8 @@ void ServiceWorkerContextClient::workerContextStarted(
// Register Mojo services.
context_->service_registry.ServiceRegistry::AddService(
base::Bind(&BackgroundSyncClientImpl::Create));
+ context_->service_registry.ServiceRegistry::AddService(
+ base::Bind(&NotificationServiceWorkerClientImpl::Create));
SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs);
@@ -526,15 +542,37 @@ void ServiceWorkerContextClient::didHandleFetchEvent(
void ServiceWorkerContextClient::didHandleNotificationClickEvent(
int request_id,
blink::WebServiceWorkerEventResult result) {
- Send(new ServiceWorkerHostMsg_NotificationClickEventFinished(
- GetRoutingID(), request_id, result));
+ const MojoStatusCallback* callback =
+ context_->notification_click_callbacks.Lookup(request_id);
+ if (!callback)
+ return;
+
+ // TODO(peter): Clean-up and unify w/ close and sync events
+ if (result == blink::WebServiceWorkerEventResultCompleted) {
+ callback->Run(mojom::ServiceWorkerEventStatus::COMPLETED);
+ } else {
+ callback->Run(mojom::ServiceWorkerEventStatus::REJECTED);
+ }
+
+ context_->notification_click_callbacks.Remove(request_id);
}
void ServiceWorkerContextClient::didHandleNotificationCloseEvent(
int request_id,
blink::WebServiceWorkerEventResult result) {
- Send(new ServiceWorkerHostMsg_NotificationCloseEventFinished(
- GetRoutingID(), request_id, result));
+ const MojoStatusCallback* callback =
+ context_->notification_close_callbacks.Lookup(request_id);
+ if (!callback)
+ return;
+
+ // TODO(peter): Clean-up and unify w/ close and sync events
+ if (result == blink::WebServiceWorkerEventResultCompleted) {
+ callback->Run(mojom::ServiceWorkerEventStatus::COMPLETED);
+ } else {
+ callback->Run(mojom::ServiceWorkerEventStatus::REJECTED);
+ }
+
+ context_->notification_close_callbacks.Remove(request_id);
}
void ServiceWorkerContextClient::didHandlePushEvent(
@@ -547,7 +585,7 @@ void ServiceWorkerContextClient::didHandlePushEvent(
void ServiceWorkerContextClient::didHandleSyncEvent(
int request_id,
blink::WebServiceWorkerEventResult result) {
- const SyncCallback* callback =
+ const MojoStatusCallback* callback =
context_->sync_event_callbacks.Lookup(request_id);
if (!callback)
return;
@@ -665,11 +703,11 @@ void ServiceWorkerContextClient::registerForeignFetchScopes(
void ServiceWorkerContextClient::DispatchSyncEvent(
const std::string& tag,
blink::WebServiceWorkerContextProxy::LastChanceOption last_chance,
- const SyncCallback& callback) {
+ const MojoStatusCallback& callback) {
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerContextClient::DispatchSyncEvent");
int request_id =
- context_->sync_event_callbacks.Add(new SyncCallback(callback));
+ context_->sync_event_callbacks.Add(new MojoStatusCallback(callback));
// TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once
// https://crrev.com/1768063002/ lands.
@@ -677,6 +715,32 @@ void ServiceWorkerContextClient::DispatchSyncEvent(
last_chance);
}
+void ServiceWorkerContextClient::DispatchNotificationClickEvent(
+ blink::mojom::blink::NotificationPtr notification,
+ int32_t action_index,
+ const MojoStatusCallback& callback) {
+ TRACE_EVENT0("ServiceWorker",
+ "ServiceWorkerContextClient::DispatchNotificationClickEvent");
+ int request_id =
+ context_->notification_click_callbacks.Add(
+ new MojoStatusCallback(callback));
+
+ proxy_->dispatchNotificationClickEvent(
+ request_id, std::move(notification), action_index);
+}
+
+void ServiceWorkerContextClient::DispatchNotificationCloseEvent(
+ blink::mojom::blink::NotificationPtr notification,
+ const MojoStatusCallback& callback) {
+ TRACE_EVENT0("ServiceWorker",
+ "ServiceWorkerContextClient::DispatchNotificationCloseEvent");
+ int request_id =
+ context_->notification_close_callbacks.Add(
+ new MojoStatusCallback(callback));
+
+ proxy_->dispatchNotificationCloseEvent(request_id, std::move(notification));
+}
+
void ServiceWorkerContextClient::Send(IPC::Message* message) {
sender_->Send(message);
}
@@ -787,31 +851,6 @@ void ServiceWorkerContextClient::OnFetchEvent(
}
}
-void ServiceWorkerContextClient::OnNotificationClickEvent(
- int request_id,
- int64_t persistent_notification_id,
- const PlatformNotificationData& notification_data,
- int action_index) {
- TRACE_EVENT0("ServiceWorker",
- "ServiceWorkerContextClient::OnNotificationClickEvent");
- proxy_->dispatchNotificationClickEvent(
- request_id,
- persistent_notification_id,
- ToWebNotificationData(notification_data),
- action_index);
-}
-
-void ServiceWorkerContextClient::OnNotificationCloseEvent(
- int request_id,
- int64_t persistent_notification_id,
- const PlatformNotificationData& notification_data) {
- TRACE_EVENT0("ServiceWorker",
- "ServiceWorkerContextClient::OnNotificationCloseEvent");
- proxy_->dispatchNotificationCloseEvent(
- request_id, persistent_notification_id,
- ToWebNotificationData(notification_data));
-}
-
void ServiceWorkerContextClient::OnPushEvent(int request_id,
const PushEventPayload& payload) {
TRACE_EVENT0("ServiceWorker",
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.h ('k') | third_party/WebKit/Source/modules/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698