Chromium Code Reviews| Index: content/child/service_worker/service_worker_dispatcher.cc |
| diff --git a/content/child/service_worker/service_worker_dispatcher.cc b/content/child/service_worker/service_worker_dispatcher.cc |
| index dfbcfc18f6c06fb4e2e20fd6796f1fa9e81b3b64..353d59fcf1417ba2f1fdb5b5e9d07cd779ea52ce 100644 |
| --- a/content/child/service_worker/service_worker_dispatcher.cc |
| +++ b/content/child/service_worker/service_worker_dispatcher.cc |
| @@ -68,6 +68,8 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| OnUnregistered) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, |
| OnDidGetRegistration) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrations, |
| + OnDidGetRegistrations) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrationForReady, |
| OnDidGetRegistrationForReady) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
| @@ -76,6 +78,8 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| OnUnregistrationError) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, |
| OnGetRegistrationError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationsError, |
| + OnGetRegistrationsError) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, |
| OnServiceWorkerStateChanged) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, |
| @@ -179,6 +183,21 @@ void ServiceWorkerDispatcher::GetRegistration( |
| CurrentWorkerId(), request_id, provider_id, document_url)); |
| } |
| +void ServiceWorkerDispatcher::GetRegistrations( |
| + int provider_id, |
| + const GURL& document_url, |
|
kinuko
2015/05/21 07:57:06
I have a feeling that this doesn't need to be (or
jungkees
2015/05/21 13:46:25
Agreed. Correct and much simpler!
|
| + WebServiceWorkerGetRegistrationsCallbacks* callbacks) { |
| + DCHECK(callbacks); |
| + |
| + int request_id = pending_get_registrations_callbacks_.Add(callbacks); |
| + TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| + "ServiceWorkerDispatcher::GetRegistrations", |
| + request_id, |
| + "Document URL", document_url.spec()); |
| + thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrations( |
| + CurrentWorkerId(), request_id, provider_id, document_url)); |
| +} |
| + |
| void ServiceWorkerDispatcher::GetRegistrationForReady( |
| int provider_id, |
| WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { |
| @@ -416,6 +435,42 @@ void ServiceWorkerDispatcher::OnDidGetRegistration( |
| pending_get_registration_callbacks_.Remove(request_id); |
| } |
| +void ServiceWorkerDispatcher::OnDidGetRegistrations( |
| + int thread_id, |
| + int request_id, |
| + const std::vector<ServiceWorkerRegistrationObjectInfo>& infos, |
| + const std::vector<ServiceWorkerVersionAttributes>& attrs) { |
| + TRACE_EVENT_ASYNC_STEP_INTO0( |
| + "ServiceWorker", |
| + "ServiceWorkerDispatcher::GetRegistrations", |
| + request_id, |
| + "OnDidGetRegistrations"); |
| + TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| + "ServiceWorkerDispatcher::GetRegistrations", |
| + request_id); |
| + |
| + WebServiceWorkerGetRegistrationsCallbacks* callbacks = |
| + pending_get_registrations_callbacks_.Lookup(request_id); |
| + DCHECK(callbacks); |
| + if (!callbacks) |
| + return; |
| + |
| + typedef blink::WebVector<blink::WebServiceWorkerRegistration*> |
| + WebServiceWorkerRegistrationArray; |
| + scoped_ptr<WebServiceWorkerRegistrationArray> |
| + registrations(new WebServiceWorkerRegistrationArray(infos.size())); |
| + for (size_t i = 0; i < infos.size(); ++i) { |
| + if (infos[i].handle_id != kInvalidServiceWorkerHandleId) { |
| + ServiceWorkerRegistrationObjectInfo info(infos[i]); |
| + ServiceWorkerVersionAttributes attr(attrs[i]); |
| + (*registrations)[i] = FindOrCreateRegistration(info, attr); |
| + } |
| + } |
| + |
| + callbacks->onSuccess(registrations.release()); |
| + pending_get_registrations_callbacks_.Remove(request_id); |
| +} |
| + |
| void ServiceWorkerDispatcher::OnDidGetRegistrationForReady( |
| int thread_id, |
| int request_id, |
| @@ -516,6 +571,31 @@ void ServiceWorkerDispatcher::OnGetRegistrationError( |
| pending_get_registration_callbacks_.Remove(request_id); |
| } |
| +void ServiceWorkerDispatcher::OnGetRegistrationsError( |
| + int thread_id, |
| + int request_id, |
| + WebServiceWorkerError::ErrorType error_type, |
| + const base::string16& message) { |
| + TRACE_EVENT_ASYNC_STEP_INTO0( |
| + "ServiceWorker", |
| + "ServiceWorkerDispatcher::GetRegistrations", |
| + request_id, |
| + "OnGetRegistrationsError"); |
| + TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| + "ServiceWorkerDispatcher::GetRegistrations", |
| + request_id); |
| + WebServiceWorkerGetRegistrationsCallbacks* callbacks = |
| + pending_get_registrations_callbacks_.Lookup(request_id); |
| + DCHECK(callbacks); |
| + if (!callbacks) |
| + return; |
| + |
| + scoped_ptr<WebServiceWorkerError> error( |
| + new WebServiceWorkerError(error_type, message)); |
| + callbacks->onError(error.release()); |
| + pending_get_registration_callbacks_.Remove(request_id); |
| +} |
| + |
| void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( |
| int thread_id, |
| int handle_id, |