From 2714bb52a3c31d1b32f7d349a182365d8585c400 Mon Sep 17 00:00:00 2001 From: "edward.lee@engineering.uiuc.edu" Date: Wed, 24 Oct 2007 15:39:05 -0700 Subject: [PATCH] Bug 399632 - Resume (not restart) a download after firefox crashes. r=sdwilsh, b-ff3=mconnor, a1.9=mconnor, aM9=mconnor --- .../downloads/src/nsDownloadManager.cpp | 40 ++----------------- .../downloads/src/nsDownloadManager.h | 3 +- 2 files changed, 6 insertions(+), 37 deletions(-) diff --git a/toolkit/components/downloads/src/nsDownloadManager.cpp b/toolkit/components/downloads/src/nsDownloadManager.cpp index 7e463d6ea11..56d9d83e8c9 100644 --- a/toolkit/components/downloads/src/nsDownloadManager.cpp +++ b/toolkit/components/downloads/src/nsDownloadManager.cpp @@ -661,46 +661,18 @@ nsDownloadManager::ImportDownloadHistory() nsresult nsDownloadManager::RestoreDatabaseState() { - // First, we get all the downloads that are supposedly active, but are not - // really because we crashed. + // Convert supposedly-active downloads into downloads that should auto-resume nsCOMPtr stmt; nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT id " - "FROM moz_downloads " - "WHERE state = ?1 " - "OR state = ?2 " - "OR state = ?3"), getter_AddRefs(stmt)); - NS_ENSURE_SUCCESS(rv, rv); - - PRInt32 i = 0; - rv = stmt->BindInt32Parameter(i++, nsIDownloadManager::DOWNLOAD_NOTSTARTED); - NS_ENSURE_SUCCESS(rv, rv); - rv = stmt->BindInt32Parameter(i++, nsIDownloadManager::DOWNLOAD_QUEUED); - NS_ENSURE_SUCCESS(rv, rv); - rv = stmt->BindInt32Parameter(i++, nsIDownloadManager::DOWNLOAD_DOWNLOADING); - NS_ENSURE_SUCCESS(rv, rv); - - // Next, we iterate through them storing them in an array - nsTArray ids; - PRBool hasResults; - while (NS_SUCCEEDED(stmt->ExecuteStep(&hasResults)) && hasResults) - (void)ids.AppendElement(stmt->AsInt32(0)); - - rv = stmt->Reset(); - NS_ENSURE_SUCCESS(rv, rv); - - // Third, change all of those downloads to a failed state so we will be able - // to retry them. - rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( "UPDATE moz_downloads " - "SET state = ?1 " + "SET autoResume = ?1 " "WHERE state = ?2 " "OR state = ?3 " "OR state = ?4"), getter_AddRefs(stmt)); NS_ENSURE_SUCCESS(rv, rv); - i = 0; - rv = stmt->BindInt32Parameter(i++, nsIDownloadManager::DOWNLOAD_FAILED); + PRInt32 i = 0; + rv = stmt->BindInt32Parameter(i++, nsDownload::AUTO_RESUME); NS_ENSURE_SUCCESS(rv, rv); rv = stmt->BindInt32Parameter(i++, nsIDownloadManager::DOWNLOAD_NOTSTARTED); NS_ENSURE_SUCCESS(rv, rv); @@ -712,10 +684,6 @@ nsDownloadManager::RestoreDatabaseState() rv = stmt->Execute(); NS_ENSURE_SUCCESS(rv, rv); - // Finally, let's retry all of those downloads - for (nsTArray::size_type i = 0; i < ids.Length(); i++) - (void)RetryDownload(ids[i]); - return NS_OK; } diff --git a/toolkit/components/downloads/src/nsDownloadManager.h b/toolkit/components/downloads/src/nsDownloadManager.h index cb7e665429e..32cd6499177 100644 --- a/toolkit/components/downloads/src/nsDownloadManager.h +++ b/toolkit/components/downloads/src/nsDownloadManager.h @@ -102,7 +102,8 @@ protected: /** * Fix up the database after a crash such as dealing with previously-active - * downloads. + * downloads. Call this before RestoreActiveDownloads to get the downloads + * fixed here to be auto-resumed. */ nsresult RestoreDatabaseState();