diff --git a/dom/indexedDB/DatabaseInfo.cpp b/dom/indexedDB/DatabaseInfo.cpp index 0433aa75da8..acdcd390604 100644 --- a/dom/indexedDB/DatabaseInfo.cpp +++ b/dom/indexedDB/DatabaseInfo.cpp @@ -61,7 +61,7 @@ struct DatabaseInfoHash nsAutoPtr objectStoreHash; }; -typedef nsClassHashtable +typedef nsClassHashtable DatabaseHash; DatabaseHash* gDatabaseHash = nsnull; @@ -83,8 +83,7 @@ EnumerateObjectStoreNames(const nsAString& aKey, #ifdef NS_BUILD_REFCNT_LOGGING DatabaseInfo::DatabaseInfo() -: id(0), - nextObjectStoreId(1), +: nextObjectStoreId(1), nextIndexId(1), runningVersionChange(false) { @@ -135,7 +134,7 @@ IndexUpdateInfo::~IndexUpdateInfo() // static bool -DatabaseInfo::Get(PRUint32 aId, +DatabaseInfo::Get(nsIAtom* aId, DatabaseInfo** aInfo) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); @@ -187,7 +186,7 @@ DatabaseInfo::Put(DatabaseInfo* aInfo) // static void -DatabaseInfo::Remove(PRUint32 aId) +DatabaseInfo::Remove(nsIAtom* aId) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(Get(aId, nsnull), "Don't know anything about this one!"); @@ -241,7 +240,7 @@ DatabaseInfo::ContainsStoreName(const nsAString& aName) // static bool -ObjectStoreInfo::Get(PRUint32 aDatabaseId, +ObjectStoreInfo::Get(nsIAtom* aDatabaseId, const nsAString& aName, ObjectStoreInfo** aInfo) { @@ -297,7 +296,7 @@ ObjectStoreInfo::Put(ObjectStoreInfo* aInfo) // static void -ObjectStoreInfo::Remove(PRUint32 aDatabaseId, +ObjectStoreInfo::Remove(nsIAtom* aDatabaseId, const nsAString& aName) { NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); diff --git a/dom/indexedDB/DatabaseInfo.h b/dom/indexedDB/DatabaseInfo.h index 1f2ff398e0a..c3bed453b7e 100644 --- a/dom/indexedDB/DatabaseInfo.h +++ b/dom/indexedDB/DatabaseInfo.h @@ -54,23 +54,23 @@ struct DatabaseInfo ~DatabaseInfo(); #else DatabaseInfo() - : id(0), nextObjectStoreId(1), nextIndexId(1), runningVersionChange(false) + : nextObjectStoreId(1), nextIndexId(1), runningVersionChange(false) { } #endif - static bool Get(PRUint32 aId, + static bool Get(nsIAtom* aId, DatabaseInfo** aInfo); static bool Put(DatabaseInfo* aInfo); - static void Remove(PRUint32 aId); + static void Remove(nsIAtom* aId); bool GetObjectStoreNames(nsTArray& aNames); bool ContainsStoreName(const nsAString& aName); nsString name; PRUint64 version; - PRUint32 id; + nsIAtom* id; nsString filePath; PRInt64 nextObjectStoreId; PRInt64 nextIndexId; @@ -106,20 +106,20 @@ struct ObjectStoreInfo : id(0), autoIncrement(false), databaseId(0) { } #endif - static bool Get(PRUint32 aDatabaseId, + static bool Get(nsIAtom* aDatabaseId, const nsAString& aName, ObjectStoreInfo** aInfo); static bool Put(ObjectStoreInfo* aInfo); - static void Remove(PRUint32 aDatabaseId, + static void Remove(nsIAtom* aDatabaseId, const nsAString& aName); nsString name; PRInt64 id; nsString keyPath; bool autoIncrement; - PRUint32 databaseId; + nsIAtom* databaseId; nsTArray indexes; }; diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp index a87a325c75b..3022f185417 100644 --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -141,7 +141,7 @@ NS_STACK_CLASS class AutoRemoveObjectStore { public: - AutoRemoveObjectStore(PRUint32 aId, const nsAString& aName) + AutoRemoveObjectStore(nsIAtom* aId, const nsAString& aName) : mId(aId), mName(aName) { } @@ -158,7 +158,7 @@ public: } private: - PRUint32 mId; + nsCOMPtr mId; nsString mName; }; diff --git a/dom/indexedDB/IDBDatabase.h b/dom/indexedDB/IDBDatabase.h index 9df3cb4f3c2..ec97551f4e7 100644 --- a/dom/indexedDB/IDBDatabase.h +++ b/dom/indexedDB/IDBDatabase.h @@ -83,7 +83,7 @@ public: // nsIDOMEventTarget virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor); - PRUint32 Id() + nsIAtom* Id() { return mDatabaseId; } @@ -144,7 +144,7 @@ private: void OnUnlink(); - PRUint32 mDatabaseId; + nsCOMPtr mDatabaseId; nsString mName; nsString mFilePath; nsCString mASCIIOrigin; diff --git a/dom/indexedDB/IDBFactory.cpp b/dom/indexedDB/IDBFactory.cpp index be7eb62c773..2ce7629a62a 100644 --- a/dom/indexedDB/IDBFactory.cpp +++ b/dom/indexedDB/IDBFactory.cpp @@ -214,7 +214,7 @@ IDBFactory::GetDirectoryForOrigin(const nsACString& aASCIIOrigin, // static nsresult IDBFactory::LoadDatabaseInformation(mozIStorageConnection* aConnection, - PRUint32 aDatabaseId, + nsIAtom* aDatabaseId, PRUint64* aVersion, ObjectStoreInfoArray& aObjectStores) { @@ -436,6 +436,9 @@ IDBFactory::Open(const nsAString& aName, nsRefPtr openHelper = new OpenDatabaseHelper(request, aName, origin, aVersion); + rv = openHelper->Init(); + NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); + nsRefPtr permissionHelper = new CheckPermissionsHelper(openHelper, window, aName, origin); diff --git a/dom/indexedDB/IDBFactory.h b/dom/indexedDB/IDBFactory.h index 786c621a178..0c5d763151c 100644 --- a/dom/indexedDB/IDBFactory.h +++ b/dom/indexedDB/IDBFactory.h @@ -49,6 +49,7 @@ #include "nsXULAppAPI.h" class nsPIDOMWindow; +class nsIAtom; BEGIN_INDEXEDDB_NAMESPACE @@ -84,7 +85,7 @@ public: static nsresult LoadDatabaseInformation(mozIStorageConnection* aConnection, - PRUint32 aDatabaseId, + nsIAtom* aDatabaseId, PRUint64* aVersion, ObjectStoreInfoArray& aObjectStores); diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index 4d254ca8677..f2443b531e6 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -364,7 +364,7 @@ NS_STACK_CLASS class AutoRemoveIndex { public: - AutoRemoveIndex(PRUint32 aDatabaseId, + AutoRemoveIndex(nsIAtom* aDatabaseId, const nsAString& aObjectStoreName, const nsAString& aIndexName) : mDatabaseId(aDatabaseId), mObjectStoreName(aObjectStoreName), @@ -392,7 +392,7 @@ public: } private: - PRUint32 mDatabaseId; + nsCOMPtr mDatabaseId; nsString mObjectStoreName; nsString mIndexName; }; diff --git a/dom/indexedDB/IDBObjectStore.h b/dom/indexedDB/IDBObjectStore.h index 111ee02cce3..30b2fb56d99 100644 --- a/dom/indexedDB/IDBObjectStore.h +++ b/dom/indexedDB/IDBObjectStore.h @@ -194,7 +194,7 @@ private: nsString mName; nsString mKeyPath; bool mAutoIncrement; - PRUint32 mDatabaseId; + nsCOMPtr mDatabaseId; PRUint32 mStructuredCloneVersion; nsTArray > mCreatedIndexes; diff --git a/dom/indexedDB/OpenDatabaseHelper.cpp b/dom/indexedDB/OpenDatabaseHelper.cpp index ffe82ba4cbc..eb946549de9 100644 --- a/dom/indexedDB/OpenDatabaseHelper.cpp +++ b/dom/indexedDB/OpenDatabaseHelper.cpp @@ -523,6 +523,20 @@ private: NS_IMPL_THREADSAFE_ISUPPORTS1(OpenDatabaseHelper, nsIRunnable); +nsresult +OpenDatabaseHelper::Init() +{ + nsCString str(mASCIIOrigin); + str.Append("*"); + str.Append(NS_ConvertUTF16toUTF8(mName)); + + nsCOMPtr atom = do_GetAtom(str); + NS_ENSURE_TRUE(atom, NS_ERROR_FAILURE); + + atom.swap(mDatabaseId); + return NS_OK; +} + nsresult OpenDatabaseHelper::Dispatch(nsIEventTarget* aTarget) { @@ -630,9 +644,6 @@ OpenDatabaseHelper::DoDatabaseWork() NS_NOTYETIMPLEMENTED("Implement me!"); } - mDatabaseId = HashString(mDatabaseFilePath); - NS_ASSERTION(mDatabaseId, "HashString gave us 0?!"); - rv = IDBFactory::LoadDatabaseInformation(connection, mDatabaseId, &mCurrentVersion, mObjectStores); NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); diff --git a/dom/indexedDB/OpenDatabaseHelper.h b/dom/indexedDB/OpenDatabaseHelper.h index 53334867ab3..206b41c5f9b 100644 --- a/dom/indexedDB/OpenDatabaseHelper.h +++ b/dom/indexedDB/OpenDatabaseHelper.h @@ -67,6 +67,8 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIRUNNABLE + nsresult Init(); + nsresult Dispatch(nsIEventTarget* aDatabaseThread); nsresult RunImmediately(); @@ -103,13 +105,13 @@ private: nsString mName; nsCString mASCIIOrigin; PRUint64 mRequestedVersion; + nsCOMPtr mDatabaseId; // Out-params. nsTArray > mObjectStores; PRUint64 mCurrentVersion; PRUint32 mDataVersion; nsString mDatabaseFilePath; - PRUint32 mDatabaseId; PRInt64 mLastObjectStoreId; PRInt64 mLastIndexId; nsRefPtr mDatabase; diff --git a/dom/indexedDB/TransactionThreadPool.cpp b/dom/indexedDB/TransactionThreadPool.cpp index c78ba97ef90..256a055eacc 100644 --- a/dom/indexedDB/TransactionThreadPool.cpp +++ b/dom/indexedDB/TransactionThreadPool.cpp @@ -223,7 +223,7 @@ TransactionThreadPool::FinishTransaction(IDBTransaction* aTransaction) // AddRef here because removing from the hash will call Release. nsRefPtr transaction(aTransaction); - const PRUint32 databaseId = aTransaction->mDatabase->Id(); + nsIAtom* databaseId = aTransaction->mDatabase->Id(); DatabaseTransactionInfo* dbTransactionInfo; if (!mTransactionsInProgress.Get(databaseId, &dbTransactionInfo)) { @@ -324,7 +324,7 @@ TransactionThreadPool::TransactionCanRun(IDBTransaction* aTransaction, NS_ASSERTION(aCanRun, "Null pointer!"); NS_ASSERTION(aExistingQueue, "Null pointer!"); - const PRUint32 databaseId = aTransaction->mDatabase->Id(); + nsIAtom* databaseId = aTransaction->mDatabase->Id(); const nsTArray& objectStoreNames = aTransaction->mObjectStoreNames; const PRUint16 mode = aTransaction->mMode; @@ -421,7 +421,7 @@ TransactionThreadPool::Dispatch(IDBTransaction* aTransaction, return NS_OK; } - const PRUint32 databaseId = aTransaction->mDatabase->Id(); + nsIAtom* databaseId = aTransaction->mDatabase->Id(); #ifdef DEBUG if (aTransaction->mMode == IDBTransaction::VERSION_CHANGE) { diff --git a/dom/indexedDB/TransactionThreadPool.h b/dom/indexedDB/TransactionThreadPool.h index 4fdd152c4b0..aea35363eb0 100644 --- a/dom/indexedDB/TransactionThreadPool.h +++ b/dom/indexedDB/TransactionThreadPool.h @@ -168,7 +168,7 @@ protected: nsCOMPtr mThreadPool; - nsClassHashtable + nsClassHashtable mTransactionsInProgress; nsTArray mDelayedDispatchQueue;