diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index cf36d775eb33..a5a60d668db2 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -1580,6 +1580,28 @@ RuntimeService::RegisterWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate) return true; } +void +RuntimeService::RemoveSharedWorker(WorkerDomainInfo* aDomainInfo, + WorkerPrivate* aWorkerPrivate) +{ + for (auto iter = aDomainInfo->mSharedWorkerInfos.Iter(); + !iter.Done(); + iter.Next()) { + SharedWorkerInfo* data = iter.UserData(); + if (data->mWorkerPrivate == aWorkerPrivate) { +#ifdef DEBUG + fprintf(stderr, "njn: RemoveSharedWorker\n"); + nsAutoCString key; + GenerateSharedWorkerKey(data->mScriptSpec, data->mName, + aWorkerPrivate->IsInPrivateBrowsing(), key); + MOZ_ASSERT(iter.Key() == key); +#endif + iter.Remove(); + break; + } + } +} + void RuntimeService::UnregisterWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate) { @@ -1622,19 +1644,8 @@ RuntimeService::UnregisterWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate) domainInfo->mActiveWorkers.RemoveElement(aWorkerPrivate); } - if (aWorkerPrivate->IsSharedWorker()) { - MatchSharedWorkerInfo match(aWorkerPrivate); - domainInfo->mSharedWorkerInfos.EnumerateRead(FindSharedWorkerInfo, - &match); - - if (match.mSharedWorkerInfo) { - nsAutoCString key; - GenerateSharedWorkerKey(match.mSharedWorkerInfo->mScriptSpec, - match.mSharedWorkerInfo->mName, - aWorkerPrivate->IsInPrivateBrowsing(), key); - domainInfo->mSharedWorkerInfos.Remove(key); - } + RemoveSharedWorker(domainInfo, aWorkerPrivate); } // See if there's a queued worker we can schedule. @@ -2178,22 +2189,6 @@ RuntimeService::RemoveSharedWorkerFromWindowMap( return PL_DHASH_NEXT; } -// static -PLDHashOperator -RuntimeService::FindSharedWorkerInfo(const nsACString& aKey, - SharedWorkerInfo* aData, - void* aUserArg) -{ - auto match = static_cast(aUserArg); - - if (aData->mWorkerPrivate == match->mWorkerPrivate) { - match->mSharedWorkerInfo = aData; - return PL_DHASH_STOP; - } - - return PL_DHASH_NEXT; -} - void RuntimeService::GetWorkersForWindow(nsPIDOMWindow* aWindow, nsTArray& aWorkers) @@ -2437,17 +2432,7 @@ RuntimeService::ForgetSharedWorker(WorkerPrivate* aWorkerPrivate) WorkerDomainInfo* domainInfo; if (mDomainMap.Get(aWorkerPrivate->Domain(), &domainInfo)) { - MatchSharedWorkerInfo match(aWorkerPrivate); - domainInfo->mSharedWorkerInfos.EnumerateRead(FindSharedWorkerInfo, - &match); - - if (match.mSharedWorkerInfo) { - nsAutoCString key; - GenerateSharedWorkerKey(match.mSharedWorkerInfo->mScriptSpec, - match.mSharedWorkerInfo->mName, - aWorkerPrivate->IsInPrivateBrowsing(), key); - domainInfo->mSharedWorkerInfos.Remove(key); - } + RemoveSharedWorker(domainInfo, aWorkerPrivate); } } diff --git a/dom/workers/RuntimeService.h b/dom/workers/RuntimeService.h index 8f7b226bc83b..350e2851558c 100644 --- a/dom/workers/RuntimeService.h +++ b/dom/workers/RuntimeService.h @@ -75,16 +75,6 @@ class RuntimeService final : public nsIObserver struct IdleThreadInfo; - struct MatchSharedWorkerInfo - { - WorkerPrivate* mWorkerPrivate; - SharedWorkerInfo* mSharedWorkerInfo; - - explicit MatchSharedWorkerInfo(WorkerPrivate* aWorkerPrivate) - : mWorkerPrivate(aWorkerPrivate), mSharedWorkerInfo(nullptr) - { } - }; - mozilla::Mutex mMutex; // Protected by mMutex. @@ -139,6 +129,10 @@ public: void UnregisterWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate); + void + RemoveSharedWorker(WorkerDomainInfo* aDomainInfo, + WorkerPrivate* aWorkerPrivate); + void CancelWorkersForWindow(nsPIDOMWindow* aWindow); @@ -278,11 +272,6 @@ private: nsAutoPtr >& aData, void* aUserArg); - static PLDHashOperator - FindSharedWorkerInfo(const nsACString& aKey, - SharedWorkerInfo* aData, - void* aUserArg); - void GetWorkersForWindow(nsPIDOMWindow* aWindow, nsTArray& aWorkers);