diff --git a/toolkit/components/places/src/nsNavBookmarks.cpp b/toolkit/components/places/src/nsNavBookmarks.cpp index a25c1840ce1a..229c3aabd4db 100644 --- a/toolkit/components/places/src/nsNavBookmarks.cpp +++ b/toolkit/components/places/src/nsNavBookmarks.cpp @@ -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()); } diff --git a/toolkit/components/places/src/nsNavBookmarks.h b/toolkit/components/places/src/nsNavBookmarks.h index 2879babfa418..f5238751f636 100644 --- a/toolkit/components/places/src/nsNavBookmarks.h +++ b/toolkit/components/places/src/nsNavBookmarks.h @@ -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, diff --git a/toolkit/components/places/src/nsNavHistory.cpp b/toolkit/components/places/src/nsNavHistory.cpp index b9e3f95d04f8..f6c98b76acb3 100644 --- a/toolkit/components/places/src/nsNavHistory.cpp +++ b/toolkit/components/places/src/nsNavHistory.cpp @@ -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()); } diff --git a/toolkit/components/places/src/nsNavHistory.h b/toolkit/components/places/src/nsNavHistory.h index 245d992b1466..54505cabd9d5 100644 --- a/toolkit/components/places/src/nsNavHistory.h +++ b/toolkit/components/places/src/nsNavHistory.h @@ -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,