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

Unified Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2569993002: [ServiceWorker] Mojofy PushEvent of Service Worker. (Closed)
Patch Set: Rebase and address comments from Peter and Marijn Created 4 years 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 | « content/renderer/service_worker/service_worker_context_client.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c4b51fb99a0920dfd06c7cd1fb8d61bc40513075..4e54c503a0a56a51ca7307f1756744371145e6c7 100644
--- a/content/renderer/service_worker/service_worker_context_client.cc
+++ b/content/renderer/service_worker/service_worker_context_client.cc
@@ -165,6 +165,15 @@ ToWebServiceWorkerClientInfo(const ServiceWorkerClientInfo& client_info) {
return web_client_info;
}
+// Use this template in willDestroyWorkerContext to abort all the pending
+// events callbacks.
+template <typename T>
+void AbortPendingEventCallbacks(T& callbacks) {
+ for (typename T::iterator it(&callbacks); !it.IsAtEnd(); it.Advance()) {
+ it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
+ }
+}
+
} // namespace
// Holding data that needs to be bound to the worker context on the
@@ -179,6 +188,8 @@ struct ServiceWorkerContextClient::WorkerContextData {
using SkipWaitingCallbacksMap =
IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>;
using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>;
+ using PushEventCallbacksMap =
+ IDMap<std::unique_ptr<const DispatchPushEventCallback>>;
using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>;
using ExtendableMessageEventCallbacksMap =
IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>;
@@ -211,6 +222,9 @@ struct ServiceWorkerContextClient::WorkerContextData {
// Pending callbacks for Background Sync Events.
SyncEventCallbacksMap sync_event_callbacks;
+ // Pending callbacks for Push Events.
+ PushEventCallbacksMap push_event_callbacks;
+
// Pending callbacks for Fetch Events.
FetchEventCallbacksMap fetch_event_callbacks;
@@ -406,7 +420,6 @@ void ServiceWorkerContextClient::OnMessageReceived(
OnNotificationClickEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationCloseEvent,
OnNotificationCloseEvent)
- IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients)
IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
@@ -568,24 +581,11 @@ void ServiceWorkerContextClient::willDestroyWorkerContext(
// (while we're still on the worker thread).
proxy_ = NULL;
- // Aborts the all pending sync event callbacks.
- for (WorkerContextData::SyncEventCallbacksMap::iterator it(
- &context_->sync_event_callbacks);
- !it.IsAtEnd(); it.Advance()) {
- it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
- }
- // Aborts the all pending fetch event callbacks.
- for (WorkerContextData::FetchEventCallbacksMap::iterator it(
- &context_->fetch_event_callbacks);
- !it.IsAtEnd(); it.Advance()) {
- it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
- }
- // Aborts the all pending extendable message event callbacks.
- for (WorkerContextData::ExtendableMessageEventCallbacksMap::iterator it(
- &context_->message_event_callbacks);
- !it.IsAtEnd(); it.Advance()) {
- it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
- }
+ // Aborts all the pending events callbacks.
+ AbortPendingEventCallbacks(context_->sync_event_callbacks);
+ AbortPendingEventCallbacks(context_->push_event_callbacks);
+ AbortPendingEventCallbacks(context_->fetch_event_callbacks);
+ AbortPendingEventCallbacks(context_->message_event_callbacks);
// We have to clear callbacks now, as they need to be freed on the
// same thread.
@@ -761,9 +761,14 @@ void ServiceWorkerContextClient::didHandlePushEvent(
int request_id,
blink::WebServiceWorkerEventResult result,
double event_dispatch_time) {
- Send(new ServiceWorkerHostMsg_PushEventFinished(
- GetRoutingID(), request_id, result,
- base::Time::FromDoubleT(event_dispatch_time)));
+ const DispatchPushEventCallback* callback =
+ context_->push_event_callbacks.Lookup(request_id);
+ DCHECK(callback);
+ callback->Run(result == blink::WebServiceWorkerEventResultCompleted
+ ? SERVICE_WORKER_OK
+ : SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
+ base::Time::FromDoubleT(event_dispatch_time));
+ context_->push_event_callbacks.Remove(request_id);
}
void ServiceWorkerContextClient::didHandleSyncEvent(
@@ -1056,10 +1061,14 @@ void ServiceWorkerContextClient::OnNotificationCloseEvent(
ToWebNotificationData(notification_data));
}
-void ServiceWorkerContextClient::OnPushEvent(int request_id,
- const PushEventPayload& payload) {
+void ServiceWorkerContextClient::DispatchPushEvent(
+ const PushEventPayload& payload,
+ const DispatchPushEventCallback& callback) {
TRACE_EVENT0("ServiceWorker",
- "ServiceWorkerContextClient::OnPushEvent");
+ "ServiceWorkerContextClient::DispatchPushEvent");
+ int request_id = context_->push_event_callbacks.Add(
+ base::MakeUnique<DispatchPushEventCallback>(callback));
+
// Only set data to be a valid string if the payload had decrypted data.
blink::WebString data;
if (!payload.is_null)
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698