зеркало из https://github.com/mozilla/gecko-dev.git
bug 239006: Download manager doesn't account for filesize when presenting combined percentages
patch by Zbigniew Braniecki <gandalf@firefox.pl>, r=cbiesinger, sr=darin
This commit is contained in:
Родитель
93740d70c0
Коммит
16bf0830c2
|
@ -141,6 +141,21 @@ nsDownloadListener::GetPercentComplete(PRInt32 *aPercentComplete)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* readonly attribute PRUint64 amountTransferred; */
|
||||
NS_IMETHODIMP
|
||||
nsDownloadListener::GetAmountTransferred(PRUint64 *aAmountTransferred)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* readonly attribute PRUint64 size; */
|
||||
NS_IMETHODIMP
|
||||
nsDownloadListener::GetSize(PRUint64 *aSize)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
/* attribute wstring displayName; */
|
||||
NS_IMETHODIMP
|
||||
nsDownloadListener::GetDisplayName(PRUnichar * *aDisplayName)
|
||||
|
|
|
@ -120,6 +120,20 @@ nsDownloadListener::GetPercentComplete(PRInt32 *aPercentComplete)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* readonly attribute PRUint64 amountTransferred; */
|
||||
NS_IMETHODIMP
|
||||
nsDownloadListener::GetAmountTransferred(PRUint64 *aAmountTransferred)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* readonly attribute PRUint64 size; */
|
||||
NS_IMETHODIMP
|
||||
nsDownloadListener::GetSize(PRUint64 *aSize)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* attribute wstring displayName; */
|
||||
NS_IMETHODIMP
|
||||
nsDownloadListener::GetDisplayName(PRUnichar * *aDisplayName)
|
||||
|
|
|
@ -972,7 +972,7 @@ nsDownloadManager::ValidateDownloadsContainer()
|
|||
// Now Remove all the bad downloads.
|
||||
PRUint32 cnt;
|
||||
ary->Count(&cnt);
|
||||
for (PRInt32 i = 0; i < cnt; ++i) {
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsCOMPtr<nsIRDFResource> download(do_QueryElementAt(ary, i));
|
||||
|
||||
// Use the internal method because we know what we're doing! (We hope!)
|
||||
|
@ -1042,7 +1042,10 @@ nsDownloadManager::PauseResumeDownload(const PRUnichar* aPath, PRBool aPause)
|
|||
// Update download state in the DataSource
|
||||
nsCOMPtr<nsIRDFInt> intLiteral;
|
||||
|
||||
gRDFService->GetIntLiteral(aPause ? nsIDownloadManager::DOWNLOAD_PAUSED : nsIDownloadManager::DOWNLOAD_DOWNLOADING, getter_AddRefs(intLiteral));
|
||||
gRDFService->GetIntLiteral(
|
||||
aPause ?
|
||||
(PRInt32)nsIDownloadManager::DOWNLOAD_PAUSED :
|
||||
(PRInt32)nsIDownloadManager::DOWNLOAD_DOWNLOADING, getter_AddRefs(intLiteral));
|
||||
|
||||
nsCOMPtr<nsIRDFResource> res;
|
||||
gRDFService->GetUnicodeResource(nsDependentString(aPath), getter_AddRefs(res));
|
||||
|
@ -1285,7 +1288,7 @@ nsDownloadManager::Observe(nsISupports* aSubject, const char* aTopic, const PRUn
|
|||
// Now Remove all the downloads.
|
||||
PRUint32 cnt;
|
||||
ary->Count(&cnt);
|
||||
for (PRInt32 i = 0; i < cnt; ++i) {
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsCOMPtr<nsIRDFResource> download(do_QueryElementAt(ary, i));
|
||||
// Here we use the internal RemoveDownload method, and only here
|
||||
// because this is _after_ the download table |mCurrDownloads| has been
|
||||
|
@ -2216,6 +2219,20 @@ nsDownload::GetPercentComplete(PRInt32* aPercentComplete)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::GetAmountTransferred(PRUint64* aAmountTransferred)
|
||||
{
|
||||
*aAmountTransferred = mCurrBytes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::GetSize(PRUint64* aSize)
|
||||
{
|
||||
*aSize = mMaxBytes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::SetListener(nsIWebProgressListener* aListener)
|
||||
{
|
||||
|
|
|
@ -247,8 +247,8 @@ private:
|
|||
|
||||
PRBool mPaused;
|
||||
PRInt32 mPercentComplete;
|
||||
PRInt32 mCurrBytes;
|
||||
PRInt32 mMaxBytes;
|
||||
PRUint64 mCurrBytes;
|
||||
PRUint64 mMaxBytes;
|
||||
PRInt64 mStartTime;
|
||||
PRTime mLastUpdate;
|
||||
|
||||
|
|
|
@ -136,7 +136,17 @@ public:
|
|||
{
|
||||
return mInner->GetPercentComplete(aPercentComplete);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP GetAmountTransferred(PRUint64* aAmountTransferred)
|
||||
{
|
||||
return mInner->GetAmountTransferred(aAmountTransferred);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetSize(PRUint64* aSize)
|
||||
{
|
||||
return mInner->GetSize(aSize);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetListener(nsIWebProgressListener** aListener)
|
||||
{
|
||||
return mInner->GetListener(aListener);
|
||||
|
|
|
@ -405,35 +405,41 @@ function onDownloadRetry(aEvent)
|
|||
|
||||
// This is called by the progress listener. We don't actually use the event
|
||||
// system here to minimize time wastage.
|
||||
var gLastComputedMean = 0;
|
||||
var gLastComputedMean = -1;
|
||||
function onUpdateProgress()
|
||||
{
|
||||
var numActiveDownloads = gActiveDownloads.length;
|
||||
if (numActiveDownloads == 0) {
|
||||
document.title = document.documentElement.getAttribute("statictitle");
|
||||
gLastComputedMean = 0;
|
||||
gLastComputedMean = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
var mean = 0;
|
||||
var base = 0;
|
||||
var dl = null;
|
||||
for (var i = 0; i < numActiveDownloads; ++i) {
|
||||
var dl = gActiveDownloads[i];
|
||||
var progress = dl.percentComplete;
|
||||
if (progress < 100)
|
||||
mean += progress;
|
||||
dl = gActiveDownloads[i];
|
||||
|
||||
// gActiveDownloads is screwed so it's possible
|
||||
// to have more files than we're really downloading.
|
||||
// The good news is that those files have size==0.
|
||||
// Same with files with unknown size. Their size==0.
|
||||
if (dl.percentComplete < 100 && dl.size > 0) {
|
||||
mean += dl.amountTransferred;
|
||||
base += dl.size;
|
||||
}
|
||||
}
|
||||
|
||||
mean = Math.round(mean / numActiveDownloads);
|
||||
|
||||
// At the end of a download, progress is set from 100% to 0% for
|
||||
// some reason. We can identify this case because at this point the
|
||||
// mean progress will be zero but the last computed mean will be
|
||||
// greater than zero.
|
||||
if (mean == 0 && gLastComputedMean > 0) {
|
||||
document.title = document.documentElement.getAttribute("statictitle");
|
||||
return;
|
||||
// we're not downloading anything at the moment,
|
||||
// but we already downloaded something.
|
||||
if (base == 0) {
|
||||
mean = 100;
|
||||
} else {
|
||||
mean = Math.floor((mean / base) * 100);
|
||||
}
|
||||
if (mean != gLastComputedMean) {
|
||||
|
||||
if (gLastComputedMean == -1 || mean != gLastComputedMean) {
|
||||
gLastComputedMean = mean;
|
||||
var strings = document.getElementById("downloadStrings");
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ interface nsIWebBrowserPersist;
|
|||
interface nsIWebProgressListener;
|
||||
interface nsIMIMEInfo;
|
||||
|
||||
[scriptable, uuid(d80095a7-e81c-464c-a13f-ecb84feb969f)]
|
||||
[scriptable, uuid(6ce8aba0-b159-411a-b14e-d1ae80b6aa9d)]
|
||||
interface nsITransfer : nsISupports {
|
||||
|
||||
/**
|
||||
|
@ -95,11 +95,6 @@ interface nsITransfer : nsISupports {
|
|||
* is being used.
|
||||
*/
|
||||
readonly attribute nsIWebBrowserPersist persist;
|
||||
|
||||
/**
|
||||
* The percentage of transfer completed;
|
||||
*/
|
||||
readonly attribute PRInt32 percentComplete;
|
||||
|
||||
/**
|
||||
* The user-readable description of the transfer.
|
||||
|
@ -131,13 +126,30 @@ interface nsITransfer : nsISupports {
|
|||
attribute nsIObserver observer;
|
||||
};
|
||||
|
||||
[scriptable, uuid(b0aae798-78aa-4769-9f0e-9aef4cf9474d)]
|
||||
[scriptable, uuid(0332d825-f3dd-4f15-abaa-e2958d396a52)]
|
||||
interface nsIDownload : nsITransfer {
|
||||
|
||||
/**
|
||||
* The target of a download is always a file on the local file system.
|
||||
*/
|
||||
readonly attribute nsILocalFile targetFile;
|
||||
|
||||
/**
|
||||
* The percentage of transfer completed.
|
||||
* If the file size is unknown it'll be -1 here.
|
||||
*/
|
||||
readonly attribute PRInt32 percentComplete;
|
||||
|
||||
/**
|
||||
* The amount of kbytes downloaded so far.
|
||||
*/
|
||||
readonly attribute PRUint64 amountTransferred;
|
||||
|
||||
/**
|
||||
* The size of file in kbytes.
|
||||
* Unknown size is represented by 0.
|
||||
*/
|
||||
readonly attribute PRUint64 size;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
|
@ -1358,6 +1358,20 @@ nsDownload::GetPercentComplete(PRInt32* aPercentComplete)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::GetAmountTransferred(PRUint64* aAmountTransferred)
|
||||
{
|
||||
*aAmountTransferred = mCurrBytes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::GetSize(PRUint64* aSize)
|
||||
{
|
||||
*aSize = mMaxBytes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDownload::SetListener(nsIWebProgressListener* aListener)
|
||||
{
|
||||
|
|
|
@ -176,8 +176,8 @@ private:
|
|||
DownloadState mDownloadState;
|
||||
|
||||
PRInt32 mPercentComplete;
|
||||
PRInt32 mCurrBytes;
|
||||
PRInt32 mMaxBytes;
|
||||
PRUint64 mCurrBytes;
|
||||
PRUint64 mMaxBytes;
|
||||
PRTime mStartTime;
|
||||
PRTime mLastUpdate;
|
||||
};
|
||||
|
|
|
@ -135,7 +135,17 @@ public:
|
|||
return NS_ERROR_NOT_INITIALIZED;
|
||||
return mInner->GetPercentComplete(aPercentComplete);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP GetAmountTransferred(PRUint64* aAmountTransferred)
|
||||
{
|
||||
return mInner->GetAmountTransferred(aAmountTransferred);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetSize(PRUint64* aSize)
|
||||
{
|
||||
return mInner->GetSize(aSize);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP GetListener(nsIWebProgressListener** aListener)
|
||||
{
|
||||
if (!mInner)
|
||||
|
|
Загрузка…
Ссылка в новой задаче