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 33baa041a2
commit 7e4f1cdc66
5 changed files with 28 additions and 52 deletions

View File

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

View File

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

View File

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

View File

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

View File

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