Bug 699468: Part 4 - Always go through the DatabaseInfo to get the ObjectStoreInfo. r=bent
authorKyle Huey <khuey@kylehuey.com>
Mon, 07 Nov 2011 19:15:43 -0500
changeset 79923 b978e3a3f46714ef58dbc92239cecce4404e55d1
parent 79922 0b28e3f6054419fc8550ff21c11d2e419e188728
child 79924 4a0214e37148fb87add7d64806d5fb7d06b27aea
push id21441
push userkhuey@mozilla.com
push dateTue, 08 Nov 2011 00:22:21 +0000
treeherdermozilla-central@d67299b21838 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs699468
milestone10.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 699468: Part 4 - Always go through the DatabaseInfo to get the ObjectStoreInfo. r=bent
dom/indexedDB/DatabaseInfo.cpp
dom/indexedDB/DatabaseInfo.h
dom/indexedDB/IDBDatabase.cpp
dom/indexedDB/IDBFactory.cpp
dom/indexedDB/IDBObjectStore.cpp
dom/indexedDB/IDBTransaction.cpp
dom/indexedDB/OpenDatabaseHelper.cpp
--- a/dom/indexedDB/DatabaseInfo.cpp
+++ b/dom/indexedDB/DatabaseInfo.cpp
@@ -207,77 +207,54 @@ DatabaseInfo::ContainsStoreName(const ns
   DatabaseInfo* dbInfo;
 
   return gDatabaseHash &&
          gDatabaseHash->Get(id, &dbInfo) &&
          dbInfo->objectStoreHash &&
          dbInfo->objectStoreHash->Get(aName, nsnull);
 }
 
-// static
 bool
-ObjectStoreInfo::Get(nsIAtom* aDatabaseId,
-                     const nsAString& aName,
-                     ObjectStoreInfo** aInfo)
+DatabaseInfo::GetObjectStore(const nsAString& aName,
+                             ObjectStoreInfo** aInfo)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
-  if (gDatabaseHash) {
-    DatabaseInfo* info;
-    if (gDatabaseHash->Get(aDatabaseId, &info) &&
-        info->objectStoreHash) {
-      return !!info->objectStoreHash->Get(aName, aInfo);
-    }
+  if (objectStoreHash) {
+    return objectStoreHash->Get(aName, aInfo);
   }
 
   return false;
 }
 
-// static
 bool
-ObjectStoreInfo::Put(ObjectStoreInfo* aInfo)
+DatabaseInfo::PutObjectStore(ObjectStoreInfo* aInfo)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(aInfo, "Null pointer!");
 
