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 df616df99896a64a39dfa496acec0a2ad41e747f..f4aff93d02ebbd6f48cf447ba68c58514fd2d7c6 100644 |
| --- a/content/child/service_worker/service_worker_dispatcher.cc |
| +++ b/content/child/service_worker/service_worker_dispatcher.cc |
| @@ -61,10 +61,14 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, |
| OnUnregistered) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, |
| + OnDidGetRegistration) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
| OnRegistrationError) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, |
| OnUnregistrationError) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, |
| + OnGetRegistrationError) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, |
| OnServiceWorkerStateChanged) |
| IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, |
| @@ -135,6 +139,30 @@ void ServiceWorkerDispatcher::UnregisterServiceWorker( |
| CurrentWorkerId(), request_id, provider_id, pattern)); |
| } |
| +void ServiceWorkerDispatcher::GetRegistration( |
| + int provider_id, |
| + const GURL& document_url, |
| + WebServiceWorkerRegistrationCallbacks* callbacks) { |
| + DCHECK(callbacks); |
| + |
| + if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { |
| + scoped_ptr<WebServiceWorkerRegistrationCallbacks> |
| + owned_callbacks(callbacks); |
| + scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( |
| + WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); |
| + callbacks->onError(error.release()); |
| + return; |
| + } |
| + |
| + int request_id = pending_get_registration_callbacks_.Add(callbacks); |
| + TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| + "ServiceWorkerDispatcher::GetRegistration", |
| + request_id, |
| + "Document URL", document_url.spec()); |
| + thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( |
| + CurrentWorkerId(), request_id, provider_id, document_url)); |
| +} |
| + |
| void ServiceWorkerDispatcher::AddProviderContext( |
| ServiceWorkerProviderContext* provider_context) { |
| DCHECK(provider_context); |
| @@ -348,6 +376,41 @@ void ServiceWorkerDispatcher::OnUnregistered(int thread_id, |
| request_id); |
| } |
| +void ServiceWorkerDispatcher::OnDidGetRegistration( |
| + int thread_id, |
| + int request_id, |
| + const ServiceWorkerRegistrationObjectInfo& info, |
| + const ServiceWorkerVersionAttributes& attrs) { |
| + WebServiceWorkerRegistrationCallbacks* callbacks = |
| + pending_get_registration_callbacks_.Lookup(request_id); |
| + TRACE_EVENT_ASYNC_STEP_INTO0( |
| + "ServiceWorker", |
| + "ServiceWorkerDispatcher::GetRegistration", |
| + request_id, |
| + "OnDidGetRegistration"); |
| + DCHECK(callbacks); |
| + if (!callbacks) |
| + return; |
| + |
| + WebServiceWorkerRegistrationImpl* registration = |
| + FindServiceWorkerRegistration(info, true); |
|
Kunihiko Sakamoto
2014/09/11 04:23:52
nhiroki@: Since your patch has landed, I've rebase
nhiroki
2014/09/11 07:23:49
If a registration object hasn't been created, Find
Kunihiko Sakamoto
2014/09/11 08:48:10
Thanks for the explanation. Fixed by introducing a
|
| + if (registration) { |
| + // |registration| must already have version attributes, so adopt and destroy |
| + // handle refs for them. |
| + ServiceWorkerHandleReference::Adopt( |
| + attrs.installing, thread_safe_sender_.get()); |
| + ServiceWorkerHandleReference::Adopt( |
| + attrs.waiting, thread_safe_sender_.get()); |
| + ServiceWorkerHandleReference::Adopt( |
| + attrs.active, thread_safe_sender_.get()); |
| + } |
| + callbacks->onSuccess(registration); |
| + pending_get_registration_callbacks_.Remove(request_id); |
| + TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| + "ServiceWorkerDispatcher::GetRegistration", |
| + request_id); |
|
nhiroki
2014/09/11 07:23:50
This is also likely to be skipped due to an early
Kunihiko Sakamoto
2014/09/11 08:48:10
Since that is an exceptional case (DCHECK fails),
|
| +} |
| + |
| void ServiceWorkerDispatcher::OnRegistrationError( |
| int thread_id, |
| int request_id, |
| @@ -397,6 +460,31 @@ void ServiceWorkerDispatcher::OnUnregistrationError( |
| request_id); |
| } |
| +void ServiceWorkerDispatcher::OnGetRegistrationError( |
| + int thread_id, |
| + int request_id, |
| + WebServiceWorkerError::ErrorType error_type, |
| + const base::string16& message) { |
| + TRACE_EVENT_ASYNC_STEP_INTO0( |
| + "ServiceWorker", |
| + "ServiceWorkerDispatcher::GetRegistration", |
| + request_id, |
| + "OnGetRegistrationError"); |
| + WebServiceWorkerGetRegistrationCallbacks* callbacks = |
| + pending_get_registration_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); |
| + TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| + "ServiceWorkerDispatcher::GetRegistration", |
| + request_id); |
|
nhiroki
2014/09/11 07:23:50
ditto.
Kunihiko Sakamoto
2014/09/11 08:48:10
see the comment above.
|
| +} |
| + |
| void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( |
| int thread_id, |
| int handle_id, |