Bug 1186810 (part 4) - Replace nsBaseHashtable::EnumerateRead() calls in dom/workers/ with iterators. r=nsm.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 25 Oct 2015 21:35:30 -0700
changeset 306365 c2a383729b77e2e542beed3676e8d3b761bc2e8e
parent 306364 280c517655d52015dd2f48ab663347c6602b6ffb
child 306366 5581cde311e019027a57faf05fc0092099bf445e
push id1040
push userraliiev@mozilla.com
push dateMon, 29 Feb 2016 17:11:22 +0000
treeherdermozilla-release@8c3167321162 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnsm
bugs1186810
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1186810 (part 4) - Replace nsBaseHashtable::EnumerateRead() calls in dom/workers/ with iterators. r=nsm.
dom/workers/ServiceWorkerManager.cpp
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -3660,52 +3660,16 @@ struct UnregisterIfMatchesUserData final
     : mRegistrationData(aRegistrationData)
     , mUserData(aUserData)
   {}
 
   ServiceWorkerManager::RegistrationDataPerPrincipal* mRegistrationData;
   void *mUserData;
 };
 
-// If host/aData is null, unconditionally unregisters.
-PLDHashOperator
-UnregisterIfMatchesHostPerPrincipal(const nsACString& aKey,
-                                    ServiceWorkerManager::RegistrationDataPerPrincipal* aData,
-                                    void* aUserData)
-{
-  UnregisterIfMatchesUserData data(aData, aUserData);
-  for (auto iter = aData->mInfos.Iter(); !iter.Done(); iter.Next()) {
-    ServiceWorkerRegistrationInfo* reg = iter.UserData();
-
-    // We avoid setting toRemove = reg by default since there is a possibility
-    // of failure when data.mUserData is passed, in which case we don't want to
-    // remove the registration.
-    ServiceWorkerRegistrationInfo* toRemove = nullptr;
-    if (data.mUserData) {
-      const nsACString& domain = *static_cast<nsACString*>(data.mUserData);
-      nsCOMPtr<nsIURI> scopeURI;
-      nsresult rv = NS_NewURI(getter_AddRefs(scopeURI), iter.Key(),
-                              nullptr, nullptr);
-      // This way subdomains are also cleared.
-      if (NS_SUCCEEDED(rv) && HasRootDomain(scopeURI, domain)) {
-        toRemove = reg;
-      }
-    } else {
-      toRemove = reg;
-    }
-
-    if (toRemove) {
-      RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
-      swm->ForceUnregister(data.mRegistrationData, toRemove);
-    }
-  }
-
-  return PL_DHASH_NEXT;
-}
-
 PLDHashOperator
 UnregisterIfMatchesClearOriginParams(const nsACString& aScope,
                                      ServiceWorkerRegistrationInfo* aReg,
                                      void* aPtr)
 {
   UnregisterIfMatchesUserData* data =
     static_cast<UnregisterIfMatchesUserData*>(aPtr);
   MOZ_ASSERT(data);
@@ -3883,17 +3847,18 @@ ServiceWorkerManager::GetAllRegistration
       array->AppendElement(info, false);
     }
   }
 
   array.forget(aResult);
   return NS_OK;
 }
 
-// MUST ONLY BE CALLED FROM UnregisterIfMatchesHostPerPrincipal()!
+// MUST ONLY BE CALLED FROM Remove(), RemoveAll() and
+// UnregisterIfMatchesClearOriginParams()!
 void
 ServiceWorkerManager::ForceUnregister(RegistrationDataPerPrincipal* aRegistrationData,
                                       ServiceWorkerRegistrationInfo* aRegistration)
 {
   MOZ_ASSERT(aRegistrationData);
   MOZ_ASSERT(aRegistration);
 
   ServiceWorkerJobQueue* queue;
@@ -3922,18 +3887,30 @@ ServiceWorkerManager::Remove(const nsACS
   // We need to postpone this operation in case we don't have an actor because
   // this is needed by the ForceUnregister.
   if (!mActor) {
     RefPtr<nsIRunnable> runnable = new RemoveRunnable(aHost);
     AppendPendingOperation(runnable);
     return;
   }
 
-  mRegistrationInfos.EnumerateRead(UnregisterIfMatchesHostPerPrincipal,
-                                   &const_cast<nsACString&>(aHost));
+  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
+  for (auto it1 = mRegistrationInfos.Iter(); !it1.Done(); it1.Next()) {
+    ServiceWorkerManager::RegistrationDataPerPrincipal* data = it1.UserData();
+    for (auto it2 = data->mInfos.Iter(); !it2.Done(); it2.Next()) {
+      ServiceWorkerRegistrationInfo* reg = it2.UserData();
+      nsCOMPtr<nsIURI> scopeURI;
+      nsresult rv = NS_NewURI(getter_AddRefs(scopeURI), it2.Key(),
+                              nullptr, nullptr);
+      // This way subdomains are also cleared.
+      if (NS_SUCCEEDED(rv) && HasRootDomain(scopeURI, aHost)) {
+        swm->ForceUnregister(data, reg);
+      }
+    }
+  }
 }
 
 void
 ServiceWorkerManager::PropagateRemove(const nsACString& aHost)
 {
   AssertIsOnMainThread();
 
   if (!mActor) {
@@ -3944,17 +3921,25 @@ ServiceWorkerManager::PropagateRemove(co
 
   mActor->SendPropagateRemove(nsCString(aHost));
 }
 
 void
 ServiceWorkerManager::RemoveAll()
 {
   AssertIsOnMainThread();
-  mRegistrationInfos.EnumerateRead(UnregisterIfMatchesHostPerPrincipal, nullptr);
+
+  RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
+  for (auto it1 = mRegistrationInfos.Iter(); !it1.Done(); it1.Next()) {
+    ServiceWorkerManager::RegistrationDataPerPrincipal* data = it1.UserData();
+    for (auto it2 = data->mInfos.Iter(); !it2.Done(); it2.Next()) {
+      ServiceWorkerRegistrationInfo* reg = it2.UserData();
+      swm->ForceUnregister(data, reg);
+    }
+  }
 }
 
 void
 ServiceWorkerManager::PropagateRemoveAll()
 {
   AssertIsOnMainThread();
   MOZ_ASSERT(XRE_IsParentProcess());