Chromium Code Reviews| Index: content/browser/service_worker/service_worker_dispatcher_host.cc |
| diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc |
| index d1ae0609bdd60ac2615626ea69c73c2a60a7ca32..5ecb0d0794a2da6e397c74fff699e02dc0ccb50c 100644 |
| --- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
| +++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
| @@ -215,12 +215,25 @@ bool ServiceWorkerDispatcherHost::Send(IPC::Message* message) { |
| return true; |
| } |
| +void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle( |
| + scoped_ptr<ServiceWorkerHandle> handle) { |
| + int handle_id = handle->handle_id(); |
| + handles_.AddWithID(handle.release(), handle_id); |
| +} |
| + |
| +void ServiceWorkerDispatcherHost::RegisterServiceWorkerRegistrationHandle( |
| + scoped_ptr<ServiceWorkerRegistrationHandle> handle) { |
| + int handle_id = handle->handle_id(); |
| + registration_handles_.AddWithID(handle.release(), handle_id); |
| +} |
| + |
| ServiceWorkerRegistrationHandle* |
| ServiceWorkerDispatcherHost::GetOrCreateRegistrationHandle( |
| - int provider_id, |
| + base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| ServiceWorkerRegistration* registration) { |
| + DCHECK(provider_host); |
| ServiceWorkerRegistrationHandle* handle = |
| - FindRegistrationHandle(provider_id, registration->id()); |
| + FindRegistrationHandle(provider_host->provider_id(), registration->id()); |
| if (handle) { |
| handle->IncrementRefCount(); |
| return handle; |
| @@ -228,25 +241,12 @@ ServiceWorkerDispatcherHost::GetOrCreateRegistrationHandle( |
| scoped_ptr<ServiceWorkerRegistrationHandle> new_handle( |
| new ServiceWorkerRegistrationHandle( |
| - GetContext()->AsWeakPtr(), this, provider_id, registration)); |
| + GetContext()->AsWeakPtr(), provider_host, registration)); |
| handle = new_handle.get(); |
| RegisterServiceWorkerRegistrationHandle(new_handle.Pass()); |
| return handle; |
| } |
| -ServiceWorkerObjectInfo |
| -ServiceWorkerDispatcherHost::CreateAndRegisterServiceWorkerHandle( |
| - ServiceWorkerVersion* version) { |
| - ServiceWorkerObjectInfo info; |
| - if (GetContext() && version) { |
| - scoped_ptr<ServiceWorkerHandle> handle = |
| - ServiceWorkerHandle::Create(GetContext()->AsWeakPtr(), this, version); |
| - info = handle->GetObjectInfo(); |
| - RegisterServiceWorkerHandle(handle.Pass()); |
| - } |
| - return info; |
| -} |
| - |
| void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
| int thread_id, |
| int request_id, |
| @@ -572,20 +572,23 @@ ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, |
| } |
| void ServiceWorkerDispatcherHost::GetRegistrationObjectInfoAndVersionAttributes( |
| - int provider_id, |
| + base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| ServiceWorkerRegistration* registration, |
| ServiceWorkerRegistrationObjectInfo* info, |
| ServiceWorkerVersionAttributes* attrs) { |
| ServiceWorkerRegistrationHandle* handle = |
| - GetOrCreateRegistrationHandle(provider_id, registration); |
| + GetOrCreateRegistrationHandle(provider_host, registration); |
| *info = handle->GetObjectInfo(); |
| - attrs->installing = CreateAndRegisterServiceWorkerHandle( |
| - registration->installing_version()); |
| - attrs->waiting = CreateAndRegisterServiceWorkerHandle( |
| - registration->waiting_version()); |
| - attrs->active = CreateAndRegisterServiceWorkerHandle( |
| - registration->active_version()); |
| + attrs->installing = |
| + provider_host->CreateAndRegisterServiceWorkerHandle( |
| + registration->installing_version()); |
| + attrs->waiting = |
| + provider_host->CreateAndRegisterServiceWorkerHandle( |
| + registration->waiting_version()); |
| + attrs->active = |
| + provider_host->CreateAndRegisterServiceWorkerHandle( |
| + registration->active_version()); |
| } |
| void ServiceWorkerDispatcherHost::RegistrationComplete( |
| @@ -598,6 +601,18 @@ void ServiceWorkerDispatcherHost::RegistrationComplete( |
| if (!GetContext()) |
| return; |
| + ServiceWorkerProviderHost* provider_host = |
| + GetContext()->GetProviderHost(render_process_id_, provider_id); |
| + if (!provider_host) |
| + return; // The provider has already been destroyed. |
| + if (!provider_host->IsContextAlive()) { |
| + Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| + thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort, |
| + base::ASCIIToUTF16(kServiceWorkerRegisterErrorPrefix) + |
| + base::ASCIIToUTF16(kShutdownErrorMessage))); |
|
kinuko
2015/01/21 10:11:00
Why do you add this error message? (It doesn't loo
nhiroki
2015/01/22 03:34:14
|provider_host->IsContextAlive()| may return false
nhiroki
2015/01/22 04:12:50
If |DeleteAndStartOver()| happens between OnRegist
nhiroki
2015/01/22 04:33:42
Done.
|
| + return; |
| + } |
| + |
| if (status != SERVICE_WORKER_OK) { |
| SendRegistrationError(thread_id, request_id, status, status_message); |
| return; |
| @@ -610,7 +625,7 @@ void ServiceWorkerDispatcherHost::RegistrationComplete( |
| ServiceWorkerRegistrationObjectInfo info; |
| ServiceWorkerVersionAttributes attrs; |
| GetRegistrationObjectInfoAndVersionAttributes( |
| - provider_id, registration, &info, &attrs); |
| + provider_host->AsWeakPtr(), registration, &info, &attrs); |
| Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
| thread_id, request_id, info, attrs)); |
| @@ -832,6 +847,18 @@ void ServiceWorkerDispatcherHost::GetRegistrationComplete( |
| if (!GetContext()) |
| return; |
| + ServiceWorkerProviderHost* provider_host = |
| + GetContext()->GetProviderHost(render_process_id_, provider_id); |
| + if (!provider_host) |
| + return; // The provider has already been destroyed. |
| + if (!provider_host->IsContextAlive()) { |
| + Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
| + thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort, |
| + base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + |
| + base::ASCIIToUTF16(kShutdownErrorMessage))); |
| + return; |
| + } |
| + |
| if (status != SERVICE_WORKER_OK && status != SERVICE_WORKER_ERROR_NOT_FOUND) { |
| SendGetRegistrationError(thread_id, request_id, status); |
| return; |
| @@ -843,7 +870,7 @@ void ServiceWorkerDispatcherHost::GetRegistrationComplete( |
| DCHECK(registration.get()); |
| if (!registration->is_uninstalling()) { |
| GetRegistrationObjectInfoAndVersionAttributes( |
| - provider_id, registration.get(), &info, &attrs); |
| + provider_host->AsWeakPtr(), registration.get(), &info, &attrs); |
| } |
| } |
| @@ -908,16 +935,4 @@ void ServiceWorkerDispatcherHost::OnTerminateWorker(int handle_id) { |
| base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| } |
| -void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle( |
| - scoped_ptr<ServiceWorkerHandle> handle) { |
| - int handle_id = handle->handle_id(); |
| - handles_.AddWithID(handle.release(), handle_id); |
| -} |
| - |
| -void ServiceWorkerDispatcherHost::RegisterServiceWorkerRegistrationHandle( |
| - scoped_ptr<ServiceWorkerRegistrationHandle> handle) { |
| - int handle_id = handle->handle_id(); |
| - registration_handles_.AddWithID(handle.release(), handle_id); |
| -} |
| - |
| } // namespace content |