From 515d0e58e1816f0000151264fefefe39b5a838ef Mon Sep 17 00:00:00 2001 From: Junior Hsu Date: Thu, 8 Jun 2017 20:05:00 +0200 Subject: [PATCH] Bug 1370456 - Batch operations for nsCookieService, r=jduell --HG-- extra : rebase_source : 0a2788a1d6d8d650f1ccdcdc4c7e875e6c5aabac --- netwerk/cookie/nsCookieService.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index 0765b1a55c1a..386d8e8b063b 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -2726,6 +2726,7 @@ nsCookieService::AsyncReadComplete() NS_ASSERTION(mDefaultDBState->pendingRead, "no pending read"); NS_ASSERTION(mDefaultDBState->readListener, "no read listener"); + mozStorageTransaction transaction(mDefaultDBState->dbConn, false); // Merge the data read on the background thread with the data synchronously // read on the main thread. Note that transactions on the cookie table may // have occurred on the main thread since, making the background data stale. @@ -2740,6 +2741,8 @@ nsCookieService::AsyncReadComplete() AddCookieToList(tuple.key, tuple.cookie, mDefaultDBState, nullptr, false); } + DebugOnly rv = transaction.Commit(); + MOZ_ASSERT(NS_SUCCEEDED(rv)); mDefaultDBState->stmtReadDomain = nullptr; mDefaultDBState->pendingRead = nullptr; @@ -2864,11 +2867,14 @@ nsCookieService::EnsureReadDomain(const nsCookieKey &aKey) aKey.mOriginAttributes)); } + mozStorageTransaction transaction(mDefaultDBState->dbConn, false); // Add the cookies to the table in a single operation. This makes sure that // either all the cookies get added, or in the case of corruption, none. for (uint32_t i = 0; i < array.Length(); ++i) { AddCookieToList(aKey, array[i], mDefaultDBState, nullptr, false); } + rv = transaction.Commit(); + MOZ_ASSERT(NS_SUCCEEDED(rv)); // Add it to the hashset of read entries, so we don't read it again. mDefaultDBState->readSet.PutEntry(aKey); @@ -2956,6 +2962,7 @@ nsCookieService::EnsureReadComplete() tuple->cookie = GetCookieFromRow(stmt, attrs); } + mozStorageTransaction transaction(mDefaultDBState->dbConn, false); // Add the cookies to the table in a single operation. This makes sure that // either all the cookies get added, or in the case of corruption, none. for (uint32_t i = 0; i < array.Length(); ++i) { @@ -2963,6 +2970,8 @@ nsCookieService::EnsureReadComplete() AddCookieToList(tuple.key, tuple.cookie, mDefaultDBState, nullptr, false); } + rv = transaction.Commit(); + MOZ_ASSERT(NS_SUCCEEDED(rv)); mDefaultDBState->syncConn = nullptr; mDefaultDBState->readSet.Clear(); @@ -4899,6 +4908,7 @@ nsCookieService::RemoveCookiesWithOriginAttributes( return NS_ERROR_NOT_AVAILABLE; } + mozStorageTransaction transaction(mDBState->dbConn, false); // Iterate the hash table of nsCookieEntry. for (auto iter = mDBState->hostTable.Iter(); !iter.Done(); iter.Next()) { nsCookieEntry* entry = iter.Get(); @@ -4931,6 +4941,8 @@ nsCookieService::RemoveCookiesWithOriginAttributes( NS_ENSURE_SUCCESS(rv, rv); } } + DebugOnly rv = transaction.Commit(); + MOZ_ASSERT(NS_SUCCEEDED(rv)); return NS_OK; }