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

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

Issue 2569993002: [ServiceWorker] Mojofy PushEvent of Service Worker. (Closed)
Patch Set: Address comments from Peter and shimazu 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
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..039adf95487e0ca6c995f530bc27fa91716384bb 100644
--- a/content/renderer/service_worker/service_worker_context_client.cc
+++ b/content/renderer/service_worker/service_worker_context_client.cc
@@ -179,6 +179,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 +213,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 +411,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 +572,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 +752,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);
Peter Beverloo 2016/12/15 17:35:39 nit: yay, thanks! :) This has one downside - DCHE
Marijn Kruisselbrink 2016/12/15 17:42:36 Handling a DCHECK failure (or your NOTREACHED case
xiaofengzhang 2016/12/16 02:15:49 Acknowledged.
+ 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 +1052,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)

Powered by Google App Engine
This is Rietveld 408576698