OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/service_worker/service_worker_context_client.h" | 5 #include "content/renderer/service_worker/service_worker_context_client.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // worker thread. | 196 // worker thread. |
197 struct ServiceWorkerContextClient::WorkerContextData { | 197 struct ServiceWorkerContextClient::WorkerContextData { |
198 using ClientsCallbacksMap = | 198 using ClientsCallbacksMap = |
199 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; | 199 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; |
200 using ClaimClientsCallbacksMap = | 200 using ClaimClientsCallbacksMap = |
201 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; | 201 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; |
202 using ClientCallbacksMap = | 202 using ClientCallbacksMap = |
203 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; | 203 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; |
204 using SkipWaitingCallbacksMap = | 204 using SkipWaitingCallbacksMap = |
205 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; | 205 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; |
| 206 using ActivateEventCallbacksMap = |
| 207 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; |
206 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; | 208 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; |
207 using PushEventCallbacksMap = | 209 using PushEventCallbacksMap = |
208 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; | 210 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; |
209 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; | 211 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; |
210 using ExtendableMessageEventCallbacksMap = | 212 using ExtendableMessageEventCallbacksMap = |
211 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; | 213 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; |
212 using NavigationPreloadRequestsMap = IDMap< | 214 using NavigationPreloadRequestsMap = IDMap< |
213 std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>; | 215 std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>; |
214 | 216 |
215 explicit WorkerContextData(ServiceWorkerContextClient* owner) | 217 explicit WorkerContextData(ServiceWorkerContextClient* owner) |
(...skipping 12 matching lines...) Expand all Loading... |
228 | 230 |
229 // Pending callbacks for OpenWindow() and FocusClient(). | 231 // Pending callbacks for OpenWindow() and FocusClient(). |
230 ClientCallbacksMap client_callbacks; | 232 ClientCallbacksMap client_callbacks; |
231 | 233 |
232 // Pending callbacks for SkipWaiting(). | 234 // Pending callbacks for SkipWaiting(). |
233 SkipWaitingCallbacksMap skip_waiting_callbacks; | 235 SkipWaitingCallbacksMap skip_waiting_callbacks; |
234 | 236 |
235 // Pending callbacks for ClaimClients(). | 237 // Pending callbacks for ClaimClients(). |
236 ClaimClientsCallbacksMap claim_clients_callbacks; | 238 ClaimClientsCallbacksMap claim_clients_callbacks; |
237 | 239 |
| 240 // Pending callbacks for Activate Events. |
| 241 ActivateEventCallbacksMap activate_event_callbacks; |
| 242 |
238 // Pending callbacks for Background Sync Events. | 243 // Pending callbacks for Background Sync Events. |
239 SyncEventCallbacksMap sync_event_callbacks; | 244 SyncEventCallbacksMap sync_event_callbacks; |
240 | 245 |
241 // Pending callbacks for Push Events. | 246 // Pending callbacks for Push Events. |
242 PushEventCallbacksMap push_event_callbacks; | 247 PushEventCallbacksMap push_event_callbacks; |
243 | 248 |
244 // Pending callbacks for Fetch Events. | 249 // Pending callbacks for Fetch Events. |
245 FetchEventCallbacksMap fetch_event_callbacks; | 250 FetchEventCallbacksMap fetch_event_callbacks; |
246 | 251 |
247 // Pending callbacks for Extendable Message Events. | 252 // Pending callbacks for Extendable Message Events. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 | 400 |
396 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} | 401 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} |
397 | 402 |
398 void ServiceWorkerContextClient::OnMessageReceived( | 403 void ServiceWorkerContextClient::OnMessageReceived( |
399 int thread_id, | 404 int thread_id, |
400 int embedded_worker_id, | 405 int embedded_worker_id, |
401 const IPC::Message& message) { | 406 const IPC::Message& message) { |
402 CHECK_EQ(embedded_worker_id_, embedded_worker_id); | 407 CHECK_EQ(embedded_worker_id_, embedded_worker_id); |
403 bool handled = true; | 408 bool handled = true; |
404 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) | 409 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) |
405 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) | |
406 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) | 410 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) |
407 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent, | 411 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent, |
408 OnNotificationClickEvent) | 412 OnNotificationClickEvent) |
409 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationCloseEvent, | 413 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationCloseEvent, |
410 OnNotificationCloseEvent) | 414 OnNotificationCloseEvent) |
411 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) | 415 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) |
412 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) | 416 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) |
413 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, | 417 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, |
414 OnOpenWindowResponse) | 418 OnOpenWindowResponse) |
415 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, | 419 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 } | 567 } |
564 | 568 |
565 void ServiceWorkerContextClient::willDestroyWorkerContext( | 569 void ServiceWorkerContextClient::willDestroyWorkerContext( |
566 v8::Local<v8::Context> context) { | 570 v8::Local<v8::Context> context) { |
567 // At this point WillStopCurrentWorkerThread is already called, so | 571 // At this point WillStopCurrentWorkerThread is already called, so |
568 // worker_task_runner_->RunsTasksOnCurrentThread() returns false | 572 // worker_task_runner_->RunsTasksOnCurrentThread() returns false |
569 // (while we're still on the worker thread). | 573 // (while we're still on the worker thread). |
570 proxy_ = NULL; | 574 proxy_ = NULL; |
571 | 575 |
572 // Aborts all the pending events callbacks. | 576 // Aborts all the pending events callbacks. |
| 577 AbortPendingEventCallbacks(context_->activate_event_callbacks); |
573 AbortPendingEventCallbacks(context_->sync_event_callbacks); | 578 AbortPendingEventCallbacks(context_->sync_event_callbacks); |
574 AbortPendingEventCallbacks(context_->push_event_callbacks); | 579 AbortPendingEventCallbacks(context_->push_event_callbacks); |
575 AbortPendingEventCallbacks(context_->fetch_event_callbacks); | 580 AbortPendingEventCallbacks(context_->fetch_event_callbacks); |
576 AbortPendingEventCallbacks(context_->message_event_callbacks); | 581 AbortPendingEventCallbacks(context_->message_event_callbacks); |
577 | 582 |
578 // We have to clear callbacks now, as they need to be freed on the | 583 // We have to clear callbacks now, as they need to be freed on the |
579 // same thread. | 584 // same thread. |
580 context_.reset(); | 585 context_.reset(); |
581 | 586 |
582 // This also lets the message filter stop dispatching messages to | 587 // This also lets the message filter stop dispatching messages to |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 | 651 |
647 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* | 652 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* |
648 ServiceWorkerContextClient::createDevToolsMessageLoop() { | 653 ServiceWorkerContextClient::createDevToolsMessageLoop() { |
649 return DevToolsAgent::createMessageLoopWrapper(); | 654 return DevToolsAgent::createMessageLoopWrapper(); |
650 } | 655 } |
651 | 656 |
652 void ServiceWorkerContextClient::didHandleActivateEvent( | 657 void ServiceWorkerContextClient::didHandleActivateEvent( |
653 int request_id, | 658 int request_id, |
654 blink::WebServiceWorkerEventResult result, | 659 blink::WebServiceWorkerEventResult result, |
655 double event_dispatch_time) { | 660 double event_dispatch_time) { |
656 Send(new ServiceWorkerHostMsg_ActivateEventFinished( | 661 const DispatchActivateEventCallback* callback = |
657 GetRoutingID(), request_id, result, | 662 context_->activate_event_callbacks.Lookup(request_id); |
658 base::Time::FromDoubleT(event_dispatch_time))); | 663 DCHECK(callback); |
| 664 callback->Run(EventResultToStatus(result), |
| 665 base::Time::FromDoubleT(event_dispatch_time)); |
| 666 context_->activate_event_callbacks.Remove(request_id); |
659 } | 667 } |
660 | 668 |
661 void ServiceWorkerContextClient::didHandleExtendableMessageEvent( | 669 void ServiceWorkerContextClient::didHandleExtendableMessageEvent( |
662 int request_id, | 670 int request_id, |
663 blink::WebServiceWorkerEventResult result, | 671 blink::WebServiceWorkerEventResult result, |
664 double event_dispatch_time) { | 672 double event_dispatch_time) { |
665 const DispatchExtendableMessageEventCallback* callback = | 673 const DispatchExtendableMessageEventCallback* callback = |
666 context_->message_event_callbacks.Lookup(request_id); | 674 context_->message_event_callbacks.Lookup(request_id); |
667 DCHECK(callback); | 675 DCHECK(callback); |
668 callback->Run(EventResultToStatus(result), | 676 callback->Run(EventResultToStatus(result), |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 base::Time::FromDoubleT(event_dispatch_time))); | 737 base::Time::FromDoubleT(event_dispatch_time))); |
730 } | 738 } |
731 | 739 |
732 void ServiceWorkerContextClient::didHandlePushEvent( | 740 void ServiceWorkerContextClient::didHandlePushEvent( |
733 int request_id, | 741 int request_id, |
734 blink::WebServiceWorkerEventResult result, | 742 blink::WebServiceWorkerEventResult result, |
735 double event_dispatch_time) { | 743 double event_dispatch_time) { |
736 const DispatchPushEventCallback* callback = | 744 const DispatchPushEventCallback* callback = |
737 context_->push_event_callbacks.Lookup(request_id); | 745 context_->push_event_callbacks.Lookup(request_id); |
738 DCHECK(callback); | 746 DCHECK(callback); |
739 callback->Run(result == blink::WebServiceWorkerEventResultCompleted | 747 callback->Run(EventResultToStatus(result), |
740 ? SERVICE_WORKER_OK | |
741 : SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, | |
742 base::Time::FromDoubleT(event_dispatch_time)); | 748 base::Time::FromDoubleT(event_dispatch_time)); |
743 context_->push_event_callbacks.Remove(request_id); | 749 context_->push_event_callbacks.Remove(request_id); |
744 } | 750 } |
745 | 751 |
746 void ServiceWorkerContextClient::didHandleSyncEvent( | 752 void ServiceWorkerContextClient::didHandleSyncEvent( |
747 int request_id, | 753 int request_id, |
748 blink::WebServiceWorkerEventResult result, | 754 blink::WebServiceWorkerEventResult result, |
749 double event_dispatch_time) { | 755 double event_dispatch_time) { |
750 const SyncCallback* callback = | 756 const SyncCallback* callback = |
751 context_->sync_event_callbacks.Lookup(request_id); | 757 context_->sync_event_callbacks.Lookup(request_id); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 | 904 |
899 // Register a registration and its version attributes with the dispatcher | 905 // Register a registration and its version attributes with the dispatcher |
900 // living on the worker thread. | 906 // living on the worker thread. |
901 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( | 907 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( |
902 dispatcher->GetOrCreateRegistration(info, attrs)); | 908 dispatcher->GetOrCreateRegistration(info, attrs)); |
903 | 909 |
904 proxy_->setRegistration( | 910 proxy_->setRegistration( |
905 WebServiceWorkerRegistrationImpl::CreateHandle(registration)); | 911 WebServiceWorkerRegistrationImpl::CreateHandle(registration)); |
906 } | 912 } |
907 | 913 |
908 void ServiceWorkerContextClient::OnActivateEvent(int request_id) { | 914 void ServiceWorkerContextClient::DispatchActivateEvent( |
| 915 const DispatchActivateEventCallback& callback) { |
909 TRACE_EVENT0("ServiceWorker", | 916 TRACE_EVENT0("ServiceWorker", |
910 "ServiceWorkerContextClient::OnActivateEvent"); | 917 "ServiceWorkerContextClient::DispatchActivateEvent"); |
| 918 int request_id = context_->activate_event_callbacks.Add( |
| 919 base::MakeUnique<DispatchActivateEventCallback>(callback)); |
911 proxy_->dispatchActivateEvent(request_id); | 920 proxy_->dispatchActivateEvent(request_id); |
912 } | 921 } |
913 | 922 |
914 void ServiceWorkerContextClient::DispatchExtendableMessageEvent( | 923 void ServiceWorkerContextClient::DispatchExtendableMessageEvent( |
915 mojom::ExtendableMessageEventPtr event, | 924 mojom::ExtendableMessageEventPtr event, |
916 const DispatchExtendableMessageEventCallback& callback) { | 925 const DispatchExtendableMessageEventCallback& callback) { |
917 TRACE_EVENT0("ServiceWorker", | 926 TRACE_EVENT0("ServiceWorker", |
918 "ServiceWorkerContextClient::DispatchExtendableMessageEvent"); | 927 "ServiceWorkerContextClient::DispatchExtendableMessageEvent"); |
919 int request_id = context_->message_event_callbacks.Add( | 928 int request_id = context_->message_event_callbacks.Add( |
920 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback)); | 929 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback)); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 } | 1264 } |
1256 | 1265 |
1257 base::WeakPtr<ServiceWorkerContextClient> | 1266 base::WeakPtr<ServiceWorkerContextClient> |
1258 ServiceWorkerContextClient::GetWeakPtr() { | 1267 ServiceWorkerContextClient::GetWeakPtr() { |
1259 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1268 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
1260 DCHECK(context_); | 1269 DCHECK(context_); |
1261 return context_->weak_factory.GetWeakPtr(); | 1270 return context_->weak_factory.GetWeakPtr(); |
1262 } | 1271 } |
1263 | 1272 |
1264 } // namespace content | 1273 } // namespace content |
OLD | NEW |