Bug 687755. Refactor some code to make it easier to add new nsDOMStorageDBWrapper methods that forward to the various storage implementations. r=honza
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 19 Sep 2011 22:49:44 -0400
changeset 77172 30a5dfdf8aba3543e6974d1650423c9b88892b62
parent 77171 e0708cefd3df4ef1626c7a15cb51d3186757f2e1
child 77173 2dbed30dd67d46cd929a305842938a2cf95f7231
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewershonza
bugs687755
milestone9.0a1
Bug 687755. Refactor some code to make it easier to add new nsDOMStorageDBWrapper methods that forward to the various storage implementations. r=honza
dom/src/storage/nsDOMStorageDBWrapper.cpp
--- a/dom/src/storage/nsDOMStorageDBWrapper.cpp
+++ b/dom/src/storage/nsDOMStorageDBWrapper.cpp
@@ -108,111 +108,77 @@ nsDOMStorageDBWrapper::FlushAndDeleteTem
   // Everything flushed?  Then no need for a timer.
   if (!mChromePersistentDB.mTempTableLoads.Count() && 
       !mPersistentDB.mTempTableLoads.Count())
     StopTempTableFlushTimer();
 
   return NS_FAILED(rv1) ? rv1 : rv2;
 }
 
+#define IMPL_FORWARDER(_code)                                         \
+  PR_BEGIN_MACRO                                                      \
+  if (aStorage->CanUseChromePersist())                                \
+    return mChromePersistentDB._code;                                 \
+  if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())  \
+    return mPrivateBrowsingDB._code;                                  \
+  if (aStorage->SessionOnly())                                        \
+    return mSessionOnlyDB._code;                                      \
+  return mPersistentDB._code;                                         \
+  PR_END_MACRO
+
 nsresult
 nsDOMStorageDBWrapper::GetAllKeys(DOMStorageImpl* aStorage,
                                   nsTHashtable<nsSessionStorageEntry>* aKeys)
 {
-  if (aStorage->CanUseChromePersist())
-    return mChromePersistentDB.GetAllKeys(aStorage, aKeys);
-  if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
-    return mPrivateBrowsingDB.GetAllKeys(aStorage, aKeys);
-  if (aStorage->SessionOnly())
-    return mSessionOnlyDB.GetAllKeys(aStorage, aKeys);
-
-  return mPersistentDB.GetAllKeys(aStorage, aKeys);
+  IMPL_FORWARDER(GetAllKeys(aStorage, aKeys));
 }
 
 nsresult
 nsDOMStorageDBWrapper::GetKeyValue(DOMStorageImpl* aStorage,
                                    const nsAString& aKey,
                                    nsAString& aValue,
                                    PRBool* aSecure)
 {
-  if (aStorage->CanUseChromePersist())
-    return mChromePersistentDB.GetKeyValue(aStorage, aKey, aValue, aSecure);
-  if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
-    return mPrivateBrowsingDB.GetKeyValue(aStorage, aKey, aValue, aSecure);
-  if (aStorage->SessionOnly())
-    return mSessionOnlyDB.GetKeyValue(aStorage, aKey, aValue, aSecure);
-
-  return mPersistentDB.GetKeyValue(aStorage, aKey, aValue, aSecure);
+  IMPL_FORWARDER(GetKeyValue(aStorage, aKey, aValue, aSecure));
 }
 
 nsresult
 nsDOMStorageDBWrapper::SetKey(DOMStorageImpl* aStorage,
                               const nsAString& aKey,
                               const nsAString& aValue,
                               PRBool aSecure,
                               PRInt32 aQuota,
                               PRBool aExcludeOfflineFromUsage,
                               PRInt32 *aNewUsage)
 {
-  if (aStorage->CanUseChromePersist())
-    return mChromePersistentDB.SetKey(aStorage, aKey, aValue, aSecure,
-                                      aQuota, aExcludeOfflineFromUsage, aNewUsage);
-  if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
-    return mPrivateBrowsingDB.SetKey(aStorage, aKey, aValue, aSecure,
-                                          aQuota, aExcludeOfflineFromUsage, aNewUsage);
-  if (aStorage->SessionOnly())
-    return mSessionOnlyDB.SetKey(aStorage, aKey, aValue, aSecure,
-                                      aQuota, aExcludeOfflineFromUsage, aNewUsage);
-
-  return mPersistentDB.SetKey(aStorage, aKey, aValue, aSecure,
-                                   aQuota, aExcludeOfflineFromUsage, aNewUsage);
+  IMPL_FORWARDER(SetKey(aStorage, aKey, aValue, aSecure,
+                        aQuota, aExcludeOfflineFromUsage, aNewUsage));
 }
 
 nsresult
 nsDOMStorageDBWrapper::SetSecure(DOMStorageImpl* aStorage,
                                  const nsAString& aKey,
                                  const PRBool aSecure)
 {
-  if (aStorage->CanUseChromePersist())
-    return mChromePersistentDB.SetSecure(aStorage, aKey, aSecure);
-  if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
-    return mPrivateBrowsingDB.SetSecure(aStorage, aKey, aSecure);
-  if (aStorage->SessionOnly())
-    return mSessionOnlyDB.SetSecure(aStorage, aKey, aSecure);
-
-  return mPersistentDB.SetSecure(aStorage, aKey, aSecure);
+  IMPL_FORWARDER(SetSecure(aStorage, aKey, aSecure));
 }
 
 nsresult
 nsDOMStorageDBWrapper::RemoveKey(DOMStorageImpl* aStorage,
                                  const nsAString& aKey,
                                  PRBool aExcludeOfflineFromUsage,
                                  PRInt32 aKeyUsage)
 {
-  if (aStorage->CanUseChromePersist())
-    return mChromePersistentDB.RemoveKey(aStorage, aKey, aExcludeOfflineFromUsage, aKeyUsage);
-  if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
-    return mPrivateBrowsingDB.RemoveKey(aStorage, aKey, aExcludeOfflineFromUsage, aKeyUsage);
-  if (aStorage->SessionOnly())
-    return mSessionOnlyDB.RemoveKey(aStorage, aKey, aExcludeOfflineFromUsage, aKeyUsage);
-
-  return mPersistentDB.RemoveKey(aStorage, aKey, aExcludeOfflineFromUsage, aKeyUsage);
+  IMPL_FORWARDER(RemoveKey(aStorage, aKey, aExcludeOfflineFromUsage, aKeyUsage));
 }
 
 nsresult
 nsDOMStorageDBWrapper::ClearStorage(DOMStorageImpl* aStorage)
 {
-  if (aStorage->CanUseChromePersist())
-    return mChromePersistentDB.ClearStorage(aStorage);
-  if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
-    return mPrivateBrowsingDB.ClearStorage(aStorage);
-  if (aStorage->SessionOnly())
-    return mSessionOnlyDB.ClearStorage(aStorage);
-
-  return mPersistentDB.ClearStorage(aStorage);
+  IMPL_FORWARDER(ClearStorage(aStorage));
 }
 
 nsresult
 nsDOMStorageDBWrapper::DropSessionOnlyStoragesForHost(const nsACString& aHostName)
 {
   return mSessionOnlyDB.RemoveOwner(aHostName, PR_TRUE);
 }
 
