diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /storage/mozStorageConnection.cpp | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'storage/mozStorageConnection.cpp')
-rw-r--r-- | storage/mozStorageConnection.cpp | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/storage/mozStorageConnection.cpp b/storage/mozStorageConnection.cpp index 3e298d0d82..b0d55b71a5 100644 --- a/storage/mozStorageConnection.cpp +++ b/storage/mozStorageConnection.cpp @@ -606,12 +606,15 @@ class AsyncBackupDatabaseFile final : public Runnable, public nsITimerCallback { */ AsyncBackupDatabaseFile(Connection* aConnection, sqlite3* aNativeConnection, nsIFile* aDestinationFile, - mozIStorageCompletionCallback* aCallback) + mozIStorageCompletionCallback* aCallback, + int32_t aPagesPerStep, uint32_t aStepDelayMs) : Runnable("storage::AsyncBackupDatabaseFile"), mConnection(aConnection), mNativeConnection(aNativeConnection), mDestinationFile(aDestinationFile), mCallback(aCallback), + mPagesPerStep(aPagesPerStep), + mStepDelayMs(aStepDelayMs), mBackupFile(nullptr), mBackupHandle(nullptr) { MOZ_ASSERT(NS_IsMainThread()); @@ -681,19 +684,14 @@ class AsyncBackupDatabaseFile final : public Runnable, public nsITimerCallback { rv = file->InitWithPath(tempPath); DISPATCH_AND_RETURN_IF_FAILED(rv); - // The number of milliseconds to wait between each batch of copies. - static constexpr uint32_t STEP_DELAY_MS = 250; - // The number of pages to copy per step - static constexpr int COPY_PAGES = 5; - - int srv = ::sqlite3_backup_step(mBackupHandle, COPY_PAGES); + int srv = ::sqlite3_backup_step(mBackupHandle, mPagesPerStep); if (srv == SQLITE_OK || srv == SQLITE_BUSY || srv == SQLITE_LOCKED) { // We're continuing the backup later. Release the guard to avoid closing // the database. guard.release(); // Queue up the next step - return NS_NewTimerWithCallback(getter_AddRefs(mTimer), this, - STEP_DELAY_MS, nsITimer::TYPE_ONE_SHOT, + return NS_NewTimerWithCallback(getter_AddRefs(mTimer), this, mStepDelayMs, + nsITimer::TYPE_ONE_SHOT, GetCurrentSerialEventTarget()); } #ifdef DEBUG @@ -771,6 +769,8 @@ class AsyncBackupDatabaseFile final : public Runnable, public nsITimerCallback { nsCOMPtr<nsITimer> mTimer; nsCOMPtr<nsIFile> mDestinationFile; nsCOMPtr<mozIStorageCompletionCallback> mCallback; + int32_t mPagesPerStep; + uint32_t mStepDelayMs; sqlite3* mBackupFile; sqlite3_backup* mBackupHandle; }; @@ -2962,7 +2962,8 @@ uint32_t Connection::DecreaseTransactionNestingLevel( NS_IMETHODIMP Connection::BackupToFileAsync(nsIFile* aDestinationFile, - mozIStorageCompletionCallback* aCallback) { + mozIStorageCompletionCallback* aCallback, + uint32_t aPagesPerStep, uint32_t aStepDelayMs) { NS_ENSURE_ARG(aDestinationFile); NS_ENSURE_ARG(aCallback); NS_ENSURE_TRUE(NS_IsMainThread(), NS_ERROR_NOT_SAME_THREAD); @@ -2984,9 +2985,28 @@ Connection::BackupToFileAsync(nsIFile* aDestinationFile, return NS_ERROR_NOT_INITIALIZED; } + // The number of pages of the database to copy per step + static constexpr int32_t DEFAULT_PAGES_PER_STEP = 5; + // The number of milliseconds to wait between each step. + static constexpr uint32_t DEFAULT_STEP_DELAY_MS = 250; + + CheckedInt<int32_t> pagesPerStep(aPagesPerStep); + if (!pagesPerStep.isValid()) { + return NS_ERROR_INVALID_ARG; + } + + if (!pagesPerStep.value()) { + pagesPerStep = DEFAULT_PAGES_PER_STEP; + } + + if (!aStepDelayMs) { + aStepDelayMs = DEFAULT_STEP_DELAY_MS; + } + // Create and dispatch our backup event to the execution thread. nsCOMPtr<nsIRunnable> backupEvent = - new AsyncBackupDatabaseFile(this, mDBConn, aDestinationFile, aCallback); + new AsyncBackupDatabaseFile(this, mDBConn, aDestinationFile, aCallback, + pagesPerStep.value(), aStepDelayMs); rv = asyncThread->Dispatch(backupEvent, NS_DISPATCH_NORMAL); return rv; } |