--- a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
@@ -1419,18 +1419,16 @@ nsUrlClassifierDBServiceWorker::AddChunk
PRIntervalTime clockStart = 0;
if (LOG_ENABLED()) {
clockStart = PR_IntervalNow();
}
#endif
LOG(("Adding %d entries to chunk %d", entries.Length(), chunkNum));
- mozStorageTransaction transaction(mConnection, PR_FALSE);
-
nsCAutoString addChunks;
nsCAutoString subChunks;
HandlePendingLookups();
nsresult rv = GetChunkLists(tableId, addChunks, subChunks);
NS_ENSURE_SUCCESS(rv, rv);
@@ -1475,38 +1473,31 @@ nsUrlClassifierDBServiceWorker::AddChunk
reinterpret_cast<PRUint8*>(entryIDs.Elements()),
entryIDs.Length() * sizeof(PRUint32));
HandlePendingLookups();
rv = mAddChunkEntriesStatement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
- HandlePendingLookups();
-
- rv = transaction.Commit();
- NS_ENSURE_SUCCESS(rv, rv);
-
#if defined(PR_LOGGING)
if (LOG_ENABLED()) {
PRIntervalTime clockEnd = PR_IntervalNow();
printf("adding chunk %d took %dms\n", chunkNum,
PR_IntervalToMilliseconds(clockEnd - clockStart));
}
#endif
return rv;
}
nsresult
nsUrlClassifierDBServiceWorker::ExpireAdd(PRUint32 tableId,
PRUint32 chunkNum)
{
- mozStorageTransaction transaction(mConnection, PR_FALSE);
-
LOG(("Expiring chunk %d\n", chunkNum));
nsCAutoString addChunks;
nsCAutoString subChunks;
HandlePendingLookups();
nsresult rv = GetChunkLists(tableId, addChunks, subChunks);
@@ -1560,28 +1551,24 @@ nsUrlClassifierDBServiceWorker::ExpireAd
HandlePendingLookups();
mozStorageStatementScoper removeScoper(mDeleteChunkEntriesStatement);
mDeleteChunkEntriesStatement->BindInt32Parameter(0, tableId);
mDeleteChunkEntriesStatement->BindInt32Parameter(1, chunkNum);
rv = mDeleteChunkEntriesStatement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
- HandlePendingLookups();
-
- return transaction.Commit();
+ return NS_OK;
}
nsresult
nsUrlClassifierDBServiceWorker::SubChunk(PRUint32 tableId,
PRUint32 chunkNum,
nsTArray<nsUrlClassifierEntry>& entries)
{
- mozStorageTransaction transaction(mConnection, PR_FALSE);
-
nsCAutoString addChunks;
nsCAutoString subChunks;
HandlePendingLookups();
nsresult rv = GetChunkLists(tableId, addChunks, subChunks);
NS_ENSURE_SUCCESS(rv, rv);
@@ -1605,44 +1592,38 @@ nsUrlClassifierDBServiceWorker::SubChunk
return NS_ERROR_FAILURE;
HandlePendingLookups();
rv = WriteEntry(existingEntry);
NS_ENSURE_SUCCESS(rv, rv);
}
- HandlePendingLookups();
-
- return transaction.Commit();
+ return NS_OK;
}
nsresult
nsUrlClassifierDBServiceWorker::ExpireSub(PRUint32 tableId, PRUint32 chunkNum)
{
- mozStorageTransaction transaction(mConnection, PR_FALSE);
-
nsCAutoString addChunks;
nsCAutoString subChunks;
HandlePendingLookups();
nsresult rv = GetChunkLists(tableId, addChunks, subChunks);
NS_ENSURE_SUCCESS(rv, rv);
nsTArray<PRUint32> subs;
ParseChunkList(subChunks, subs);
subs.RemoveElement(chunkNum);
JoinChunkList(subs, subChunks);
rv = SetChunkLists(tableId, addChunks, subChunks);
NS_ENSURE_SUCCESS(rv, rv);
- HandlePendingLookups();
-
- return transaction.Commit();
+ return NS_OK;
}
nsresult
nsUrlClassifierDBServiceWorker::ProcessChunk(PRBool* done)
{
// wait until the chunk plus terminating \n has been read
if (mPendingStreamUpdate.Length() <= static_cast<PRUint32>(mChunkLen)) {
*done = PR_TRUE;
@@ -1815,16 +1796,26 @@ nsUrlClassifierDBServiceWorker::Update(c
return NS_ERROR_FAILURE;
}
// if something has gone wrong during this update, just throw it away
if (NS_FAILED(mUpdateStatus)) {
return mUpdateStatus;
}
+ PRBool transaction;
+ if (NS_SUCCEEDED(mConnection->GetTransactionInProgress(&transaction)) &&
+ !transaction) {
+ rv = mConnection->BeginTransaction();
+ if (NS_FAILED(rv)) {
+ mUpdateStatus = rv;
+ return rv;
+ }
+ }
+
LOG(("Got %s\n", PromiseFlatCString(chunk).get()));
mPendingStreamUpdate.Append(chunk);
PRBool done = PR_FALSE;
while (!done) {
if (mState == STATE_CHUNK) {
rv = ProcessChunk(&done);
@@ -1841,16 +1832,22 @@ nsUrlClassifierDBServiceWorker::Update(c
}
NS_IMETHODIMP
nsUrlClassifierDBServiceWorker::Finish(nsIUrlClassifierCallback* aSuccessCallback,
nsIUrlClassifierCallback* aErrorCallback)
{
nsCAutoString arg;
if (NS_SUCCEEDED(mUpdateStatus)) {
+ mUpdateStatus = mConnection->CommitTransaction();
+ } else {
+ mConnection->RollbackTransaction();
+ }
+
+ if (NS_SUCCEEDED(mUpdateStatus)) {
arg.AppendInt(mUpdateWait);
aSuccessCallback->HandleEvent(arg);
} else {
arg.AppendInt(mUpdateStatus);
aErrorCallback->HandleEvent(arg);
}
ResetUpdate();