| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 // worker thread. | 198 // worker thread. |
| 199 struct ServiceWorkerContextClient::WorkerContextData { | 199 struct ServiceWorkerContextClient::WorkerContextData { |
| 200 using ClientsCallbacksMap = | 200 using ClientsCallbacksMap = |
| 201 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; | 201 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; |
| 202 using ClaimClientsCallbacksMap = | 202 using ClaimClientsCallbacksMap = |
| 203 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; | 203 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; |
| 204 using ClientCallbacksMap = | 204 using ClientCallbacksMap = |
| 205 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; | 205 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; |
| 206 using SkipWaitingCallbacksMap = | 206 using SkipWaitingCallbacksMap = |
| 207 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; | 207 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; |
| 208 using ActivateEventCallbacksMap = |
| 209 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; |
| 208 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; | 210 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; |
| 209 using PaymentRequestEventCallbacksMap = | 211 using PaymentRequestEventCallbacksMap = |
| 210 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; | 212 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; |
| 211 using NotificationClickEventCallbacksMap = | 213 using NotificationClickEventCallbacksMap = |
| 212 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; | 214 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; |
| 213 using NotificationCloseEventCallbacksMap = | 215 using NotificationCloseEventCallbacksMap = |
| 214 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; | 216 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; |
| 215 using PushEventCallbacksMap = | 217 using PushEventCallbacksMap = |
| 216 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; | 218 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; |
| 217 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; | 219 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 236 | 238 |
| 237 // Pending callbacks for OpenWindow() and FocusClient(). | 239 // Pending callbacks for OpenWindow() and FocusClient(). |
| 238 ClientCallbacksMap client_callbacks; | 240 ClientCallbacksMap client_callbacks; |
| 239 | 241 |
| 240 // Pending callbacks for SkipWaiting(). | 242 // Pending callbacks for SkipWaiting(). |
| 241 SkipWaitingCallbacksMap skip_waiting_callbacks; | 243 SkipWaitingCallbacksMap skip_waiting_callbacks; |
| 242 | 244 |
| 243 // Pending callbacks for ClaimClients(). | 245 // Pending callbacks for ClaimClients(). |
| 244 ClaimClientsCallbacksMap claim_clients_callbacks; | 246 ClaimClientsCallbacksMap claim_clients_callbacks; |
| 245 | 247 |
| 248 // Pending callbacks for Activate Events. |
| 249 ActivateEventCallbacksMap activate_event_callbacks; |
| 250 |
| 246 // Pending callbacks for Background Sync Events. | 251 // Pending callbacks for Background Sync Events. |
| 247 SyncEventCallbacksMap sync_event_callbacks; | 252 SyncEventCallbacksMap sync_event_callbacks; |
| 248 | 253 |
| 249 // Pending callbacks for Payment Request Events. | 254 // Pending callbacks for Payment Request Events. |
| 250 PaymentRequestEventCallbacksMap payment_request_event_callbacks; | 255 PaymentRequestEventCallbacksMap payment_request_event_callbacks; |
| 251 | 256 |
| 252 // Pending callbacks for Notification Click Events. | 257 // Pending callbacks for Notification Click Events. |
| 253 NotificationClickEventCallbacksMap notification_click_event_callbacks; | 258 NotificationClickEventCallbacksMap notification_click_event_callbacks; |
| 254 | 259 |
| 255 // Pending callbacks for Notification Close Events. | 260 // Pending callbacks for Notification Close Events. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 417 |
| 413 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} | 418 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} |
| 414 | 419 |
| 415 void ServiceWorkerContextClient::OnMessageReceived( | 420 void ServiceWorkerContextClient::OnMessageReceived( |
| 416 int thread_id, | 421 int thread_id, |
| 417 int embedded_worker_id, | 422 int embedded_worker_id, |
| 418 const IPC::Message& message) { | 423 const IPC::Message& message) { |
| 419 CHECK_EQ(embedded_worker_id_, embedded_worker_id); | 424 CHECK_EQ(embedded_worker_id_, embedded_worker_id); |
| 420 bool handled = true; | 425 bool handled = true; |
| 421 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) | 426 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) |
| 422 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) | |
| 423 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) | 427 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) |
| 424 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) | 428 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) |
| 425 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) | 429 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) |
| 426 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, | 430 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, |
| 427 OnOpenWindowResponse) | 431 OnOpenWindowResponse) |
| 428 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, | 432 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, |
| 429 OnOpenWindowError) | 433 OnOpenWindowError) |
| 430 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, | 434 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, |
| 431 OnFocusClientResponse) | 435 OnFocusClientResponse) |
| 432 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, | 436 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 } | 580 } |
| 577 | 581 |
| 578 void ServiceWorkerContextClient::willDestroyWorkerContext( | 582 void ServiceWorkerContextClient::willDestroyWorkerContext( |
| 579 v8::Local<v8::Context> context) { | 583 v8::Local<v8::Context> context) { |
| 580 // At this point WillStopCurrentWorkerThread is already called, so | 584 // At this point WillStopCurrentWorkerThread is already called, so |
| 581 // worker_task_runner_->RunsTasksOnCurrentThread() returns false | 585 // worker_task_runner_->RunsTasksOnCurrentThread() returns false |
| 582 // (while we're still on the worker thread). | 586 // (while we're still on the worker thread). |
| 583 proxy_ = NULL; | 587 proxy_ = NULL; |
| 584 | 588 |
| 585 // Aborts all the pending events callbacks. | 589 // Aborts all the pending events callbacks. |
| 590 AbortPendingEventCallbacks(context_->activate_event_callbacks); |
| 586 AbortPendingEventCallbacks(context_->sync_event_callbacks); | 591 AbortPendingEventCallbacks(context_->sync_event_callbacks); |
| 587 AbortPendingEventCallbacks(context_->notification_click_event_callbacks); | 592 AbortPendingEventCallbacks(context_->notification_click_event_callbacks); |
| 588 AbortPendingEventCallbacks(context_->notification_close_event_callbacks); | 593 AbortPendingEventCallbacks(context_->notification_close_event_callbacks); |
| 589 AbortPendingEventCallbacks(context_->push_event_callbacks); | 594 AbortPendingEventCallbacks(context_->push_event_callbacks); |
| 590 AbortPendingEventCallbacks(context_->fetch_event_callbacks); | 595 AbortPendingEventCallbacks(context_->fetch_event_callbacks); |
| 591 AbortPendingEventCallbacks(context_->message_event_callbacks); | 596 AbortPendingEventCallbacks(context_->message_event_callbacks); |
| 592 | 597 |
| 593 // We have to clear callbacks now, as they need to be freed on the | 598 // We have to clear callbacks now, as they need to be freed on the |
| 594 // same thread. | 599 // same thread. |
| 595 context_.reset(); | 600 context_.reset(); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 666 |
| 662 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* | 667 blink::WebDevToolsAgentClient::WebKitClientMessageLoop* |
| 663 ServiceWorkerContextClient::createDevToolsMessageLoop() { | 668 ServiceWorkerContextClient::createDevToolsMessageLoop() { |
| 664 return DevToolsAgent::createMessageLoopWrapper(); | 669 return DevToolsAgent::createMessageLoopWrapper(); |
| 665 } | 670 } |
| 666 | 671 |
| 667 void ServiceWorkerContextClient::didHandleActivateEvent( | 672 void ServiceWorkerContextClient::didHandleActivateEvent( |
| 668 int request_id, | 673 int request_id, |
| 669 blink::WebServiceWorkerEventResult result, | 674 blink::WebServiceWorkerEventResult result, |
| 670 double event_dispatch_time) { | 675 double event_dispatch_time) { |
| 671 Send(new ServiceWorkerHostMsg_ActivateEventFinished( | 676 const DispatchActivateEventCallback* callback = |
| 672 GetRoutingID(), request_id, result, | 677 context_->activate_event_callbacks.Lookup(request_id); |
| 673 base::Time::FromDoubleT(event_dispatch_time))); | 678 DCHECK(callback); |
| 679 callback->Run(EventResultToStatus(result), |
| 680 base::Time::FromDoubleT(event_dispatch_time)); |
| 681 context_->activate_event_callbacks.Remove(request_id); |
| 674 } | 682 } |
| 675 | 683 |
| 676 void ServiceWorkerContextClient::didHandleExtendableMessageEvent( | 684 void ServiceWorkerContextClient::didHandleExtendableMessageEvent( |
| 677 int request_id, | 685 int request_id, |
| 678 blink::WebServiceWorkerEventResult result, | 686 blink::WebServiceWorkerEventResult result, |
| 679 double event_dispatch_time) { | 687 double event_dispatch_time) { |
| 680 const DispatchExtendableMessageEventCallback* callback = | 688 const DispatchExtendableMessageEventCallback* callback = |
| 681 context_->message_event_callbacks.Lookup(request_id); | 689 context_->message_event_callbacks.Lookup(request_id); |
| 682 DCHECK(callback); | 690 DCHECK(callback); |
| 683 callback->Run(EventResultToStatus(result), | 691 callback->Run(EventResultToStatus(result), |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 | 945 |
| 938 // Register a registration and its version attributes with the dispatcher | 946 // Register a registration and its version attributes with the dispatcher |
| 939 // living on the worker thread. | 947 // living on the worker thread. |
| 940 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( | 948 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( |
| 941 dispatcher->GetOrCreateRegistration(info, attrs)); | 949 dispatcher->GetOrCreateRegistration(info, attrs)); |
| 942 | 950 |
| 943 proxy_->setRegistration( | 951 proxy_->setRegistration( |
| 944 WebServiceWorkerRegistrationImpl::CreateHandle(registration)); | 952 WebServiceWorkerRegistrationImpl::CreateHandle(registration)); |
| 945 } | 953 } |
| 946 | 954 |
| 947 void ServiceWorkerContextClient::OnActivateEvent(int request_id) { | 955 void ServiceWorkerContextClient::DispatchActivateEvent( |
| 956 const DispatchActivateEventCallback& callback) { |
| 948 TRACE_EVENT0("ServiceWorker", | 957 TRACE_EVENT0("ServiceWorker", |
| 949 "ServiceWorkerContextClient::OnActivateEvent"); | 958 "ServiceWorkerContextClient::DispatchActivateEvent"); |
| 959 int request_id = context_->activate_event_callbacks.Add( |
| 960 base::MakeUnique<DispatchActivateEventCallback>(callback)); |
| 950 proxy_->dispatchActivateEvent(request_id); | 961 proxy_->dispatchActivateEvent(request_id); |
| 951 } | 962 } |
| 952 | 963 |
| 953 void ServiceWorkerContextClient::DispatchExtendableMessageEvent( | 964 void ServiceWorkerContextClient::DispatchExtendableMessageEvent( |
| 954 mojom::ExtendableMessageEventPtr event, | 965 mojom::ExtendableMessageEventPtr event, |
| 955 const DispatchExtendableMessageEventCallback& callback) { | 966 const DispatchExtendableMessageEventCallback& callback) { |
| 956 TRACE_EVENT0("ServiceWorker", | 967 TRACE_EVENT0("ServiceWorker", |
| 957 "ServiceWorkerContextClient::DispatchExtendableMessageEvent"); | 968 "ServiceWorkerContextClient::DispatchExtendableMessageEvent"); |
| 958 int request_id = context_->message_event_callbacks.Add( | 969 int request_id = context_->message_event_callbacks.Add( |
| 959 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback)); | 970 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback)); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 } | 1316 } |
| 1306 | 1317 |
| 1307 base::WeakPtr<ServiceWorkerContextClient> | 1318 base::WeakPtr<ServiceWorkerContextClient> |
| 1308 ServiceWorkerContextClient::GetWeakPtr() { | 1319 ServiceWorkerContextClient::GetWeakPtr() { |
| 1309 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1320 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1310 DCHECK(context_); | 1321 DCHECK(context_); |
| 1311 return context_->weak_factory.GetWeakPtr(); | 1322 return context_->weak_factory.GetWeakPtr(); |
| 1312 } | 1323 } |
| 1313 | 1324 |
| 1314 } // namespace content | 1325 } // namespace content |
| OLD | NEW |