Bug 398218 - Download DB tracks -1 as the max size when resuming. r=sdwilsh, a=mconnor
authoredward.lee@engineering.uiuc.edu
Tue, 02 Oct 2007 08:08:12 -0700
changeset 6542 7bc34113bf3b2abf798f93ced77a0b06ea05ba2a
parent 6541 c273a3fed3b76405861d4c63a27c540e4b39d3a8
child 6543 b3051cb089b6ba415503f84d9bde680746394d09
push idunknown
push userunknown
push dateunknown
reviewerssdwilsh, mconnor
bugs398218
milestone1.9a9pre
Bug 398218 - Download DB tracks -1 as the max size when resuming. r=sdwilsh, a=mconnor
toolkit/components/downloads/src/nsDownloadManager.cpp
--- a/toolkit/components/downloads/src/nsDownloadManager.cpp
+++ b/toolkit/components/downloads/src/nsDownloadManager.cpp
@@ -820,17 +820,19 @@ nsDownloadManager::GetDownloadFromDB(PRU
   if (NS_SUCCEEDED(rv) && !referrer.IsEmpty()) {
     rv = NS_NewURI(getter_AddRefs(dl->mReferrer), referrer);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   rv = stmt->GetUTF8String(i++, dl->mEntityID);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  dl->SetProgressBytes(stmt->AsInt64(i++), stmt->AsInt64(i++));
+  PRInt64 currBytes = stmt->AsInt64(i++);
+  PRInt64 maxBytes = stmt->AsInt64(i++);
+  dl->SetProgressBytes(currBytes, maxBytes);
 
   // Addrefing and returning
   NS_ADDREF(*retVal = dl);
   return NS_OK;
 }
 
 nsresult
 nsDownloadManager::AddToCurrentDownloads(nsDownload *aDl)
@@ -2189,20 +2191,22 @@ nsDownload::RealResume()
 
   // Set the channel to resume at the right position along with the entityID
   nsCOMPtr<nsIResumableChannel> resumableChannel(do_QueryInterface(channel));
   if (!resumableChannel)
     return NS_ERROR_UNEXPECTED;
   rv = resumableChannel->ResumeAt(fileSize, mEntityID);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  // If we know the max size, we know what it should be when resuming
+  PRInt64 maxBytes;
+  GetSize(&maxBytes);
+  SetProgressBytes(0, maxBytes != -1 ? maxBytes - fileSize : -1);
   // Track where we resumed because progress notifications restart at 0
   mResumedAt = fileSize;
-  mCurrBytes = 0;
-  mMaxBytes = -1;
 
   // Set the referrer
   if (mReferrer) {
     nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
     if (httpChannel) {
       rv = httpChannel->SetReferrer(mReferrer);
       NS_ENSURE_SUCCESS(rv, rv);
     }