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

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

Issue 2620333003: Reland of [ServiceWorker] Mojofy PushEvent of Service Worker. (Closed)
Patch Set: Rebase Created 3 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 | « 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 3edb052b64e4b74f2dc8e489150862772d549c29..352b1eb2d18548de6a9647e4a429a75a2fc4d3f5 100644
--- a/content/renderer/service_worker/service_worker_context_client.cc
+++ b/content/renderer/service_worker/service_worker_context_client.cc
@@ -180,6 +180,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
@@ -194,6 +203,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>>;
@@ -226,6 +237,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;
@@ -414,7 +428,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,
@@ -576,24 +589,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.
@@ -760,9 +760,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(
@@ -1053,10 +1058,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