Bug 396450 - Move logic out of nsDownloadManager.h. Patch by Edward Lee <edilee@gmail.com>. r=sdwilsh, a=mconnor

This commit is contained in:
sdwilsh@shawnwilsher.com 2007-09-17 14:02:39 -07:00
Родитель e66675cbb7
Коммит a29c041492
2 изменённых файлов: 40 добавлений и 29 удалений

Просмотреть файл

@ -831,6 +831,15 @@ nsDownloadManager::GetDownloadFromDB(PRUint32 aID, nsDownload **retVal)
return NS_OK;
}
nsresult
nsDownloadManager::AddToCurrentDownloads(nsDownload *aDl)
{
if (!mCurrentDownloads.AppendObject(aDl))
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
void
nsDownloadManager::SendEvent(nsDownload *aDownload, const char *aTopic)
{
@ -1126,7 +1135,7 @@ nsDownloadManager::CancelDownload(PRUint32 aID)
return NS_ERROR_FAILURE;
// Don't cancel if download is already finished
if (CompletedSuccessfully(dl->mDownloadState))
if (dl->IsFinished())
return NS_OK;
// if the download is paused, we have to resume it so we can cancel it
@ -1876,7 +1885,7 @@ nsDownload::OnStateChange(nsIWebProgress *aWebProgress,
}
}
} else if (aStateFlags & STATE_STOP) {
if (nsDownloadManager::IsInFinalStage(mDownloadState)) {
if (IsFinishable()) {
// Set file size at the end of a transfer (for unknown transfer amounts)
if (mMaxBytes == LL_MAXUINT)
mMaxBytes = mCurrBytes;
@ -2133,6 +2142,20 @@ nsDownload::PauseResume(PRBool aPause)
return SetState(nsIDownloadManager::DOWNLOAD_DOWNLOADING);
}
PRBool
nsDownload::IsFinishable()
{
return mDownloadState == nsIDownloadManager::DOWNLOAD_NOTSTARTED ||
mDownloadState == nsIDownloadManager::DOWNLOAD_QUEUED ||
mDownloadState == nsIDownloadManager::DOWNLOAD_DOWNLOADING;
}
PRBool
nsDownload::IsFinished()
{
return mDownloadState == nsIDownloadManager::DOWNLOAD_FINISHED;
}
nsresult
nsDownload::UpdateDB()
{

Просмотреть файл

@ -101,13 +101,11 @@ protected:
nsresult RestoreDatabaseState();
nsresult GetDownloadFromDB(PRUint32 aID, nsDownload **retVal);
inline nsresult AddToCurrentDownloads(nsDownload *aDl)
{
if (!mCurrentDownloads.AppendObject(aDl))
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
/**
* Specially track the active downloads so that we don't need to check
* every download to see if they're in progress.
*/
nsresult AddToCurrentDownloads(nsDownload *aDl);
void SendEvent(nsDownload *aDownload, const char *aTopic);
@ -160,26 +158,6 @@ protected:
PRInt32 GetRetentionBehavior();
nsresult ExecuteDesiredAction(nsDownload *aDownload);
static PRBool IsInFinalStage(DownloadState aState)
{
return aState == nsIDownloadManager::DOWNLOAD_NOTSTARTED ||
aState == nsIDownloadManager::DOWNLOAD_QUEUED ||
aState == nsIDownloadManager::DOWNLOAD_DOWNLOADING;
}
static PRBool IsInProgress(DownloadState aState)
{
return aState == nsIDownloadManager::DOWNLOAD_NOTSTARTED ||
aState == nsIDownloadManager::DOWNLOAD_QUEUED ||
aState == nsIDownloadManager::DOWNLOAD_DOWNLOADING ||
aState == nsIDownloadManager::DOWNLOAD_PAUSED;
}
static PRBool CompletedSuccessfully(DownloadState aState)
{
return aState == nsIDownloadManager::DOWNLOAD_FINISHED;
}
private:
nsCOMArray<nsIDownloadProgressListener> mListeners;
nsCOMPtr<nsIStringBundle> mBundle;
@ -223,6 +201,16 @@ protected:
nsresult PauseResume(PRBool aPause);
/**
* Download is in a state to stop and complete the download?
*/
PRBool IsFinishable();
/**
* Download is totally done transferring and all?
*/
PRBool IsFinished();
nsDownloadManager *mDownloadManager;
nsCOMPtr<nsIURI> mTarget;