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_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "content/browser/message_port_message_filter.h" | 10 #include "content/browser/message_port_message_filter.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 bool ServiceWorkerDispatcherHost::OnMessageReceived( | 156 bool ServiceWorkerDispatcherHost::OnMessageReceived( |
157 const IPC::Message& message) { | 157 const IPC::Message& message) { |
158 bool handled = true; | 158 bool handled = true; |
159 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) | 159 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) |
160 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, | 160 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, |
161 OnRegisterServiceWorker) | 161 OnRegisterServiceWorker) |
162 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, | 162 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, |
163 OnUnregisterServiceWorker) | 163 OnUnregisterServiceWorker) |
164 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, | 164 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, |
165 OnGetRegistration) | 165 OnGetRegistration) |
| 166 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady, |
| 167 OnGetRegistrationForReady) |
166 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, | 168 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, |
167 OnProviderCreated) | 169 OnProviderCreated) |
168 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, | 170 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, |
169 OnProviderDestroyed) | 171 OnProviderDestroyed) |
170 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, | 172 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, |
171 OnSetHostedVersionId) | 173 OnSetHostedVersionId) |
172 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker, | 174 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker, |
173 OnPostMessageToWorker) | 175 OnPostMessageToWorker) |
174 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerReadyForInspection, | 176 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerReadyForInspection, |
175 OnWorkerReadyForInspection) | 177 OnWorkerReadyForInspection) |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 | 487 |
486 GetContext()->storage()->FindRegistrationForDocument( | 488 GetContext()->storage()->FindRegistrationForDocument( |
487 document_url, | 489 document_url, |
488 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, | 490 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, |
489 this, | 491 this, |
490 thread_id, | 492 thread_id, |
491 provider_id, | 493 provider_id, |
492 request_id)); | 494 request_id)); |
493 } | 495 } |
494 | 496 |
| 497 void ServiceWorkerDispatcherHost::OnGetRegistrationForReady( |
| 498 int thread_id, |
| 499 int request_id, |
| 500 int provider_id) { |
| 501 TRACE_EVENT0("ServiceWorker", |
| 502 "ServiceWorkerDispatcherHost::OnGetRegistrationForReady"); |
| 503 if (!GetContext()) |
| 504 return; |
| 505 ServiceWorkerProviderHost* provider_host = |
| 506 GetContext()->GetProviderHost(render_process_id_, provider_id); |
| 507 if (!provider_host) { |
| 508 BadMessageReceived(); |
| 509 return; |
| 510 } |
| 511 if (!provider_host->IsContextAlive()) |
| 512 return; |
| 513 |
| 514 TRACE_EVENT_ASYNC_BEGIN0( |
| 515 "ServiceWorker", |
| 516 "ServiceWorkerDispatcherHost::GetRegistrationForReady", |
| 517 request_id); |
| 518 |
| 519 if (!provider_host->GetRegistrationForReady(base::Bind( |
| 520 &ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete, |
| 521 this, thread_id, request_id, provider_host->AsWeakPtr()))) { |
| 522 BadMessageReceived(); |
| 523 } |
| 524 } |
| 525 |
495 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( | 526 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( |
496 int handle_id, | 527 int handle_id, |
497 const base::string16& message, | 528 const base::string16& message, |
498 const std::vector<TransferredMessagePort>& sent_message_ports) { | 529 const std::vector<TransferredMessagePort>& sent_message_ports) { |
499 TRACE_EVENT0("ServiceWorker", | 530 TRACE_EVENT0("ServiceWorker", |
500 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); | 531 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); |
501 if (!GetContext()) | 532 if (!GetContext()) |
502 return; | 533 return; |
503 | 534 |
504 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 535 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 if (!registration->is_uninstalling()) { | 932 if (!registration->is_uninstalling()) { |
902 GetRegistrationObjectInfoAndVersionAttributes( | 933 GetRegistrationObjectInfoAndVersionAttributes( |
903 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); | 934 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); |
904 } | 935 } |
905 } | 936 } |
906 | 937 |
907 Send(new ServiceWorkerMsg_DidGetRegistration( | 938 Send(new ServiceWorkerMsg_DidGetRegistration( |
908 thread_id, request_id, info, attrs)); | 939 thread_id, request_id, info, attrs)); |
909 } | 940 } |
910 | 941 |
| 942 void ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete( |
| 943 int thread_id, |
| 944 int request_id, |
| 945 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 946 ServiceWorkerRegistration* registration) { |
| 947 DCHECK(registration); |
| 948 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 949 "ServiceWorkerDispatcherHost::GetRegistrationForReady", |
| 950 request_id, |
| 951 "Registration ID", |
| 952 registration ? registration->id() |
| 953 : kInvalidServiceWorkerRegistrationId); |
| 954 |
| 955 if (!GetContext()) |
| 956 return; |
| 957 |
| 958 ServiceWorkerRegistrationObjectInfo info; |
| 959 ServiceWorkerVersionAttributes attrs; |
| 960 GetRegistrationObjectInfoAndVersionAttributes( |
| 961 provider_host, registration, &info, &attrs); |
| 962 Send(new ServiceWorkerMsg_DidGetRegistrationForReady( |
| 963 thread_id, request_id, info, attrs)); |
| 964 } |
| 965 |
911 void ServiceWorkerDispatcherHost::SendRegistrationError( | 966 void ServiceWorkerDispatcherHost::SendRegistrationError( |
912 int thread_id, | 967 int thread_id, |
913 int request_id, | 968 int request_id, |
914 ServiceWorkerStatusCode status, | 969 ServiceWorkerStatusCode status, |
915 const std::string& status_message) { | 970 const std::string& status_message) { |
916 base::string16 error_message; | 971 base::string16 error_message; |
917 blink::WebServiceWorkerError::ErrorType error_type; | 972 blink::WebServiceWorkerError::ErrorType error_type; |
918 GetServiceWorkerRegistrationStatusResponse(status, status_message, | 973 GetServiceWorkerRegistrationStatusResponse(status, status_message, |
919 &error_type, &error_message); | 974 &error_type, &error_message); |
920 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 975 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 1014 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
960 if (!handle) { | 1015 if (!handle) { |
961 BadMessageReceived(); | 1016 BadMessageReceived(); |
962 return; | 1017 return; |
963 } | 1018 } |
964 handle->version()->StopWorker( | 1019 handle->version()->StopWorker( |
965 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1020 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
966 } | 1021 } |
967 | 1022 |
968 } // namespace content | 1023 } // namespace content |
OLD | NEW |