Bug 559682 - Ensure we create a valid transaction in batches before trying to commit it. r=sdwilsh

This commit is contained in:
Marco Bonardo 2010-04-16 14:31:21 +02:00
parent 7a4702f9fa
commit 9edfc53e75
4 changed files with 24 additions and 29 deletions

View File

@ -106,7 +106,7 @@ nsNavBookmarks::nsNavBookmarks() : mItemCount(0)
, mTagRoot(0)
, mToolbarFolder(0)
, mBatchLevel(0)
, mBatchHasTransaction(PR_FALSE)
, mBatchDBTransaction(nsnull)
, mCanNotify(false)
, mCacheObservers("bookmark-observers")
, mShuttingDown(false)
@ -2907,12 +2907,7 @@ nsresult
nsNavBookmarks::BeginUpdateBatch()
{
if (mBatchLevel++ == 0) {
mozIStorageConnection* conn = mDBConn;
PRBool transactionInProgress = PR_TRUE; // default to no transaction on err
conn->GetTransactionInProgress(&transactionInProgress);
mBatchHasTransaction = ! transactionInProgress;
if (mBatchHasTransaction)
conn->BeginTransaction();
mBatchDBTransaction = new mozStorageTransaction(mDBConn, PR_FALSE);
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
nsINavBookmarkObserver, OnBeginUpdateBatch());
@ -2925,9 +2920,13 @@ nsresult
nsNavBookmarks::EndUpdateBatch()
{
if (--mBatchLevel == 0) {
if (mBatchHasTransaction)
mDBConn->CommitTransaction();
mBatchHasTransaction = PR_FALSE;
if (mBatchDBTransaction) {
nsresult rv = mBatchDBTransaction->Commit();
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Batch failed to commit transaction");
delete mBatchDBTransaction;
mBatchDBTransaction = nsnull;
}
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
nsINavBookmarkObserver, OnEndUpdateBatch());
}

View File

@ -234,12 +234,10 @@ private:
// personal toolbar folder
PRInt64 mToolbarFolder;
// the level of nesting of batches, 0 when no batches are open
// The level of batches' nesting, 0 when no batches are open.
PRInt32 mBatchLevel;
// true if the outermost batch has an associated transaction that should
// be committed when our batch level reaches 0 again.
PRBool mBatchHasTransaction;
// Current active transaction for a batch.
mozStorageTransaction* mBatchDBTransaction;
nsresult GetParentAndIndexOfFolder(PRInt64 aFolder,
PRInt64* aParent,

View File

@ -385,7 +385,7 @@ PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsNavHistory, gHistoryService)
nsNavHistory::nsNavHistory()
: mBatchLevel(0)
, mBatchHasTransaction(PR_FALSE)
, mBatchDBTransaction(nsnull)
, mCachedNow(0)
, mExpireNowTimer(nsnull)
, mLastSessionID(0)
@ -4284,11 +4284,7 @@ nsresult
nsNavHistory::BeginUpdateBatch()
{
if (mBatchLevel++ == 0) {
PRBool transactionInProgress = PR_TRUE; // default to no transaction on err
mDBConn->GetTransactionInProgress(&transactionInProgress);
mBatchHasTransaction = ! transactionInProgress;
if (mBatchHasTransaction)
mDBConn->BeginTransaction();
mBatchDBTransaction = new mozStorageTransaction(mDBConn, PR_FALSE);
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
nsINavHistoryObserver, OnBeginUpdateBatch());
@ -4301,9 +4297,13 @@ nsresult
nsNavHistory::EndUpdateBatch()
{
if (--mBatchLevel == 0) {
if (mBatchHasTransaction)
mDBConn->CommitTransaction();
mBatchHasTransaction = PR_FALSE;
if (mBatchDBTransaction) {
nsresult rv = mBatchDBTransaction->Commit();
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Batch failed to commit transaction");
delete mBatchDBTransaction;
mBatchDBTransaction = nsnull;
}
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
nsINavHistoryObserver, OnEndUpdateBatch());
}

View File

@ -313,12 +313,10 @@ public:
nsresult BeginUpdateBatch();
nsresult EndUpdateBatch();
// the level of nesting of batches, 0 when no batches are open
// The level of batches' nesting, 0 when no batches are open.
PRInt32 mBatchLevel;
// true if the outermost batch has an associated transaction that should
// be committed when our batch level reaches 0 again.
PRBool mBatchHasTransaction;
// Current active transaction for a batch.
mozStorageTransaction* mBatchDBTransaction;
// better alternative to QueryStringToQueries (in nsNavHistoryQuery.cpp)
nsresult QueryStringToQueryArray(const nsACString& aQueryString,