-  if (!gDatabaseHash) {
-    NS_ERROR("No databases known!");
-    return false;
-  }
-
-  DatabaseInfo* info;
-  if (!gDatabaseHash->Get(aInfo->databaseId, &info)) {
-    NS_ERROR("Don't know about this database!");
-    return false;
-  }
-
-  if (!info->objectStoreHash) {
-    nsAutoPtr<ObjectStoreInfoHash> objectStoreHash(new ObjectStoreInfoHash());
-    if (!objectStoreHash->Init()) {
+  if (!objectStoreHash) {
+    nsAutoPtr<ObjectStoreInfoHash> hash(new ObjectStoreInfoHash());
+    if (!hash->Init()) {
       NS_ERROR("Failed to initialize hashtable!");
       return false;
     }
-    info->objectStoreHash = objectStoreHash.forget();
+    objectStoreHash = hash.forget();
   }
 
-  if (info->objectStoreHash->Get(aInfo->name, nsnull)) {
+  if (objectStoreHash->Get(aInfo->name, nsnull)) {
     NS_ERROR("Already have an entry for this objectstore!");
     return false;
   }
 
-  return !!info->objectStoreHash->Put(aInfo->name, aInfo);
+  return objectStoreHash->Put(aInfo->name, aInfo);
 }
 
-// static
 void
-ObjectStoreInfo::Remove(nsIAtom* aDatabaseId,
-                        const nsAString& aName)
+DatabaseInfo::RemoveObjectStore(const nsAString& aName)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-  NS_ASSERTION(Get(aDatabaseId, aName, nsnull), "Don't know about this one!");
+  NS_ASSERTION(GetObjectStore(aName, nsnull), "Don't know about this one!");
 
-  if (gDatabaseHash) {
-    DatabaseInfo* info;
-    if (gDatabaseHash->Get(aDatabaseId, &info) && info->objectStoreHash) {
-      info->objectStoreHash->Remove(aName);
-    }
+  if (objectStoreHash) {
+    objectStoreHash->Remove(aName);
   }
 }
--- a/dom/indexedDB/DatabaseInfo.h
+++ b/dom/indexedDB/DatabaseInfo.h
@@ -70,16 +70,23 @@ struct DatabaseInfo
 
   static bool Put(DatabaseInfo* aInfo);
 
   static void Remove(nsIAtom* aId);
 
   bool GetObjectStoreNames(nsTArray<nsString>& aNames);
   bool ContainsStoreName(const nsAString& aName);
 
+  bool GetObjectStore(const nsAString& aName,
+                      ObjectStoreInfo** aInfo);
+
+  bool PutObjectStore(ObjectStoreInfo* aInfo);
+
+  void RemoveObjectStore(const nsAString& aName);
+
   nsString name;
   PRUint64 version;
   nsIAtom* id;
   nsString filePath;
   PRInt64 nextObjectStoreId;
   PRInt64 nextIndexId;
   bool runningVersionChange;
 
@@ -110,25 +117,16 @@ struct ObjectStoreInfo
 #ifdef NS_BUILD_REFCNT_LOGGING
   ObjectStoreInfo();
   ~ObjectStoreInfo();
 #else
   ObjectStoreInfo()
   : id(0), autoIncrement(false), databaseId(0) { }
 #endif
 
-  static bool Get(nsIAtom* aDatabaseId,
-                  const nsAString& aName,
-                  ObjectStoreInfo** aInfo);
-
-  static bool Put(ObjectStoreInfo* aInfo);
-
-  static void Remove(nsIAtom* aDatabaseId,
-                     const nsAString& aName);
-
   nsString name;
   PRInt64 id;
   nsString keyPath;
   bool autoIncrement;
   nsIAtom* databaseId;
   nsTArray<IndexInfo> indexes;
 };
 
--- a/dom/indexedDB/IDBDatabase.cpp
+++ b/dom/indexedDB/IDBDatabase.cpp
@@ -126,34 +126,34 @@ private:
   // In-params.
   PRInt64 mObjectStoreId;
 };
 
 NS_STACK_CLASS
 class AutoRemoveObjectStore
 {
 public:
-  AutoRemoveObjectStore(nsIAtom* aId, const nsAString& aName)
-  : mId(aId), mName(aName)
+  AutoRemoveObjectStore(IDBDatabase* aDatabase, const nsAString& aName)
+  : mDatabase(aDatabase), mName(aName)
   { }
 
   ~AutoRemoveObjectStore()
   {
-    if (mId) {
-      ObjectStoreInfo::Remove(mId, mName);
+    if (mDatabase) {
+      mDatabase->Info()->RemoveObjectStore(mName);
     }
   }
 
   void forget()
   {
-    mId = 0;
+    mDatabase = nsnull;
   }
 
 private:
-  nsCOMPtr<nsIAtom> mId;
+  IDBDatabase* mDatabase;
   nsString mName;
 };
 
 } // anonymous namespace
 
 // static
 already_AddRefed<IDBDatabase>
 IDBDatabase::Create(nsIScriptContext* aScriptContext,
@@ -537,24 +537,24 @@ IDBDatabase::CreateObjectStore(const nsA
   nsAutoPtr<ObjectStoreInfo> newInfo(new ObjectStoreInfo());
 
   newInfo->name = aName;
   newInfo->id = databaseInfo->nextObjectStoreId++;
   newInfo->keyPath = keyPath;
   newInfo->autoIncrement = autoIncrement;
   newInfo->databaseId = mDatabaseId;
 
-  if (!ObjectStoreInfo::Put(newInfo)) {
+  if (!Info()->PutObjectStore(newInfo)) {
     NS_WARNING("Put failed!");
     return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
   }
   ObjectStoreInfo* objectStoreInfo = newInfo.forget();
 
   // Don't leave this in the hash if we fail below!
-  AutoRemoveObjectStore autoRemove(mDatabaseId, aName);
+  AutoRemoveObjectStore autoRemove(this, aName);
 
   nsRefPtr<IDBObjectStore> objectStore =
     transaction->GetOrCreateObjectStore(aName, objectStoreInfo);
   NS_ENSURE_TRUE(objectStore, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
 
   nsRefPtr<CreateObjectStoreHelper> helper =
     new CreateObjectStoreHelper(transaction, objectStore);
 
@@ -574,27 +574,28 @@ IDBDatabase::DeleteObjectStore(const nsA
 
   IDBTransaction* transaction = AsyncConnectionHelper::GetCurrentTransaction();
 
   if (!transaction ||
       transaction->Mode() != nsIIDBTransaction::VERSION_CHANGE) {
     return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
   }
 
+  DatabaseInfo* info = Info();
   ObjectStoreInfo* objectStoreInfo;
-  if (!ObjectStoreInfo::Get(mDatabaseId, aName, &objectStoreInfo)) {
+  if (!info->GetObjectStore(aName, &objectStoreInfo)) {
     return NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR;
   }
 
   nsRefPtr<DeleteObjectStoreHelper> helper =
     new DeleteObjectStoreHelper(transaction, objectStoreInfo->id);
   nsresult rv = helper->DispatchToTransactionPool();
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
 
-  ObjectStoreInfo::Remove(mDatabaseId, aName);
+  info->RemoveObjectStore(aName);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 IDBDatabase::Transaction(const jsval& aStoreNames,
                          PRUint16 aMode,
                          JSContext* aCx,
                          PRUint8 aOptionalArgCount,
--- a/dom/indexedDB/IDBFactory.cpp
+++ b/dom/indexedDB/IDBFactory.cpp
@@ -341,26 +341,26 @@ IDBFactory::UpdateDatabaseMetadata(Datab
   nsAutoTArray<nsString, 10> existingNames;
   if (!aDatabaseInfo->GetObjectStoreNames(existingNames)) {
     NS_WARNING("Out of memory!");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   // Remove all the old ones.
   for (PRUint32 index = 0; index < existingNames.Length(); index++) {
-    ObjectStoreInfo::Remove(aDatabaseInfo->id, existingNames[index]);
+    aDatabaseInfo->RemoveObjectStore(existingNames[index]);
   }
 
   aDatabaseInfo->version = aVersion;
 
   for (PRUint32 index = 0; index < objectStores.Length(); index++) {
     nsAutoPtr<ObjectStoreInfo>& info = objectStores[index];
     NS_ASSERTION(info->databaseId == aDatabaseInfo->id, "Huh?!");
 
-    if (!ObjectStoreInfo::Put(info)) {
+    if (!aDatabaseInfo->PutObjectStore(info)) {
       NS_WARNING("Out of memory!");
       return NS_ERROR_OUT_OF_MEMORY;
     }
 
     info.forget();
   }
 
   return NS_OK;
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -372,45 +372,45 @@ protected:
 private:
   PRUint64 mCount;
 };
 
 NS_STACK_CLASS
 class AutoRemoveIndex
 {
 public:
-  AutoRemoveIndex(nsIAtom* aDatabaseId,
+  AutoRemoveIndex(IDBDatabase* aDatabase,
                   const nsAString& aObjectStoreName,
                   const nsAString& aIndexName)
-  : mDatabaseId(aDatabaseId), mObjectStoreName(aObjectStoreName),
+  : mDatabase(aDatabase), mObjectStoreName(aObjectStoreName),
     mIndexName(aIndexName)
   { }
 
   ~AutoRemoveIndex()
   {
-    if (mDatabaseId) {
+    if (mDatabase) {
       ObjectStoreInfo* info;
-      if (ObjectStoreInfo::Get(mDatabaseId, mObjectStoreName, &info)) {
+      if (mDatabase->Info()->GetObjectStore(mObjectStoreName, &info)) {
         for (PRUint32 index = 0; index < info->indexes.Length(); index++) {
           if (info->indexes[index].name == mIndexName) {
             info->indexes.RemoveElementAt(index);
             break;
           }
         }
       }
     }
   }
 
   void forget()
   {
-    mDatabaseId = 0;
+    mDatabase = nsnull;
   }
 
 private:
-  nsCOMPtr<nsIAtom> mDatabaseId;
+  IDBDatabase* mDatabase;
   nsString mObjectStoreName;
   nsString mIndexName;
 };
 
 inline
 nsresult
 GetKeyFromObject(JSContext* aCx,
                  JSObject* aObj,
@@ -857,17 +857,17 @@ IDBObjectStore::GetAddInfo(JSContext* aC
   // Return DATA_ERR if no key was specified this isn't an autoIncrement
   // objectStore.
   if (aKey.IsUnset() && !mAutoIncrement) {
     return NS_ERROR_DOM_INDEXEDDB_DATA_ERR;
   }
 
   // Figure out indexes and the index values to update here.
   ObjectStoreInfo* info;
-  if (!ObjectStoreInfo::Get(mTransaction->Database()->Id(), mName, &info)) {
+  if (!mTransaction->Database()->Info()->GetObjectStore(mName, &info)) {
     NS_ERROR("This should never fail!");
   }
 
   rv = GetIndexUpdateInfo(info, aCx, aValue, aUpdateInfoArray);
   NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
 
   const jschar* keyPathChars =
     reinterpret_cast<const jschar*>(mKeyPath.get());
@@ -1032,17 +1032,17 @@ IDBObjectStore::GetTransaction(nsIIDBTra
 }
 
 NS_IMETHODIMP
 IDBObjectStore::GetIndexNames(nsIDOMDOMStringList** aIndexNames)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   ObjectStoreInfo* info;
-  if (!ObjectStoreInfo::Get(mTransaction->Database()->Id(), mName, &info)) {
+  if (!mTransaction->Database()->Info()->GetObjectStore(mName, &info)) {
     NS_ERROR("This should never fail!");
   }
 
   nsRefPtr<nsDOMStringList> list(new nsDOMStringList());
 
   PRUint32 count = info->indexes.Length();
   for (PRUint32 index = 0; index < count; index++) {
     NS_ENSURE_TRUE(list->Add(info->indexes[index].name),
@@ -1273,17 +1273,17 @@ IDBObjectStore::CreateIndex(const nsAStr
 
   if (!transaction ||
       transaction != mTransaction ||
       mTransaction->Mode() != nsIIDBTransaction::VERSION_CHANGE) {
     return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
   }
 
   ObjectStoreInfo* info;
-  if (!ObjectStoreInfo::Get(mTransaction->Database()->Id(), mName, &info)) {
+  if (!mTransaction->Database()->Info()->GetObjectStore(mName, &info)) {
     NS_ERROR("This should never fail!");
   }
 
   bool found = false;
   PRUint32 indexCount = info->indexes.Length();
   for (PRUint32 index = 0; index < indexCount; index++) {
     if (info->indexes[index].name == aName) {
       found = true;
@@ -1352,17 +1352,17 @@ IDBObjectStore::CreateIndex(const nsAStr
 
   indexInfo->id = databaseInfo->nextIndexId++;
   indexInfo->name = aName;
   indexInfo->keyPath = aKeyPath;
   indexInfo->unique = unique;
   indexInfo->autoIncrement = mAutoIncrement;
 
   // Don't leave this in the list if we fail below!
-  AutoRemoveIndex autoRemove(databaseInfo->id, mName, aName);
+  AutoRemoveIndex autoRemove(mTransaction->Database(), mName, aName);
 
 #ifdef DEBUG
   for (PRUint32 index = 0; index < mCreatedIndexes.Length(); index++) {
     if (mCreatedIndexes[index]->Name() == aName) {
       NS_ERROR("Already created this one!");
     }
   }
 #endif
@@ -1392,17 +1392,17 @@ IDBObjectStore::Index(const nsAString& a
 {
   NS_PRECONDITION(NS_IsMainThread(), "Wrong thread!");
 
   if (!mTransaction->IsOpen()) {
     return NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR;
   }
 
   ObjectStoreInfo* info;
-  if (!ObjectStoreInfo::Get(mTransaction->Database()->Id(), mName, &info)) {
+  if (!mTransaction->Database()->Info()->GetObjectStore(mName, &info)) {
     NS_ERROR("This should never fail!");
   }
 
   IndexInfo* indexInfo = nsnull;
   PRUint32 indexCount = info->indexes.Length();
   for (PRUint32 index = 0; index < indexCount; index++) {
     if (info->indexes[index].name == aName) {
       indexInfo = &(info->indexes[index]);
@@ -1448,17 +1448,17 @@ IDBObjectStore::DeleteIndex(const nsAStr
       transaction != mTransaction ||
       mTransaction->Mode() != nsIIDBTransaction::VERSION_CHANGE) {
     return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
   }
 
   NS_ASSERTION(mTransaction->IsOpen(), "Impossible!");
 
   ObjectStoreInfo* info;
-  if (!ObjectStoreInfo::Get(mTransaction->Database()->Id(), mName, &info)) {
+  if (!mTransaction->Database()->Info()->GetObjectStore(mName, &info)) {
     NS_ERROR("This should never fail!");
   }
 
   PRUint32 index = 0;
   for (; index < info->indexes.Length(); index++) {
     if (info->indexes[index].name == aName) {
       break;
     }
--- a/dom/indexedDB/IDBTransaction.cpp
+++ b/dom/indexedDB/IDBTransaction.cpp
@@ -627,17 +627,17 @@ IDBTransaction::ObjectStore(const nsAStr
   if (!IsOpen()) {
     return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
   }
 
   ObjectStoreInfo* info = nsnull;
 
   if (mMode == nsIIDBTransaction::VERSION_CHANGE ||
       mObjectStoreNames.Contains(aName)) {
-    ObjectStoreInfo::Get(mDatabase->Id(), aName, &info);
+    mDatabase->Info()->GetObjectStore(aName, &info);
   }
 
   if (!info) {
     return NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR;
   }
 
   nsRefPtr<IDBObjectStore> objectStore = GetOrCreateObjectStore(aName, info);
   NS_ENSURE_TRUE(objectStore, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
--- a/dom/indexedDB/OpenDatabaseHelper.cpp
+++ b/dom/indexedDB/OpenDatabaseHelper.cpp
@@ -893,17 +893,17 @@ OpenDatabaseHelper::EnsureSuccessResult(
                    "Metadata mismatch!");
 
       PRUint32 objectStoreCount = mObjectStores.Length();
       for (PRUint32 index = 0; index < objectStoreCount; index++) {
         nsAutoPtr<ObjectStoreInfo>& info = mObjectStores[index];
         NS_ASSERTION(info->databaseId == mDatabaseId, "Huh?!");
 
         ObjectStoreInfo* otherInfo;
-        NS_ASSERTION(ObjectStoreInfo::Get(mDatabaseId, info->name, &otherInfo),
+        NS_ASSERTION(dbInfo->GetObjectStore(info->name, &otherInfo),
                      "ObjectStore not known!");
 
         NS_ASSERTION(info->name == otherInfo->name &&
                      info->id == otherInfo->id &&
                      info->keyPath == otherInfo->keyPath &&
                      info->autoIncrement == otherInfo->autoIncrement &&
                      info->databaseId == otherInfo->databaseId,
                      "Metadata mismatch!");