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 || !provider_host->IsContextAlive()) { | |
508 BadMessageReceived(); | |
falken
2015/03/02 02:09:40
It seems possible for IsContextAlive to be false h
xiang
2015/03/03 08:56:03
Done.
| |
509 return; | |
510 } | |
511 | |
512 TRACE_EVENT_ASYNC_BEGIN0( | |
513 "ServiceWorker", | |
514 "ServiceWorkerDispatcherHost::GetRegistrationForReady", | |
515 request_id); | |
516 | |
517 if (!provider_host->GetRegistrationForReady(base::Bind( | |
518 &ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete, | |
519 this, thread_id, request_id, provider_host->AsWeakPtr()))) { | |
520 BadMessageReceived(); | |
521 } | |
522 } | |
523 | |
495 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( | 524 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( |
496 int handle_id, | 525 int handle_id, |
497 const base::string16& message, | 526 const base::string16& message, |
498 const std::vector<int>& sent_message_port_ids) { | 527 const std::vector<int>& sent_message_port_ids) { |
499 TRACE_EVENT0("ServiceWorker", | 528 TRACE_EVENT0("ServiceWorker", |
500 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); | 529 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); |
501 if (!GetContext()) | 530 if (!GetContext()) |
502 return; | 531 return; |
503 | 532 |
504 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 533 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 if (!registration->is_uninstalling()) { | 927 if (!registration->is_uninstalling()) { |
899 GetRegistrationObjectInfoAndVersionAttributes( | 928 GetRegistrationObjectInfoAndVersionAttributes( |
900 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); | 929 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); |
901 } | 930 } |
902 } | 931 } |
903 | 932 |
904 Send(new ServiceWorkerMsg_DidGetRegistration( | 933 Send(new ServiceWorkerMsg_DidGetRegistration( |
905 thread_id, request_id, info, attrs)); | 934 thread_id, request_id, info, attrs)); |
906 } | 935 } |
907 | 936 |
937 void ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete( | |
938 int thread_id, | |
939 int request_id, | |
940 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | |
941 ServiceWorkerRegistration* registration) { | |
942 DCHECK(registration); | |
943 TRACE_EVENT_ASYNC_END1("ServiceWorker", | |
944 "ServiceWorkerDispatcherHost::GetRegistrationForReady", | |
945 request_id, | |
946 "Registration ID", | |
947 registration ? registration->id() | |
948 : kInvalidServiceWorkerRegistrationId); | |
949 | |
950 if (!GetContext()) | |
951 return; | |
952 | |
953 ServiceWorkerRegistrationObjectInfo info; | |
954 ServiceWorkerVersionAttributes attrs; | |
955 GetRegistrationObjectInfoAndVersionAttributes( | |
956 provider_host, registration, &info, &attrs); | |
957 Send(new ServiceWorkerMsg_DidGetRegistrationForReady( | |
958 thread_id, request_id, info, attrs)); | |
959 } | |
960 | |
908 void ServiceWorkerDispatcherHost::SendRegistrationError( | 961 void ServiceWorkerDispatcherHost::SendRegistrationError( |
909 int thread_id, | 962 int thread_id, |
910 int request_id, | 963 int request_id, |
911 ServiceWorkerStatusCode status, | 964 ServiceWorkerStatusCode status, |
912 const std::string& status_message) { | 965 const std::string& status_message) { |
913 base::string16 error_message; | 966 base::string16 error_message; |
914 blink::WebServiceWorkerError::ErrorType error_type; | 967 blink::WebServiceWorkerError::ErrorType error_type; |
915 GetServiceWorkerRegistrationStatusResponse(status, status_message, | 968 GetServiceWorkerRegistrationStatusResponse(status, status_message, |
916 &error_type, &error_message); | 969 &error_type, &error_message); |
917 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 970 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 1009 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
957 if (!handle) { | 1010 if (!handle) { |
958 BadMessageReceived(); | 1011 BadMessageReceived(); |
959 return; | 1012 return; |
960 } | 1013 } |
961 handle->version()->StopWorker( | 1014 handle->version()->StopWorker( |
962 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1015 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
963 } | 1016 } |
964 | 1017 |
965 } // namespace content | 1018 } // namespace content |
OLD | NEW |