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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 if (!registration->is_uninstalling()) { | 929 if (!registration->is_uninstalling()) { |
899 GetRegistrationObjectInfoAndVersionAttributes( | 930 GetRegistrationObjectInfoAndVersionAttributes( |
900 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); | 931 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); |
901 } | 932 } |
902 } | 933 } |
903 | 934 |
904 Send(new ServiceWorkerMsg_DidGetRegistration( | 935 Send(new ServiceWorkerMsg_DidGetRegistration( |
905 thread_id, request_id, info, attrs)); | 936 thread_id, request_id, info, attrs)); |
906 } | 937 } |
907 | 938 |
| 939 void ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete( |
| 940 int thread_id, |
| 941 int request_id, |
| 942 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 943 ServiceWorkerRegistration* registration) { |
| 944 DCHECK(registration); |
| 945 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 946 "ServiceWorkerDispatcherHost::GetRegistrationForReady", |
| 947 request_id, |
| 948 "Registration ID", |
| 949 registration ? registration->id() |
| 950 : kInvalidServiceWorkerRegistrationId); |
| 951 |
| 952 if (!GetContext()) |
| 953 return; |
| 954 |
| 955 ServiceWorkerRegistrationObjectInfo info; |
| 956 ServiceWorkerVersionAttributes attrs; |
| 957 GetRegistrationObjectInfoAndVersionAttributes( |
| 958 provider_host, registration, &info, &attrs); |
| 959 Send(new ServiceWorkerMsg_DidGetRegistrationForReady( |
| 960 thread_id, request_id, info, attrs)); |
| 961 } |
| 962 |
908 void ServiceWorkerDispatcherHost::SendRegistrationError( | 963 void ServiceWorkerDispatcherHost::SendRegistrationError( |
909 int thread_id, | 964 int thread_id, |
910 int request_id, | 965 int request_id, |
911 ServiceWorkerStatusCode status, | 966 ServiceWorkerStatusCode status, |
912 const std::string& status_message) { | 967 const std::string& status_message) { |
913 base::string16 error_message; | 968 base::string16 error_message; |
914 blink::WebServiceWorkerError::ErrorType error_type; | 969 blink::WebServiceWorkerError::ErrorType error_type; |
915 GetServiceWorkerRegistrationStatusResponse(status, status_message, | 970 GetServiceWorkerRegistrationStatusResponse(status, status_message, |
916 &error_type, &error_message); | 971 &error_type, &error_message); |
917 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 972 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 1011 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
957 if (!handle) { | 1012 if (!handle) { |
958 BadMessageReceived(); | 1013 BadMessageReceived(); |
959 return; | 1014 return; |
960 } | 1015 } |
961 handle->version()->StopWorker( | 1016 handle->version()->StopWorker( |
962 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1017 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
963 } | 1018 } |
964 | 1019 |
965 } // namespace content | 1020 } // namespace content |
OLD | NEW |