Chromium Code Reviews| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 bool ServiceWorkerDispatcherHost::OnMessageReceived( | 154 bool ServiceWorkerDispatcherHost::OnMessageReceived( |
| 155 const IPC::Message& message) { | 155 const IPC::Message& message) { |
| 156 bool handled = true; | 156 bool handled = true; |
| 157 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) | 157 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) |
| 158 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, | 158 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, |
| 159 OnRegisterServiceWorker) | 159 OnRegisterServiceWorker) |
| 160 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, | 160 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, |
| 161 OnUnregisterServiceWorker) | 161 OnUnregisterServiceWorker) |
| 162 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, | 162 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, |
| 163 OnGetRegistration) | 163 OnGetRegistration) |
| 164 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady, | |
| 165 OnGetRegistrationForReady) | |
| 164 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, | 166 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, |
| 165 OnProviderCreated) | 167 OnProviderCreated) |
| 166 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, | 168 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, |
| 167 OnProviderDestroyed) | 169 OnProviderDestroyed) |
| 168 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, | 170 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, |
| 169 OnSetHostedVersionId) | 171 OnSetHostedVersionId) |
| 170 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker, | 172 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker, |
| 171 OnPostMessageToWorker) | 173 OnPostMessageToWorker) |
| 172 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerReadyForInspection, | 174 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerReadyForInspection, |
| 173 OnWorkerReadyForInspection) | 175 OnWorkerReadyForInspection) |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 | 485 |
| 484 GetContext()->storage()->FindRegistrationForDocument( | 486 GetContext()->storage()->FindRegistrationForDocument( |
| 485 document_url, | 487 document_url, |
| 486 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, | 488 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, |
| 487 this, | 489 this, |
| 488 thread_id, | 490 thread_id, |
| 489 provider_id, | 491 provider_id, |
| 490 request_id)); | 492 request_id)); |
| 491 } | 493 } |
| 492 | 494 |
| 495 void ServiceWorkerDispatcherHost::OnGetRegistrationForReady( | |
| 496 int thread_id, | |
| 497 int request_id, | |
| 498 int provider_id) { | |
| 499 TRACE_EVENT0("ServiceWorker", | |
| 500 "ServiceWorkerDispatcherHost::OnGetRegistrationForReady"); | |
| 501 if (!GetContext()) | |
| 502 return; | |
| 503 ServiceWorkerProviderHost* provider_host = | |
| 504 GetContext()->GetProviderHost(render_process_id_, provider_id); | |
| 505 if (!provider_host || !provider_host->IsContextAlive()) | |
| 506 return; | |
| 507 | |
| 508 TRACE_EVENT_ASYNC_BEGIN0( | |
| 509 "ServiceWorker", | |
| 510 "ServiceWorkerDispatcherHost::GetRegistrationForReady", | |
| 511 request_id); | |
| 512 | |
| 513 provider_host->GetRegistrationForReady( | |
|
falken
2015/02/16 09:18:29
GetRegistrationForReady does a DCHECK that it hasn
xiang
2015/02/26 06:52:14
Done. I put it into GetRegistrationForReadyComplet
| |
| 514 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete, | |
| 515 this, thread_id, request_id, provider_host->AsWeakPtr())); | |
| 516 } | |
| 517 | |
| 493 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( | 518 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( |
| 494 int handle_id, | 519 int handle_id, |
| 495 const base::string16& message, | 520 const base::string16& message, |
| 496 const std::vector<int>& sent_message_port_ids) { | 521 const std::vector<int>& sent_message_port_ids) { |
| 497 TRACE_EVENT0("ServiceWorker", | 522 TRACE_EVENT0("ServiceWorker", |
| 498 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); | 523 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); |
| 499 if (!GetContext()) | 524 if (!GetContext()) |
| 500 return; | 525 return; |
| 501 | 526 |
| 502 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 527 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 893 if (!registration->is_uninstalling()) { | 918 if (!registration->is_uninstalling()) { |
| 894 GetRegistrationObjectInfoAndVersionAttributes( | 919 GetRegistrationObjectInfoAndVersionAttributes( |
| 895 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); | 920 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); |
| 896 } | 921 } |
| 897 } | 922 } |
| 898 | 923 |
| 899 Send(new ServiceWorkerMsg_DidGetRegistration( | 924 Send(new ServiceWorkerMsg_DidGetRegistration( |
| 900 thread_id, request_id, info, attrs)); | 925 thread_id, request_id, info, attrs)); |
| 901 } | 926 } |
| 902 | 927 |
| 928 void ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete( | |
| 929 int thread_id, | |
| 930 int request_id, | |
| 931 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | |
| 932 ServiceWorkerRegistration* registration) { | |
| 933 DCHECK(registration); | |
| 934 TRACE_EVENT_ASYNC_END1("ServiceWorker", | |
| 935 "ServiceWorkerDispatcherHost::GetRegistrationForReady", | |
| 936 request_id, | |
| 937 "Registration ID", | |
| 938 registration ? registration->id() | |
| 939 : kInvalidServiceWorkerRegistrationId); | |
| 940 | |
| 941 ServiceWorkerRegistrationObjectInfo info; | |
| 942 ServiceWorkerVersionAttributes attrs; | |
| 943 GetRegistrationObjectInfoAndVersionAttributes( | |
| 944 provider_host, registration, &info, &attrs); | |
| 945 Send(new ServiceWorkerMsg_DidGetRegistrationForReady( | |
| 946 thread_id, request_id, info, attrs)); | |
| 947 } | |
| 948 | |
| 903 void ServiceWorkerDispatcherHost::SendRegistrationError( | 949 void ServiceWorkerDispatcherHost::SendRegistrationError( |
| 904 int thread_id, | 950 int thread_id, |
| 905 int request_id, | 951 int request_id, |
| 906 ServiceWorkerStatusCode status, | 952 ServiceWorkerStatusCode status, |
| 907 const std::string& status_message) { | 953 const std::string& status_message) { |
| 908 base::string16 error_message; | 954 base::string16 error_message; |
| 909 blink::WebServiceWorkerError::ErrorType error_type; | 955 blink::WebServiceWorkerError::ErrorType error_type; |
| 910 GetServiceWorkerRegistrationStatusResponse(status, status_message, | 956 GetServiceWorkerRegistrationStatusResponse(status, status_message, |
| 911 &error_type, &error_message); | 957 &error_type, &error_message); |
| 912 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 958 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 997 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
| 952 if (!handle) { | 998 if (!handle) { |
| 953 BadMessageReceived(); | 999 BadMessageReceived(); |
| 954 return; | 1000 return; |
| 955 } | 1001 } |
| 956 handle->version()->StopWorker( | 1002 handle->version()->StopWorker( |
| 957 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1003 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 958 } | 1004 } |
| 959 | 1005 |
| 960 } // namespace content | 1006 } // namespace content |
| OLD | NEW |