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

This commit is contained in:
Kyle Huey 2011-11-07 19:15:43 -05:00
Родитель 39a529b2c0
Коммит d69b0e97cf
7 изменённых файлов: 49 добавлений и 73 удалений

Просмотреть файл

@ -212,72 +212,49 @@ DatabaseInfo::ContainsStoreName(const nsAString& aName)
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);
}
}

Просмотреть файл

@ -75,6 +75,13 @@ struct DatabaseInfo
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;
@ -115,15 +122,6 @@ struct 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;

Просмотреть файл

@ -131,24 +131,24 @@ 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;
};
@ -542,14 +542,14 @@ IDBDatabase::CreateObjectStore(const nsAString& aName,
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);
@ -579,8 +579,9 @@ IDBDatabase::DeleteObjectStore(const nsAString& aName)
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;
}
@ -589,7 +590,7 @@ IDBDatabase::DeleteObjectStore(const nsAString& aName)
nsresult rv = helper->DispatchToTransactionPool();
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
ObjectStoreInfo::Remove(mDatabaseId, aName);
info->RemoveObjectStore(aName);
return NS_OK;
}

Просмотреть файл

@ -346,7 +346,7 @@ IDBFactory::UpdateDatabaseMetadata(DatabaseInfo* aDatabaseInfo,
// 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;
@ -355,7 +355,7 @@ IDBFactory::UpdateDatabaseMetadata(DatabaseInfo* aDatabaseInfo,
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;
}

Просмотреть файл

@ -377,18 +377,18 @@ 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);
@ -401,11 +401,11 @@ public:
void forget()
{
mDatabaseId = 0;
mDatabase = nsnull;
}
private:
nsCOMPtr<nsIAtom> mDatabaseId;
IDBDatabase* mDatabase;
nsString mObjectStoreName;
nsString mIndexName;
};
@ -862,7 +862,7 @@ IDBObjectStore::GetAddInfo(JSContext* aCx,
// 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!");
}
@ -1037,7 +1037,7 @@ 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!");
}
@ -1278,7 +1278,7 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
}
ObjectStoreInfo* info;
if (!ObjectStoreInfo::Get(mTransaction->Database()->Id(), mName, &info)) {
if (!mTransaction->Database()->Info()->GetObjectStore(mName, &info)) {
NS_ERROR("This should never fail!");
}
@ -1357,7 +1357,7 @@ IDBObjectStore::CreateIndex(const nsAString& aName,
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++) {
@ -1397,7 +1397,7 @@ IDBObjectStore::Index(const nsAString& aName,
}
ObjectStoreInfo* info;
if (!ObjectStoreInfo::Get(mTransaction->Database()->Id(), mName, &info)) {
if (!mTransaction->Database()->Info()->GetObjectStore(mName, &info)) {
NS_ERROR("This should never fail!");
}
@ -1453,7 +1453,7 @@ IDBObjectStore::DeleteIndex(const nsAString& aName)
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!");
}

Просмотреть файл

@ -632,7 +632,7 @@ IDBTransaction::ObjectStore(const nsAString& aName,
if (mMode == nsIIDBTransaction::VERSION_CHANGE ||
mObjectStoreNames.Contains(aName)) {
ObjectStoreInfo::Get(mDatabase->Id(), aName, &info);
mDatabase->Info()->GetObjectStore(aName, &info);
}
if (!info) {

Просмотреть файл

@ -898,7 +898,7 @@ OpenDatabaseHelper::EnsureSuccessResult()
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 &&