Bug 1182977 - Use PLDHashTable::Iterator in dom/storage/. r=khuey.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 21 Jul 2015 23:54:12 -0700
changeset 254127 cef50aeb685eed7fb0f5b20cd2f3dac68a616f71
parent 254081 236004185e7f1c24a10900bf32d2e6c4024b54a4
child 254128 076402b442958313e39b3e0c67cc01e42ee6e864
push id29090
push userryanvm@gmail.com
push dateWed, 22 Jul 2015 20:34:12 +0000
treeherdermozilla-central@8650fe82f1cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1182977
milestone42.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 1182977 - Use PLDHashTable::Iterator in dom/storage/. r=khuey.
dom/storage/DOMStorageManager.cpp
dom/storage/DOMStorageManager.h
--- a/dom/storage/DOMStorageManager.cpp
+++ b/dom/storage/DOMStorageManager.cpp
@@ -467,105 +467,74 @@ DOMStorageManager::GetLocalStorageForPri
 {
   if (mType != LocalStorage) {
     return NS_ERROR_UNEXPECTED;
   }
 
   return CreateStorage(nullptr, aPrincipal, aDocumentURI, aPrivate, aRetval);
 }
 
-namespace {
-
-class ClearCacheEnumeratorData
+void
+DOMStorageManager::ClearCaches(uint32_t aUnloadFlags,
+                               const nsACString& aKeyPrefix)
 {
-public:
-  explicit ClearCacheEnumeratorData(uint32_t aFlags)
-    : mUnloadFlags(aFlags)
-  {}
-
-  uint32_t mUnloadFlags;
-  nsCString mKeyPrefix;
-};
+  for (auto iter = mCaches.Iter(); !iter.Done(); iter.Next()) {
+    DOMStorageCache* cache = iter.Get()->cache();
+    nsCString& key = const_cast<nsCString&>(cache->Scope());
 
-} // namespace
-
-PLDHashOperator
-DOMStorageManager::ClearCacheEnumerator(DOMStorageCacheHashKey* aEntry, void* aClosure)
-{
-  DOMStorageCache* cache = aEntry->cache();
-  nsCString& key = const_cast<nsCString&>(cache->Scope());
-
-  ClearCacheEnumeratorData* data = static_cast<ClearCacheEnumeratorData*>(aClosure);
-
-  if (data->mKeyPrefix.IsEmpty() || StringBeginsWith(key, data->mKeyPrefix)) {
-    cache->UnloadItems(data->mUnloadFlags);
+    if (aKeyPrefix.IsEmpty() || StringBeginsWith(key, aKeyPrefix)) {
+      cache->UnloadItems(aUnloadFlags);
+    }
   }
-
-  return PL_DHASH_NEXT;
 }
 
 nsresult
 DOMStorageManager::Observe(const char* aTopic, const nsACString& aScopePrefix)
 {
   // Clear everything, caches + database
   if (!strcmp(aTopic, "cookie-cleared")) {
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadComplete);
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadComplete, EmptyCString());
     return NS_OK;
   }
 
   // Clear from caches everything that has been stored
   // while in session-only mode
   if (!strcmp(aTopic, "session-only-cleared")) {
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadSession);
-    data.mKeyPrefix = aScopePrefix;
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadSession, aScopePrefix);
     return NS_OK;
   }
 
   // Clear everything (including so and pb data) from caches and database
   // for the gived domain and subdomains.
   if (!strcmp(aTopic, "domain-data-cleared")) {
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadComplete);
-    data.mKeyPrefix = aScopePrefix;
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadComplete, aScopePrefix);
     return NS_OK;
   }
 
   // Clear all private-browsing caches
   if (!strcmp(aTopic, "private-browsing-data-cleared")) {
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadPrivate);
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadPrivate, EmptyCString());
     return NS_OK;
   }
 
   // Clear localStorage data beloging to an app.
   if (!strcmp(aTopic, "app-data-cleared")) {
 
     // sessionStorage is expected to stay
     if (mType == SessionStorage) {
       return NS_OK;
     }
 
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadComplete);
-    data.mKeyPrefix = aScopePrefix;
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadComplete, aScopePrefix);
     return NS_OK;
   }
 
   if (!strcmp(aTopic, "profile-change")) {
     // For case caches are still referenced - clear them completely
-    ClearCacheEnumeratorData data(DOMStorageCache::kUnloadComplete);
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
-
+    ClearCaches(DOMStorageCache::kUnloadComplete, EmptyCString());
     mCaches.Clear();
     return NS_OK;
   }
 
   if (!strcmp(aTopic, "low-disk-space")) {
     if (mType == LocalStorage) {
       mLowDiskSpace = true;
     }
@@ -583,18 +552,17 @@ DOMStorageManager::Observe(const char* a
 
 #ifdef DOM_STORAGE_TESTS
   if (!strcmp(aTopic, "test-reload")) {
     if (mType != LocalStorage) {
       return NS_OK;
     }
 
     // This immediately completely reloads all caches from the database.
-    ClearCacheEnumeratorData data(DOMStorageCache::kTestReload);
-    mCaches.EnumerateEntries(ClearCacheEnumerator, &data);
+    ClearCaches(DOMStorageCache::kTestReload, EmptyCString());
     return NS_OK;
   }
 
   if (!strcmp(aTopic, "test-flushed")) {
     if (!XRE_IsParentProcess()) {
       nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
       if (obs) {
         obs->NotifyObservers(nullptr, "domstorage-test-flushed", nullptr);
--- a/dom/storage/DOMStorageManager.h
+++ b/dom/storage/DOMStorageManager.h
@@ -94,18 +94,17 @@ private:
   const DOMStorage::StorageType mType;
 
   // If mLowDiskSpace is true it indicates a low device storage situation and
   // so no localStorage writes are allowed. sessionStorage writes are still
   // allowed.
   bool mLowDiskSpace;
   bool IsLowDiskSpace() const { return mLowDiskSpace; };
 
-  static PLDHashOperator ClearCacheEnumerator(DOMStorageCacheHashKey* aCache,
-                                              void* aClosure);
+  void ClearCaches(uint32_t aUnloadFlags, const nsACString& aKeyPrefix);
 
 protected:
   // Keeps usage cache objects for eTLD+1 scopes we have touched.
   nsDataHashtable<nsCStringHashKey, nsRefPtr<DOMStorageUsage> > mUsages;
 
   friend class DOMStorageCache;
   // Releases cache since it is no longer referrered by any DOMStorage object.
   virtual void DropCache(DOMStorageCache* aCache);