OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/service_worker/service_worker_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 if (running_status() == EmbeddedWorkerStatus::RUNNING) { | 623 if (running_status() == EmbeddedWorkerStatus::RUNNING) { |
624 DCHECK(start_callbacks_.empty()); | 624 DCHECK(start_callbacks_.empty()); |
625 task.Run(); | 625 task.Run(); |
626 return; | 626 return; |
627 } | 627 } |
628 StartWorker(purpose, | 628 StartWorker(purpose, |
629 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), | 629 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), |
630 error_callback, task)); | 630 error_callback, task)); |
631 } | 631 } |
632 | 632 |
633 void ServiceWorkerVersion::DispatchEvent(const std::vector<int>& request_ids, | |
634 const IPC::Message& message) { | |
635 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status()); | |
636 | |
637 const ServiceWorkerStatusCode status = embedded_worker_->SendMessage(message); | |
638 | |
639 for (int request_id : request_ids) { | |
640 PendingRequest* request = pending_requests_.Lookup(request_id); | |
641 DCHECK(request) << "Invalid request id"; | |
642 DCHECK(!request->is_dispatched) | |
643 << "Request already dispatched an IPC event"; | |
644 if (status != SERVICE_WORKER_OK) { | |
645 RunSoon(base::Bind(request->error_callback, status)); | |
646 pending_requests_.Remove(request_id); | |
647 } else { | |
648 request->is_dispatched = true; | |
649 } | |
650 } | |
651 } | |
652 | |
653 void ServiceWorkerVersion::AddControllee( | 633 void ServiceWorkerVersion::AddControllee( |
654 ServiceWorkerProviderHost* provider_host) { | 634 ServiceWorkerProviderHost* provider_host) { |
655 const std::string& uuid = provider_host->client_uuid(); | 635 const std::string& uuid = provider_host->client_uuid(); |
656 CHECK(!provider_host->client_uuid().empty()); | 636 CHECK(!provider_host->client_uuid().empty()); |
657 DCHECK(!base::ContainsKey(controllee_map_, uuid)); | 637 DCHECK(!base::ContainsKey(controllee_map_, uuid)); |
658 controllee_map_[uuid] = provider_host; | 638 controllee_map_[uuid] = provider_host; |
659 // Keep the worker alive a bit longer right after a new controllee is added. | 639 // Keep the worker alive a bit longer right after a new controllee is added. |
660 RestartTick(&idle_time_); | 640 RestartTick(&idle_time_); |
661 for (auto& observer : listeners_) | 641 for (auto& observer : listeners_) |
662 observer.OnControlleeAdded(this, provider_host); | 642 observer.OnControlleeAdded(this, provider_host); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 OnClearCachedMetadata) | 934 OnClearCachedMetadata) |
955 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, | 935 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, |
956 OnPostMessageToClient) | 936 OnPostMessageToClient) |
957 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, | 937 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, |
958 OnFocusClient) | 938 OnFocusClient) |
959 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NavigateClient, OnNavigateClient) | 939 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NavigateClient, OnNavigateClient) |
960 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting, | 940 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting, |
961 OnSkipWaiting) | 941 OnSkipWaiting) |
962 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, | 942 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, |
963 OnClaimClients) | 943 OnClaimClients) |
964 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterForeignFetchScopes, | |
965 OnRegisterForeignFetchScopes) | |
966 IPC_MESSAGE_UNHANDLED(handled = false) | 944 IPC_MESSAGE_UNHANDLED(handled = false) |
967 IPC_END_MESSAGE_MAP() | 945 IPC_END_MESSAGE_MAP() |
968 return handled; | 946 return handled; |
969 } | 947 } |
970 | 948 |
971 void ServiceWorkerVersion::OnStartSentAndScriptEvaluated( | 949 void ServiceWorkerVersion::OnStartSentAndScriptEvaluated( |
972 ServiceWorkerStatusCode status) { | 950 ServiceWorkerStatusCode status) { |
973 if (status != SERVICE_WORKER_OK) { | 951 if (status != SERVICE_WORKER_OK) { |
974 scoped_refptr<ServiceWorkerVersion> protect(this); | 952 scoped_refptr<ServiceWorkerVersion> protect(this); |
975 FinishStartWorker(DeduceStartWorkerFailureReason(status)); | 953 FinishStartWorker(DeduceStartWorkerFailureReason(status)); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 | 1308 |
1331 embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError( | 1309 embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError( |
1332 request_id, blink::WebServiceWorkerError::kErrorTypeAbort, | 1310 request_id, blink::WebServiceWorkerError::kErrorTypeAbort, |
1333 base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage))); | 1311 base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage))); |
1334 } | 1312 } |
1335 | 1313 |
1336 void ServiceWorkerVersion::OnPongFromWorker() { | 1314 void ServiceWorkerVersion::OnPongFromWorker() { |
1337 ping_controller_->OnPongReceived(); | 1315 ping_controller_->OnPongReceived(); |
1338 } | 1316 } |
1339 | 1317 |
1340 void ServiceWorkerVersion::OnRegisterForeignFetchScopes( | 1318 void ServiceWorkerVersion::RegisterForeignFetchScopes( |
1341 const std::vector<GURL>& sub_scopes, | 1319 const std::vector<GURL>& sub_scopes, |
1342 const std::vector<url::Origin>& origins) { | 1320 const std::vector<url::Origin>& origins) { |
1343 DCHECK(status() == INSTALLING || status() == REDUNDANT) << status(); | 1321 DCHECK(status() == INSTALLING || status() == REDUNDANT) << status(); |
1344 // Renderer should have already verified all these urls are inside the | 1322 // Renderer should have already verified all these urls are inside the |
1345 // worker's scope, but verify again here on the browser process side. | 1323 // worker's scope, but verify again here on the browser process side. |
1346 GURL origin = scope_.GetOrigin(); | 1324 GURL origin = scope_.GetOrigin(); |
1347 std::string scope_path = scope_.path(); | 1325 std::string scope_path = scope_.path(); |
1348 for (const GURL& url : sub_scopes) { | 1326 for (const GURL& url : sub_scopes) { |
1349 if (!url.is_valid() || url.GetOrigin() != origin || | 1327 if (!url.is_valid() || url.GetOrigin() != origin || |
1350 !base::StartsWith(url.path(), scope_path, | 1328 !base::StartsWith(url.path(), scope_path, |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 | 1818 |
1841 void ServiceWorkerVersion::CleanUpExternalRequest( | 1819 void ServiceWorkerVersion::CleanUpExternalRequest( |
1842 const std::string& request_uuid, | 1820 const std::string& request_uuid, |
1843 ServiceWorkerStatusCode status) { | 1821 ServiceWorkerStatusCode status) { |
1844 if (status == SERVICE_WORKER_OK) | 1822 if (status == SERVICE_WORKER_OK) |
1845 return; | 1823 return; |
1846 external_request_uuid_to_request_id_.erase(request_uuid); | 1824 external_request_uuid_to_request_id_.erase(request_uuid); |
1847 } | 1825 } |
1848 | 1826 |
1849 } // namespace content | 1827 } // namespace content |
OLD | NEW |