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 184d1654961d9244637b7c15c64ff124d861ff40..0d006e8be07bddfad722537ee91f84372f017c19 100644 |
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
@@ -315,6 +315,20 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId( |
BadMessageReceived(); |
} |
+ServiceWorkerHandle* ServiceWorkerDispatcherHost::FindHandle(int thread_id, |
+ int64 version_id) { |
+ for (IDMap<ServiceWorkerHandle, IDMapOwnPointer>::iterator iter(&handles_); |
+ !iter.IsAtEnd(); |
+ iter.Advance()) { |
+ ServiceWorkerHandle* handle = iter.GetCurrentValue(); |
+ DCHECK(handle); |
+ if (handle->thread_id() == thread_id && handle->version() && |
+ handle->version()->version_id() == version_id) |
+ return handle; |
+ } |
+ return NULL; |
+} |
+ |
void ServiceWorkerDispatcherHost::RegistrationComplete( |
int thread_id, |
int request_id, |
@@ -332,12 +346,19 @@ void ServiceWorkerDispatcherHost::RegistrationComplete( |
ServiceWorkerVersion* version = GetContext()->GetLiveVersion(version_id); |
DCHECK(version); |
DCHECK_EQ(registration_id, version->registration_id()); |
- scoped_ptr<ServiceWorkerHandle> handle = |
- ServiceWorkerHandle::Create(GetContext()->AsWeakPtr(), |
- this, thread_id, version); |
+ ServiceWorkerObjectInfo info; |
+ ServiceWorkerHandle* handle = FindHandle(thread_id, version_id); |
+ if (handle) { |
+ info = handle->GetObjectInfo(); |
+ handle->IncrementRefCount(); |
+ } else { |
+ scoped_ptr<ServiceWorkerHandle> new_handle = ServiceWorkerHandle::Create( |
+ GetContext()->AsWeakPtr(), this, thread_id, version); |
+ info = new_handle->GetObjectInfo(); |
+ RegisterServiceWorkerHandle(new_handle.Pass()); |
+ } |
Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
- thread_id, request_id, handle->GetObjectInfo())); |
- RegisterServiceWorkerHandle(handle.Pass()); |
+ thread_id, request_id, info)); |
} |
void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(int embedded_worker_id) { |