| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 // worker thread. | 186 // worker thread. |
| 187 struct ServiceWorkerContextClient::WorkerContextData { | 187 struct ServiceWorkerContextClient::WorkerContextData { |
| 188 using ClientsCallbacksMap = | 188 using ClientsCallbacksMap = |
| 189 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; | 189 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; |
| 190 using ClaimClientsCallbacksMap = | 190 using ClaimClientsCallbacksMap = |
| 191 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; | 191 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; |
| 192 using ClientCallbacksMap = | 192 using ClientCallbacksMap = |
| 193 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; | 193 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; |
| 194 using SkipWaitingCallbacksMap = | 194 using SkipWaitingCallbacksMap = |
| 195 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; | 195 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; |
| 196 using ActivateEventCallbacksMap = |
| 197 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; |
| 196 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; | 198 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; |
| 197 using PaymentRequestEventCallbacksMap = | 199 using PaymentRequestEventCallbacksMap = |
| 198 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; | 200 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; |
| 199 using NotificationClickEventCallbacksMap = | 201 using NotificationClickEventCallbacksMap = |
| 200 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; | 202 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; |
| 201 using NotificationCloseEventCallbacksMap = | 203 using NotificationCloseEventCallbacksMap = |
| 202 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; | 204 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; |
| 203 using PushEventCallbacksMap = | 205 using PushEventCallbacksMap = |
| 204 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; | 206 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; |
| 205 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; | 207 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 224 | 226 |
| 225 // Pending callbacks for OpenWindow() and FocusClient(). | 227 // Pending callbacks for OpenWindow() and FocusClient(). |
| 226 ClientCallbacksMap client_callbacks; | 228 ClientCallbacksMap client_callbacks; |
| 227 | 229 |
| 228 // Pending callbacks for SkipWaiting(). | 230 // Pending callbacks for SkipWaiting(). |
| 229 SkipWaitingCallbacksMap skip_waiting_callbacks; | 231 SkipWaitingCallbacksMap skip_waiting_callbacks; |
| 230 | 232 |
| 231 // Pending callbacks for ClaimClients(). | 233 // Pending callbacks for ClaimClients(). |
| 232 ClaimClientsCallbacksMap claim_clients_callbacks; | 234 ClaimClientsCallbacksMap claim_clients_callbacks; |
| 233 | 235 |
| 236 // Pending callbacks for Activate Events. |
| 237 ActivateEventCallbacksMap activate_event_callbacks; |
| 238 |
| 234 // Pending callbacks for Background Sync Events. | 239 // Pending callbacks for Background Sync Events. |
| 235 SyncEventCallbacksMap sync_event_callbacks; | 240 SyncEventCallbacksMap sync_event_callbacks; |
| 236 | 241 |
| 237 // Pending callbacks for Payment Request Events. | 242 // Pending callbacks for Payment Request Events. |
| 238 PaymentRequestEventCallbacksMap payment_request_event_callbacks; | 243 PaymentRequestEventCallbacksMap payment_request_event_callbacks; |
| 239 | 244 |
| 240 // Pending callbacks for Notification Click Events. | 245 // Pending callbacks for Notification Click Events. |
| 241 NotificationClickEventCallbacksMap notification_click_event_callbacks; | 246 NotificationClickEventCallbacksMap notification_click_event_callbacks; |
| 242 | 247 |
| 243 // Pending callbacks for Notification Close Events. | 248 // Pending callbacks for Notification Close Events. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 405 |
| 401 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} | 406 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} |
| 402 | 407 |
| 403 void ServiceWorkerContextClient::OnMessageReceived( | 408 void ServiceWorkerContextClient::OnMessageReceived( |
| 404 int thread_id, | 409 int thread_id, |
| 405 int embedded_worker_id, | 410 int embedded_worker_id, |
| 406 const IPC::Message& message) { | 411 const IPC::Message& message) { |
| 407 CHECK_EQ(embedded_worker_id_, embedded_worker_id); | 412 CHECK_EQ(embedded_worker_id_, embedded_worker_id); |
| 408 bool handled = true; | 413 bool handled = true; |
| 409 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) | 414 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) |
| 410 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) | |
| 411 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) | 415 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) |
| 412 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) | 416 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) |
| 413 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) | 417 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) |
| 414 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, | 418 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, |
| 415 OnOpenWindowResponse) | 419 OnOpenWindowResponse) |
| 416 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, | 420 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, |
| 417 OnOpenWindowError) | 421 OnOpenWindowError) |
| 418 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 422 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
| 419 OnFocusClientResponse) | 423 OnFocusClientResponse) |
| 420 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, | 424 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 } | 568 } |
| 565 | 569 |
| 566 void ServiceWorkerContextClient::willDestroyWorkerContext( | 570 void ServiceWorkerContextClient::willDestroyWorkerContext( |
| 567 v8::Local<v8::Context> context) { | 571 v8::Local<v8::Context> context) { |
| 568 // At this point WillStopCurrentWorkerThread is already called, so | 572 // At this point WillStopCurrentWorkerThread is already called, so |
| 569 // worker_task_runner_->RunsTasksOnCurrentThread() returns false | 573 // worker_task_runner_->RunsTasksOnCurrentThread() returns false |
| 570 // (while we're still on the worker thread). | 574 // (while we're still on the worker thread). |
| 571 proxy_ = NULL; | 575 proxy_ = NULL; |
| 572 | 576 |
| 573 // Aborts all the pending events callbacks. | 577 // Aborts all the pending events callbacks. |
| 578 AbortPendingEventCallbacks(context_->activate_event_callbacks); |
| 574 AbortPendingEventCallbacks(context_->sync_event_callbacks); | 579 AbortPendingEventCallbacks(context_->sync_event_callbacks); |
| 575 AbortPendingEventCallbacks(context_->notification_click_event_callbacks); | 580 AbortPendingEventCallbacks(context_->notification_click_event_callbacks); |
| 576 AbortPendingEventCallbacks(context_->notification_close_event_callbacks); | 581 AbortPendingEventCallbacks(context_->notification_close_event_callbacks); |
| 577 AbortPendingEventCallbacks(context_->push_event_callbacks); | 582 AbortPendingEventCallbacks(context_->push_event_callbacks); |
| 578 AbortPendingEventCallbacks(context_->fetch_event_callbacks); | 583 AbortPendingEventCallbacks(context_->fetch_event_callbacks); |
| 579 AbortPendingEventCallbacks(context_->message_event_callbacks); | 584 AbortPendingEventCallbacks(context_->message_event_callbacks); |
| 580 | 585 |
| 581 // We have to clear callbacks now, as they need to be freed on the | 586 // We have to clear callbacks now, as they need to be freed on the |
| 582 // same thread. | 587 // same thread. |
| 583 context_.reset(); | 588 context_.reset(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 662 |
| 658 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* | 663 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* |
| 659 ServiceWorkerContextClient::createDevToolsMessageLoop() { | 664 ServiceWorkerContextClient::createDevToolsMessageLoop() { |
| 660 return DevToolsAgent::createMessageLoopWrapper(); | 665 return DevToolsAgent::createMessageLoopWrapper(); |
| 661 } | 666 } |
| 662 | 667 |
| 663 void ServiceWorkerContextClient::didHandleActivateEvent( | 668 void ServiceWorkerContextClient::didHandleActivateEvent( |
| 664 int request_id, | 669 int request_id, |
| 665 blink::WebServiceWorkerEventResult result, | 670 blink::WebServiceWorkerEventResult result, |
| 666 double event_dispatch_time) { | 671 double event_dispatch_time) { |
| 667 Send(new ServiceWorkerHostMsg_ActivateEventFinished( | 672 const DispatchActivateEventCallback* callback = |
| 668 GetRoutingID(), request_id, result, | 673 context_->activate_event_callbacks.Lookup(request_id); |
| 669 base::Time::FromDoubleT(event_dispatch_time))); | 674 DCHECK(callback); |
| 675 callback->Run(EventResultToStatus(result), |
| 676 base::Time::FromDoubleT(event_dispatch_time)); |
| 677 context_->activate_event_callbacks.Remove(request_id); |
| 670 } | 678 } |
| 671 | 679 |
| 672 void ServiceWorkerContextClient::didHandleExtendableMessageEvent( | 680 void ServiceWorkerContextClient::didHandleExtendableMessageEvent( |
| 673 int request_id, | 681 int request_id, |
| 674 blink::WebServiceWorkerEventResult result, | 682 blink::WebServiceWorkerEventResult result, |
| 675 double event_dispatch_time) { | 683 double event_dispatch_time) { |
| 676 const DispatchExtendableMessageEventCallback* callback = | 684 const DispatchExtendableMessageEventCallback* callback = |
| 677 context_->message_event_callbacks.Lookup(request_id); | 685 context_->message_event_callbacks.Lookup(request_id); |
| 678 DCHECK(callback); | 686 DCHECK(callback); |
| 679 callback->Run(EventResultToStatus(result), | 687 callback->Run(EventResultToStatus(result), |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 | 934 |
| 927 // Register a registration and its version attributes with the dispatcher | 935 // Register a registration and its version attributes with the dispatcher |
| 928 // living on the worker thread. | 936 // living on the worker thread. |
| 929 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( | 937 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( |
| 930 dispatcher->GetOrCreateRegistration(info, attrs)); | 938 dispatcher->GetOrCreateRegistration(info, attrs)); |
| 931 | 939 |
| 932 proxy_->setRegistration( | 940 proxy_->setRegistration( |
| 933 WebServiceWorkerRegistrationImpl::CreateHandle(registration)); | 941 WebServiceWorkerRegistrationImpl::CreateHandle(registration)); |
| 934 } | 942 } |
| 935 | 943 |
| 936 void ServiceWorkerContextClient::OnActivateEvent(int request_id) { | 944 void ServiceWorkerContextClient::DispatchActivateEvent( |
| 945 const DispatchActivateEventCallback& callback) { |
| 937 TRACE_EVENT0("ServiceWorker", | 946 TRACE_EVENT0("ServiceWorker", |
| 938 "ServiceWorkerContextClient::OnActivateEvent"); | 947 "ServiceWorkerContextClient::DispatchActivateEvent"); |
| 948 int request_id = context_->activate_event_callbacks.Add( |
| 949 base::MakeUnique<DispatchActivateEventCallback>(callback)); |
| 939 proxy_->dispatchActivateEvent(request_id); | 950 proxy_->dispatchActivateEvent(request_id); |
| 940 } | 951 } |
| 941 | 952 |
| 942 void ServiceWorkerContextClient::DispatchExtendableMessageEvent( | 953 void ServiceWorkerContextClient::DispatchExtendableMessageEvent( |
| 943 mojom::ExtendableMessageEventPtr event, | 954 mojom::ExtendableMessageEventPtr event, |
| 944 const DispatchExtendableMessageEventCallback& callback) { | 955 const DispatchExtendableMessageEventCallback& callback) { |
| 945 TRACE_EVENT0("ServiceWorker", | 956 TRACE_EVENT0("ServiceWorker", |
| 946 "ServiceWorkerContextClient::DispatchExtendableMessageEvent"); | 957 "ServiceWorkerContextClient::DispatchExtendableMessageEvent"); |
| 947 int request_id = context_->message_event_callbacks.Add( | 958 int request_id = context_->message_event_callbacks.Add( |
| 948 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback)); | 959 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback)); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 } | 1305 } |
| 1295 | 1306 |
| 1296 base::WeakPtr<ServiceWorkerContextClient> | 1307 base::WeakPtr<ServiceWorkerContextClient> |
| 1297 ServiceWorkerContextClient::GetWeakPtr() { | 1308 ServiceWorkerContextClient::GetWeakPtr() { |
| 1298 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1309 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1299 DCHECK(context_); | 1310 DCHECK(context_); |
| 1300 return context_->weak_factory.GetWeakPtr(); | 1311 return context_->weak_factory.GetWeakPtr(); |
| 1301 } | 1312 } |
| 1302 | 1313 |
| 1303 } // namespace content | 1314 } // namespace content |
| OLD | NEW |