Bug 699468: Part 2 - Give DatabaseInfo an AddRef/Release instead of twiddling a refcount manually. r=bent

This commit is contained in:
Kyle Huey 2011-11-07 19:06:13 -05:00
parent 625868f68e
commit 33baa041a2
4 changed files with 13 additions and 32 deletions

View File

@ -66,20 +66,13 @@ EnumerateObjectStoreNames(const nsAString& aKey,
}
#ifdef NS_BUILD_REFCNT_LOGGING
DatabaseInfo::DatabaseInfo()
: nextObjectStoreId(1),
nextIndexId(1),
runningVersionChange(false)
{
MOZ_COUNT_CTOR(DatabaseInfo);
}
DatabaseInfo::~DatabaseInfo()
{
MOZ_COUNT_DTOR(DatabaseInfo);
DatabaseInfo::Remove(id);
}
#ifdef NS_BUILD_REFCNT_LOGGING
IndexInfo::IndexInfo()
: id(LL_MININT),
unique(false),
@ -181,8 +174,6 @@ DatabaseInfo::Remove(nsIAtom* aId)
gDatabaseHash = nsnull;
}
}
delete info;
}
bool

View File

@ -58,14 +58,12 @@ typedef nsClassHashtable<nsStringHashKey, ObjectStoreInfo>
struct DatabaseInfo
{
#ifdef NS_BUILD_REFCNT_LOGGING
DatabaseInfo();
~DatabaseInfo();
#else
DatabaseInfo()
: nextObjectStoreId(1), nextIndexId(1), runningVersionChange(false)
: nextObjectStoreId(1),
nextIndexId(1),
runningVersionChange(false)
{ }
#endif
~DatabaseInfo();
static bool Get(nsIAtom* aId,
DatabaseInfo** aInfo);
@ -87,7 +85,7 @@ struct DatabaseInfo
nsAutoPtr<ObjectStoreInfoHash> objectStoreHash;
nsAutoRefCnt referenceCount;
NS_INLINE_DECL_REFCOUNTING(DatabaseInfo)
};
struct IndexInfo

View File

@ -219,10 +219,7 @@ IDBDatabase::~IDBDatabase()
NS_ERROR("This should never fail!");
}
NS_ASSERTION(info->referenceCount, "Bad reference count!");
if (--info->referenceCount == 0) {
DatabaseInfo::Remove(mDatabaseId);
}
NS_RELEASE(info);
}
if (mListenerManager) {
@ -315,10 +312,7 @@ IDBDatabase::Invalidate()
NS_ERROR("This should never fail!");
}
NS_ASSERTION(info->referenceCount, "Bad reference count!");
if (--info->referenceCount == 0) {
DatabaseInfo::Remove(mDatabaseId);
}
NS_RELEASE(info);
}
}

View File

@ -882,8 +882,7 @@ OpenDatabaseHelper::EnsureSuccessResult()
{
DatabaseInfo* dbInfo;
if (DatabaseInfo::Get(mDatabaseId, &dbInfo)) {
NS_ASSERTION(dbInfo->referenceCount, "Bad reference count!");
++dbInfo->referenceCount;
NS_ADDREF(dbInfo);
#ifdef DEBUG
{
@ -934,19 +933,18 @@ OpenDatabaseHelper::EnsureSuccessResult()
}
else {
nsAutoPtr<DatabaseInfo> newInfo(new DatabaseInfo());
nsRefPtr<DatabaseInfo> newInfo(new DatabaseInfo());
newInfo->name = mName;
newInfo->id = mDatabaseId;
newInfo->filePath = mDatabaseFilePath;
newInfo->referenceCount = 1;
if (!DatabaseInfo::Put(newInfo)) {
NS_ERROR("Failed to add to hash!");
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
dbInfo = newInfo.forget();
newInfo.forget(&dbInfo);
nsresult rv = IDBFactory::UpdateDatabaseMetadata(dbInfo, mCurrentVersion,
mObjectStores);