| 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_GetReadyRegistration, |
| 167 OnGetReadyRegistration) |
| 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 502 |
| 501 GetContext()->storage()->FindRegistrationForDocument( | 503 GetContext()->storage()->FindRegistrationForDocument( |
| 502 document_url, | 504 document_url, |
| 503 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, | 505 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, |
| 504 this, | 506 this, |
| 505 thread_id, | 507 thread_id, |
| 506 provider_id, | 508 provider_id, |
| 507 request_id)); | 509 request_id)); |
| 508 } | 510 } |
| 509 | 511 |
| 512 void ServiceWorkerDispatcherHost::OnGetReadyRegistration(int thread_id, |
| 513 int request_id, |
| 514 int provider_id) { |
| 515 TRACE_EVENT0("ServiceWorker", |
| 516 "ServiceWorkerDispatcherHost::OnGetReadyRegistration"); |
| 517 if (!GetContext()) |
| 518 return; |
| 519 ServiceWorkerProviderHost* provider_host = |
| 520 GetContext()->GetProviderHost(render_process_id_, provider_id); |
| 521 if (!provider_host || !provider_host->IsContextAlive()) |
| 522 return; |
| 523 |
| 524 TRACE_EVENT_ASYNC_BEGIN0( |
| 525 "ServiceWorker", |
| 526 "ServiceWorkerDispatcherHost::GetReadyRegistration", |
| 527 request_id); |
| 528 |
| 529 provider_host->GetReadyRegistration( |
| 530 base::Bind(&ServiceWorkerDispatcherHost::GetReadyRegistrationComplete, |
| 531 this, thread_id, request_id, provider_host->AsWeakPtr())); |
| 532 } |
| 533 |
| 510 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( | 534 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( |
| 511 int handle_id, | 535 int handle_id, |
| 512 const base::string16& message, | 536 const base::string16& message, |
| 513 const std::vector<int>& sent_message_port_ids) { | 537 const std::vector<int>& sent_message_port_ids) { |
| 514 TRACE_EVENT0("ServiceWorker", | 538 TRACE_EVENT0("ServiceWorker", |
| 515 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); | 539 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); |
| 516 if (!GetContext()) | 540 if (!GetContext()) |
| 517 return; | 541 return; |
| 518 | 542 |
| 519 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 543 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 if (!registration->is_uninstalling()) { | 934 if (!registration->is_uninstalling()) { |
| 911 GetRegistrationObjectInfoAndVersionAttributes( | 935 GetRegistrationObjectInfoAndVersionAttributes( |
| 912 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); | 936 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); |
| 913 } | 937 } |
| 914 } | 938 } |
| 915 | 939 |
| 916 Send(new ServiceWorkerMsg_DidGetRegistration( | 940 Send(new ServiceWorkerMsg_DidGetRegistration( |
| 917 thread_id, request_id, info, attrs)); | 941 thread_id, request_id, info, attrs)); |
| 918 } | 942 } |
| 919 | 943 |
| 944 void ServiceWorkerDispatcherHost::GetReadyRegistrationComplete( |
| 945 int thread_id, |
| 946 int request_id, |
| 947 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 948 ServiceWorkerRegistration* registration) { |
| 949 DCHECK(registration); |
| 950 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 951 "ServiceWorkerDispatcherHost::GetReadyRegistration", |
| 952 request_id, |
| 953 "Registration ID", |
| 954 registration ? registration->id() |
| 955 : kInvalidServiceWorkerRegistrationId); |
| 956 |
| 957 ServiceWorkerRegistrationObjectInfo info; |
| 958 ServiceWorkerVersionAttributes attrs; |
| 959 GetRegistrationObjectInfoAndVersionAttributes( |
| 960 provider_host, registration, &info, &attrs); |
| 961 Send(new ServiceWorkerMsg_DidGetReadyRegistration( |
| 962 thread_id, request_id, info, attrs)); |
| 963 } |
| 964 |
| 920 void ServiceWorkerDispatcherHost::SendRegistrationError( | 965 void ServiceWorkerDispatcherHost::SendRegistrationError( |
| 921 int thread_id, | 966 int thread_id, |
| 922 int request_id, | 967 int request_id, |
| 923 ServiceWorkerStatusCode status, | 968 ServiceWorkerStatusCode status, |
| 924 const std::string& status_message) { | 969 const std::string& status_message) { |
| 925 base::string16 error_message; | 970 base::string16 error_message; |
| 926 blink::WebServiceWorkerError::ErrorType error_type; | 971 blink::WebServiceWorkerError::ErrorType error_type; |
| 927 GetServiceWorkerRegistrationStatusResponse(status, status_message, | 972 GetServiceWorkerRegistrationStatusResponse(status, status_message, |
| 928 &error_type, &error_message); | 973 &error_type, &error_message); |
| 929 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 974 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 1013 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
| 969 if (!handle) { | 1014 if (!handle) { |
| 970 BadMessageReceived(); | 1015 BadMessageReceived(); |
| 971 return; | 1016 return; |
| 972 } | 1017 } |
| 973 handle->version()->StopWorker( | 1018 handle->version()->StopWorker( |
| 974 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1019 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 975 } | 1020 } |
| 976 | 1021 |
| 977 } // namespace content | 1022 } // namespace content |
| OLD | NEW |