Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6587)

Unified Diff: content/browser/service_worker/service_worker_dispatcher_host.cc

Issue 412833002: Ensure JavaScript equality when serviceWorker.register resolves to an existing worker [2/3] (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comment Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698