Bug 696399 - close connections in dom. r=honzab.moz.

This commit is contained in:
Rafael Ávila de Espíndola 2011-11-30 19:30:32 -05:00
Родитель 87ba18ddb5
Коммит 3fd972d654
6 изменённых файлов: 54 добавлений и 4 удалений

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

@ -304,8 +304,6 @@ nsDOMStorageManager::Initialize()
// Used for temporary table flushing
rv = os->AddObserver(gStorageManager, "profile-before-change", true);
NS_ENSURE_SUCCESS(rv, rv);
rv = os->AddObserver(gStorageManager, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
NS_ENSURE_SUCCESS(rv, rv);
rv = os->AddObserver(gStorageManager, NS_DOMSTORAGE_FLUSH_TIMER_TOPIC, true);
NS_ENSURE_SUCCESS(rv, rv);
@ -329,6 +327,14 @@ nsDOMStorageManager::Shutdown()
NS_IF_RELEASE(gStorageManager);
gStorageManager = nsnull;
ShutdownDB();
}
//static
void
nsDOMStorageManager::ShutdownDB()
{
DOMStorageImpl::gStorageDB->Close();
delete DOMStorageImpl::gStorageDB;
DOMStorageImpl::gStorageDB = nsnull;
}
@ -484,13 +490,13 @@ nsDOMStorageManager::Observe(nsISupports *aSubject,
NS_ENSURE_SUCCESS(rv, rv);
DOMStorageImpl::gStorageDB->RemoveOwner(aceDomain, true);
} else if (!strcmp(aTopic, "profile-before-change") ||
!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
} else if (!strcmp(aTopic, "profile-before-change")) {
if (DOMStorageImpl::gStorageDB) {
DebugOnly<nsresult> rv =
DOMStorageImpl::gStorageDB->FlushAndDeleteTemporaryTables(true);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"DOMStorage: temporary table commit failed");
nsDOMStorageManager::ShutdownDB();
}
} else if (!strcmp(aTopic, NS_DOMSTORAGE_FLUSH_TIMER_TOPIC)) {
if (DOMStorageImpl::gStorageDB) {

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

@ -129,6 +129,7 @@ public:
static nsresult Initialize();
static nsDOMStorageManager* GetInstance();
static void Shutdown();
static void ShutdownDB();
/**
* Checks whether there is any data waiting to be flushed from a temp table.

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

@ -78,6 +78,13 @@ nsDOMStorageDBWrapper::~nsDOMStorageDBWrapper()
{
}
void
nsDOMStorageDBWrapper::Close()
{
mPersistentDB.Close();
mChromePersistentDB.Close();
}
nsresult
nsDOMStorageDBWrapper::Init()
{

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

@ -89,6 +89,11 @@ public:
nsDOMStorageDBWrapper();
~nsDOMStorageDBWrapper();
/**
* Close the connections, finalizing all the cached statements.
*/
void Close();
nsresult
Init();

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

@ -54,6 +54,8 @@
#include "mozIStorageFunction.h"
#include "nsNetUtil.h"
using namespace mozilla;
// Temporary tables for a storage scope will be flushed if found older
// then this time in seconds since the load
#define TEMP_TABLE_MAX_AGE (10) // seconds
@ -447,6 +449,28 @@ nsDOMStoragePersistentDB::Init(const nsString& aDatabaseName)
return NS_OK;
}
void
nsDOMStoragePersistentDB::Close()
{
// Null the statements, this will finalize them.
mCopyToTempTableStatement = nsnull;
mCopyBackToDiskStatement = nsnull;
mDeleteTemporaryTableStatement = nsnull;
mGetAllKeysStatement = nsnull;
mGetKeyValueStatement = nsnull;
mInsertKeyStatement = nsnull;
mSetSecureStatement = nsnull;
mRemoveKeyStatement = nsnull;
mRemoveOwnerStatement = nsnull;
mRemoveStorageStatement = nsnull;
mRemoveAllStatement = nsnull;
mGetOfflineExcludedUsageStatement = nsnull;
mGetFullUsageStatement = nsnull;
DebugOnly<nsresult> rv = mConnection->Close();
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
nsresult
nsDOMStoragePersistentDB::EnsureLoadTemporaryTableForStorage(DOMStorageImpl* aStorage)
{

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

@ -62,6 +62,12 @@ public:
nsresult
Init(const nsString& aDatabaseName);
/**
* Close the connection, finalizing all the cached statements.
*/
void
Close();
/**
* Retrieve a list of all the keys associated with a particular domain.
*/
@ -199,6 +205,7 @@ protected:
nsCOMPtr<mozIStorageStatement> mRemoveAllStatement;
nsCOMPtr<mozIStorageStatement> mGetOfflineExcludedUsageStatement;
nsCOMPtr<mozIStorageStatement> mGetFullUsageStatement;
// If you add an statement, remember to null in in Close.
nsCString mCachedOwner;
PRInt32 mCachedUsage;