Bug 450174: Remove static nsCAutoString usage from nsDOMOfflineResourceList. r+sr=bz
authorDave Camp <dcamp@mozilla.com>
Tue, 26 Aug 2008 13:31:48 -0700
changeset 18427 b6fde4f6d35cffb593b4ef2fc6df390f70166a66
parent 18426 e49ce187bae5c8eeda2e89c2c661d61f91e1c8c0
child 18428 43e89bd626d27eb3574f5a3af9239b2fc24e7c97
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs450174
milestone1.9.1a2pre
Bug 450174: Remove static nsCAutoString usage from nsDOMOfflineResourceList. r+sr=bz
dom/src/offline/nsDOMOfflineResourceList.cpp
dom/src/offline/nsDOMOfflineResourceList.h
--- a/dom/src/offline/nsDOMOfflineResourceList.cpp
+++ b/dom/src/offline/nsDOMOfflineResourceList.cpp
@@ -68,20 +68,16 @@
 
 // To prevent abuse of the resource list for data storage, the number
 // of offline urls and their length are limited.
 
 static const char kMaxEntriesPref[] =  "offline.max_site_resources";
 #define DEFAULT_MAX_ENTRIES 100
 #define MAX_URI_LENGTH 2048
 
-static nsCAutoString gCachedAsciiHost;
-static char **gCachedKeys = nsnull;
-static PRUint32 gCachedKeysCount = 0;
-
 //
 // nsDOMOfflineResourceList
 //
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMOfflineResourceList)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMOfflineResourceList)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mWindow)
@@ -157,22 +153,25 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMOf
 nsDOMOfflineResourceList::nsDOMOfflineResourceList(PRBool aToplevel,
                                                    nsIURI *aManifestURI,
                                                    nsIURI *aDocumentURI,
                                                    nsIDOMWindow *aWindow)
   : mInitialized(PR_FALSE)
   , mToplevel(aToplevel)
   , mManifestURI(aManifestURI)
   , mDocumentURI(aDocumentURI)
+  , mCachedKeys(nsnull)
+  , mCachedKeysCount(0)
 {
   mWindow = do_GetWeakReference(aWindow);
 }
 
 nsDOMOfflineResourceList::~nsDOMOfflineResourceList()
 {
+  ClearCachedKeys();
 }
 
 nsresult
 nsDOMOfflineResourceList::Init()
 {
   if (mInitialized) {
     return NS_OK;
   }
@@ -281,35 +280,35 @@ nsDOMOfflineResourceList::GetLength(PRUi
   }
 
   nsresult rv = Init();
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = CacheKeys();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  *aLength = gCachedKeysCount;
+  *aLength = mCachedKeysCount;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMOfflineResourceList::Item(PRUint32 aIndex, nsAString& aURI)
 {
   nsresult rv = Init();
   NS_ENSURE_SUCCESS(rv, rv);
 
   SetDOMStringToNull(aURI);
 
   rv = CacheKeys();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  if (aIndex >= gCachedKeysCount)
+  if (aIndex >= mCachedKeysCount)
     return NS_ERROR_NOT_AVAILABLE;
 
-  CopyUTF8toUTF16(gCachedKeys[aIndex], aURI);
+  CopyUTF8toUTF16(mCachedKeys[aIndex], aURI);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMOfflineResourceList::Add(const nsAString& aURI)
 {
   nsresult rv = Init();
@@ -979,36 +978,27 @@ nsDOMOfflineResourceList::GetCacheKey(ns
   }
 
   return NS_OK;
 }
 
 nsresult
 nsDOMOfflineResourceList::CacheKeys()
 {
-  if (gCachedKeys && mAsciiHost == gCachedAsciiHost)
+  if (mCachedKeys)
     return NS_OK;
 
-  ClearCachedKeys();
-
-  nsresult rv = mCacheSession->GetOwnedKeys(mAsciiHost, mDynamicOwnerSpec,
-                                            &gCachedKeysCount, &gCachedKeys);
-
-  if (NS_SUCCEEDED(rv))
-    gCachedAsciiHost = mAsciiHost;
-
-  return rv;
+  return mCacheSession->GetOwnedKeys(mAsciiHost, mDynamicOwnerSpec,
+                                     &mCachedKeysCount, &mCachedKeys);
 }
 
 void
 nsDOMOfflineResourceList::ClearCachedKeys()
 {
-  if (gCachedKeys) {
-    NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(gCachedKeysCount, gCachedKeys);
-    gCachedKeys = nsnull;
-    gCachedKeysCount = 0;
+  if (mCachedKeys) {
+    NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(mCachedKeysCount, mCachedKeys);
+    mCachedKeys = nsnull;
+    mCachedKeysCount = 0;
   }
-
-  gCachedAsciiHost = "";
 }
 
 
 
--- a/dom/src/offline/nsDOMOfflineResourceList.h
+++ b/dom/src/offline/nsDOMOfflineResourceList.h
@@ -108,16 +108,20 @@ private:
   nsCOMPtr<nsIURI> mManifestURI;
   nsCOMPtr<nsIURI> mDocumentURI;
   nsCOMPtr<nsIWeakReference> mWindow;
   nsCOMPtr<nsIOfflineCacheSession> mCacheSession;
   nsCOMPtr<nsIOfflineCacheUpdate> mCacheUpdate;
   nsCAutoString mAsciiHost;
   nsCAutoString mDynamicOwnerSpec;
 
+  // The set of dynamic keys for this application cache object.
+  char **mCachedKeys;
+  PRUint32 mCachedKeysCount;
+
   nsCOMArray<nsIDOMEventListener> mCheckingListeners;
   nsCOMArray<nsIDOMEventListener> mErrorListeners;
   nsCOMArray<nsIDOMEventListener> mNoUpdateListeners;
   nsCOMArray<nsIDOMEventListener> mDownloadingListeners;
   nsCOMArray<nsIDOMEventListener> mProgressListeners;
   nsCOMArray<nsIDOMEventListener> mCachedListeners;
   nsCOMArray<nsIDOMEventListener> mUpdateReadyListeners;