Bug 699468: Part 3 - Always go through the Database to get the DatabaseInfo. r=bent

This commit is contained in:
Kyle Huey 2011-11-07 19:06:13 -05:00
parent a306354f5d
commit eaf3c475ca
5 changed files with 28 additions and 52 deletions

View File

@ -214,11 +214,7 @@ IDBDatabase::~IDBDatabase()
} }
if (mDatabaseId && !mInvalidated) { if (mDatabaseId && !mInvalidated) {
DatabaseInfo* info; DatabaseInfo* info = Info();
if (!DatabaseInfo::Get(mDatabaseId, &info)) {
NS_ERROR("This should never fail!");
}
NS_RELEASE(info); NS_RELEASE(info);
} }
@ -237,6 +233,17 @@ IDBDatabase::~IDBDatabase()
} }
} }
DatabaseInfo*
IDBDatabase::Info() const
{
DatabaseInfo* dbInfo = nsnull;
DebugOnly<bool> got = DatabaseInfo::Get(Id(), &dbInfo);
NS_ASSERTION(got && dbInfo, "This should never fail!");
return dbInfo;
}
bool bool
IDBDatabase::IsQuotaDisabled() IDBDatabase::IsQuotaDisabled()
{ {
@ -307,11 +314,7 @@ IDBDatabase::Invalidate()
} }
if (!PR_ATOMIC_SET(&mInvalidated, 1)) { if (!PR_ATOMIC_SET(&mInvalidated, 1)) {
DatabaseInfo* info; DatabaseInfo* info = Info();
if (!DatabaseInfo::Get(mDatabaseId, &info)) {
NS_ERROR("This should never fail!");
}
NS_RELEASE(info); NS_RELEASE(info);
} }
} }
@ -346,10 +349,7 @@ IDBDatabase::IsClosed()
void void
IDBDatabase::EnterSetVersionTransaction() IDBDatabase::EnterSetVersionTransaction()
{ {
DatabaseInfo* dbInfo; DatabaseInfo* dbInfo = Info();
if (!DatabaseInfo::Get(mDatabaseId, &dbInfo)) {
NS_ERROR("This should never fail!");
}
NS_ASSERTION(!dbInfo->runningVersionChange, "How did that happen?"); NS_ASSERTION(!dbInfo->runningVersionChange, "How did that happen?");
dbInfo->runningVersionChange = true; dbInfo->runningVersionChange = true;
@ -358,10 +358,7 @@ IDBDatabase::EnterSetVersionTransaction()
void void
IDBDatabase::ExitSetVersionTransaction() IDBDatabase::ExitSetVersionTransaction()
{ {
DatabaseInfo* dbInfo; DatabaseInfo* dbInfo = Info();
if (!DatabaseInfo::Get(mDatabaseId, &dbInfo)) {
NS_ERROR("This should never fail!");
}
NS_ASSERTION(dbInfo->runningVersionChange, "How did that happen?"); NS_ASSERTION(dbInfo->runningVersionChange, "How did that happen?");
dbInfo->runningVersionChange = false; dbInfo->runningVersionChange = false;
@ -426,11 +423,10 @@ NS_IMETHODIMP
IDBDatabase::GetVersion(PRUint64* aVersion) IDBDatabase::GetVersion(PRUint64* aVersion)
{ {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
DatabaseInfo* info;
if (!DatabaseInfo::Get(mDatabaseId, &info)) { DatabaseInfo* info = Info();
NS_ERROR("This should never fail!");
}
*aVersion = info->version; *aVersion = info->version;
return NS_OK; return NS_OK;
} }
@ -439,10 +435,7 @@ IDBDatabase::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores)
{ {
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
DatabaseInfo* info; DatabaseInfo* info = Info();
if (!DatabaseInfo::Get(mDatabaseId, &info)) {
NS_ERROR("This should never fail!");
}
nsAutoTArray<nsString, 10> objectStoreNames; nsAutoTArray<nsString, 10> objectStoreNames;
if (!info->GetObjectStoreNames(objectStoreNames)) { if (!info->GetObjectStoreNames(objectStoreNames)) {
@ -476,10 +469,7 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
} }
DatabaseInfo* databaseInfo; DatabaseInfo* databaseInfo = Info();
if (!DatabaseInfo::Get(mDatabaseId, &databaseInfo)) {
NS_ERROR("This should never fail!");
}
if (databaseInfo->ContainsStoreName(aName)) { if (databaseInfo->ContainsStoreName(aName)) {
return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR; return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
@ -620,10 +610,7 @@ IDBDatabase::Transaction(const jsval& aStoreNames,
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
} }
DatabaseInfo* info; DatabaseInfo* info = Info();
if (!DatabaseInfo::Get(mDatabaseId, &info)) {
NS_ERROR("This should never fail!");
}
if (info->runningVersionChange) { if (info->runningVersionChange) {
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;

View File

@ -83,11 +83,13 @@ public:
// nsIDOMEventTarget // nsIDOMEventTarget
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor); virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
nsIAtom* Id() nsIAtom* Id() const
{ {
return mDatabaseId; return mDatabaseId;
} }
DatabaseInfo* Info() const;
const nsString& Name() const nsString& Name()
{ {
return mName; return mName;

View File

@ -1342,10 +1342,7 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
} }
} }
DatabaseInfo* databaseInfo; DatabaseInfo* databaseInfo = mTransaction->Database()->Info();
if (!DatabaseInfo::Get(mTransaction->Database()->Id(), &databaseInfo)) {
NS_ERROR("This should never fail!");
}
IndexInfo* indexInfo = info->indexes.AppendElement(); IndexInfo* indexInfo = info->indexes.AppendElement();
if (!indexInfo) { if (!indexInfo) {

View File

@ -595,10 +595,7 @@ IDBTransaction::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores)
nsTArray<nsString>* arrayOfNames; nsTArray<nsString>* arrayOfNames;
if (mMode == IDBTransaction::VERSION_CHANGE) { if (mMode == IDBTransaction::VERSION_CHANGE) {
DatabaseInfo* info; DatabaseInfo* info = mDatabase->Info();
if (!DatabaseInfo::Get(mDatabase->Id(), &info)) {
NS_ERROR("This should never fail!");
}
if (!info->GetObjectStoreNames(stackArray)) { if (!info->GetObjectStoreNames(stackArray)) {
NS_ERROR("Out of memory!"); NS_ERROR("Out of memory!");
@ -834,10 +831,7 @@ CommitHelper::Run()
NS_ASSERTION(mTransaction->Mode() == nsIIDBTransaction::VERSION_CHANGE, NS_ASSERTION(mTransaction->Mode() == nsIIDBTransaction::VERSION_CHANGE,
"Bad transaction type!"); "Bad transaction type!");
DatabaseInfo* dbInfo; DatabaseInfo* dbInfo = mTransaction->Database()->Info();
if (!DatabaseInfo::Get(mTransaction->Database()->Id(), &dbInfo)) {
NS_ERROR("This should never fail!");
}
if (NS_FAILED(IDBFactory::UpdateDatabaseMetadata(dbInfo, mOldVersion, if (NS_FAILED(IDBFactory::UpdateDatabaseMetadata(dbInfo, mOldVersion,
mOldObjectStores))) { mOldObjectStores))) {

View File

@ -1091,11 +1091,7 @@ nsresult
SetVersionHelper::GetSuccessResult(JSContext* aCx, SetVersionHelper::GetSuccessResult(JSContext* aCx,
jsval* aVal) jsval* aVal)
{ {
DatabaseInfo* info; DatabaseInfo* info = mDatabase->Info();
if (!DatabaseInfo::Get(mDatabase->Id(), &info)) {
NS_ERROR("This should never fail!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
info->version = mRequestedVersion; info->version = mRequestedVersion;
NS_ASSERTION(mTransaction, "Better have a transaction!"); NS_ASSERTION(mTransaction, "Better have a transaction!");