@@ -284,24 +250,17 @@ nsDOMStorageDBWrapper::RemoveAll()
 
   return rv;
 }
 
 nsresult
 nsDOMStorageDBWrapper::GetUsage(DOMStorageImpl* aStorage,
                                 PRBool aExcludeOfflineFromUsage, PRInt32 *aUsage)
 {
-  if (aStorage->CanUseChromePersist())
-    return mChromePersistentDB.GetUsage(aStorage, aExcludeOfflineFromUsage, aUsage);    
-  if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
-    return mPrivateBrowsingDB.GetUsage(aStorage, aExcludeOfflineFromUsage, aUsage);
-  if (aStorage->SessionOnly())
-    return mSessionOnlyDB.GetUsage(aStorage, aExcludeOfflineFromUsage, aUsage);
-
-  return mPersistentDB.GetUsage(aStorage, aExcludeOfflineFromUsage, aUsage);
+  IMPL_FORWARDER(GetUsage(aStorage, aExcludeOfflineFromUsage, aUsage));
 }
 
 nsresult
 nsDOMStorageDBWrapper::GetUsage(const nsACString& aDomain,
                                 PRBool aIncludeSubDomains, PRInt32 *aUsage)
 {
   if (nsDOMStorageManager::gStorageManager->InPrivateBrowsingMode())
     return mPrivateBrowsingDB.GetUsage(aDomain, aIncludeSubDomains, aUsage);