Bug 803438 - Convert nsPreflightCache and nsPreflightCache::CacheEntry to use mozilla::LinkedList and mozilla::LinkedListElement instead of prclist.h. r=jlebar
authorJeff Walden <jwalden@mit.edu>
Thu, 18 Oct 2012 20:41:13 -0700
changeset 110930 499ca9ee03bca43676218bbf5dba8e55f100a362
parent 110929 d5e23f4018c67d62d9c393544fae0c6f8e7c5f8b
child 110931 8559d650b22dd3f3253b767248dbde5e691f6d48
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersjlebar
bugs803438
milestone19.0a1
Bug 803438 - Convert nsPreflightCache and nsPreflightCache::CacheEntry to use mozilla::LinkedList and mozilla::LinkedListElement instead of prclist.h. r=jlebar
content/base/src/nsCrossSiteListenerProxy.cpp
--- a/content/base/src/nsCrossSiteListenerProxy.cpp
+++ b/content/base/src/nsCrossSiteListenerProxy.cpp
@@ -1,30 +1,32 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/Assertions.h"
+#include "mozilla/LinkedList.h"
+
 #include "nsCrossSiteListenerProxy.h"
 #include "nsIChannel.h"
 #include "nsIHttpChannel.h"
 #include "nsError.h"
 #include "nsContentUtils.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsNetUtil.h"
 #include "nsMimeTypes.h"
 #include "nsIStreamConverterService.h"
 #include "nsStringStream.h"
 #include "nsGkAtoms.h"
 #include "nsWhitespaceTokenizer.h"
 #include "nsIChannelEventSink.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsAsyncRedirectVerifyHelper.h"
-#include "prclist.h"
 #include "prtime.h"
 #include "nsClassHashtable.h"
 #include "nsHashKeys.h"
 #include "nsStreamUtils.h"
 #include "mozilla/Preferences.h"
 
 using namespace mozilla;
 
@@ -40,17 +42,17 @@ class nsPreflightCache
 {
 public:
   struct TokenTime
   {
     nsCString token;
     PRTime expirationTime;
   };
 
-  struct CacheEntry : public PRCList
+  struct CacheEntry : public LinkedListElement<CacheEntry>
   {
     CacheEntry(nsCString& aKey)
       : mKey(aKey)
     {
       MOZ_COUNT_CTOR(nsPreflightCache::CacheEntry);
     }
     
     ~CacheEntry()
@@ -65,17 +67,16 @@ public:
     nsCString mKey;
     nsTArray<TokenTime> mMethods;
     nsTArray<TokenTime> mHeaders;
   };
 
   nsPreflightCache()
   {
     MOZ_COUNT_CTOR(nsPreflightCache);
-    PR_INIT_CLIST(&mList);
   }
 
   ~nsPreflightCache()
   {
     Clear();
     MOZ_COUNT_DTOR(nsPreflightCache);
   }
 
@@ -95,17 +96,17 @@ private:
   static PLDHashOperator
     RemoveExpiredEntries(const nsACString& aKey, nsAutoPtr<CacheEntry>& aValue,
                          void* aUserData);
 
   static bool GetCacheKey(nsIURI* aURI, nsIPrincipal* aPrincipal,
                             bool aWithCredentials, nsACString& _retval);
 
   nsClassHashtable<nsCStringHashKey, CacheEntry> mTable;
-  PRCList mList;
+  LinkedList<CacheEntry> mList;
 };
 
 // Will be initialized in EnsurePreflightCache.
 static nsPreflightCache* sPreflightCache = nullptr;
 
 static bool EnsurePreflightCache()
 {
   if (sPreflightCache)
@@ -183,18 +184,18 @@ nsPreflightCache::GetEntry(nsIURI* aURI,
   }
 
   CacheEntry* entry;
 
   if (mTable.Get(key, &entry)) {
     // Entry already existed so just return it. Also update the LRU list.
 
     // Move to the head of the list.
-    PR_REMOVE_LINK(entry);
-    PR_INSERT_LINK(entry, &mList);
+    entry->remove();
+    mList.insertFront(entry);
 
     return entry;
   }
 
   if (!aCreate) {
     return nullptr;
   }
 
@@ -213,71 +214,71 @@ nsPreflightCache::GetEntry(nsIURI* aURI,
   if (mTable.Count() == PREFLIGHT_CACHE_SIZE) {
     // Try to kick out all the expired entries.
     PRTime now = PR_Now();
     mTable.Enumerate(RemoveExpiredEntries, &now);
 
     // If that didn't remove anything then kick out the least recently used
     // entry.
     if (mTable.Count() == PREFLIGHT_CACHE_SIZE) {
-      CacheEntry* lruEntry = static_cast<CacheEntry*>(PR_LIST_TAIL(&mList));
-      PR_REMOVE_LINK(lruEntry);
+      CacheEntry* lruEntry = static_cast<CacheEntry*>(mList.popLast());
+      MOZ_ASSERT(lruEntry);
 
       // This will delete 'lruEntry'.
       mTable.Remove(lruEntry->mKey);
 
       NS_ASSERTION(mTable.Count() == PREFLIGHT_CACHE_SIZE - 1,
                    "Somehow tried to remove an entry that was never added!");
     }
   }
   
   mTable.Put(key, entry);
-  PR_INSERT_LINK(entry, &mList);
+  mList.insertFront(entry);
 
   return entry;
 }
 
 void
 nsPreflightCache::RemoveEntries(nsIURI* aURI, nsIPrincipal* aPrincipal)
 {
   CacheEntry* entry;
   nsCString key;
   if (GetCacheKey(aURI, aPrincipal, true, key) &&
       mTable.Get(key, &entry)) {
-    PR_REMOVE_LINK(entry);
+    entry->remove();
     mTable.Remove(key);
   }
 
   if (GetCacheKey(aURI, aPrincipal, false, key) &&
       mTable.Get(key, &entry)) {
-    PR_REMOVE_LINK(entry);
+    entry->remove();
     mTable.Remove(key);
   }
 }
 
 void
 nsPreflightCache::Clear()
 {
-  PR_INIT_CLIST(&mList);
+  mList.clear();
   mTable.Clear();
 }
 
 /* static */ PLDHashOperator
 nsPreflightCache::RemoveExpiredEntries(const nsACString& aKey,
                                            nsAutoPtr<CacheEntry>& aValue,
                                            void* aUserData)
 {
   PRTime* now = static_cast<PRTime*>(aUserData);
   
   aValue->PurgeExpired(*now);
   
   if (aValue->mHeaders.IsEmpty() &&
       aValue->mMethods.IsEmpty()) {
     // Expired, remove from the list as well as the hash table.
-    PR_REMOVE_LINK(aValue);
+    aValue->remove();
     return PL_DHASH_REMOVE;
   }
   
   return PL_DHASH_NEXT;
 }
 
 /* static */ bool
 nsPreflightCache::GetCacheKey(nsIURI* aURI,