Bug 819971 - Expose nsOfflineCacheUpdate::Cancel() via nsIOfflineCacheUpdate.idl; r=honzab
This commit is contained in:
@@ -324,6 +324,12 @@ OfflineCacheUpdateChild::AddDynamicURI(nsIURI *aURI)
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
OfflineCacheUpdateChild::Cancel()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
OfflineCacheUpdateChild::AddObserver(nsIOfflineCacheUpdateObserver *aObserver,
|
||||
bool aHoldWeak)
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace docshell {
|
||||
NS_IMETHOD AddDynamicURI(nsIURI *aURI) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddDynamicURI(aURI); } \
|
||||
NS_IMETHOD AddObserver(nsIOfflineCacheUpdateObserver *aObserver, bool aHoldWeak) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddObserver(aObserver, aHoldWeak); } \
|
||||
NS_IMETHOD RemoveObserver(nsIOfflineCacheUpdateObserver *aObserver) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveObserver(aObserver); } \
|
||||
NS_IMETHOD GetByteProgress(uint64_t * _result) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetByteProgress(_result); }
|
||||
NS_IMETHOD GetByteProgress(uint64_t * _result) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetByteProgress(_result); } \
|
||||
NS_IMETHOD Cancel() { return !_to ? NS_ERROR_NULL_POINTER : _to->Cancel(); }
|
||||
|
||||
class OfflineCacheUpdateGlue MOZ_FINAL : public nsSupportsWeakReference
|
||||
, public nsIOfflineCacheUpdate
|
||||
|
||||
@@ -63,7 +63,7 @@ interface nsIOfflineCacheUpdateObserver : nsISupports {
|
||||
* load its items one by one, sending itemCompleted() to any registered
|
||||
* observers.
|
||||
*/
|
||||
[scriptable, uuid(91b94446-5d91-4089-bed7-edfab25824a7)]
|
||||
[scriptable, uuid(a4503a53-6ab8-4b50-b01e-1c4f393fc980)]
|
||||
interface nsIOfflineCacheUpdate : nsISupports {
|
||||
/**
|
||||
* Fetch the status of the running update. This will return a value
|
||||
@@ -184,6 +184,13 @@ interface nsIOfflineCacheUpdate : nsISupports {
|
||||
*/
|
||||
void removeObserver(in nsIOfflineCacheUpdateObserver aObserver);
|
||||
|
||||
/**
|
||||
* Cancel the update when still in progress. This stops all running resource
|
||||
* downloads and discards the downloaded cache version. Throws when update
|
||||
* has already finished and made the new cache version active.
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* Return the number of bytes downloaded so far
|
||||
*/
|
||||
|
||||
@@ -1550,6 +1550,7 @@ nsOfflineCacheUpdate::LoadCompleted(nsOfflineCacheUpdateItem *aItem)
|
||||
nsCOMPtr<nsIOfflineCacheUpdate> kungFuDeathGrip(this);
|
||||
|
||||
if (mState == STATE_CANCELLED) {
|
||||
NotifyState(nsIOfflineCacheUpdateObserver::STATE_ERROR);
|
||||
Finish();
|
||||
return;
|
||||
}
|
||||
@@ -1807,25 +1808,6 @@ nsOfflineCacheUpdate::Begin()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsOfflineCacheUpdate::Cancel()
|
||||
{
|
||||
LOG(("nsOfflineCacheUpdate::Cancel [%p]", this));
|
||||
|
||||
mState = STATE_CANCELLED;
|
||||
mSucceeded = false;
|
||||
|
||||
// Cancel all running downloads
|
||||
for (uint32_t i = 0; i < mItems.Length(); ++i) {
|
||||
nsOfflineCacheUpdateItem * item = mItems[i];
|
||||
|
||||
if (item->IsInProgress())
|
||||
item->Cancel();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsOfflineCacheUpdate <private>
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -1883,9 +1865,6 @@ nsOfflineCacheUpdate::ProcessNextURI()
|
||||
LOG(("nsOfflineCacheUpdate::ProcessNextURI [%p, inprogress=%d, numItems=%d]",
|
||||
this, mItemsInProgress, mItems.Length()));
|
||||
|
||||
NS_ASSERTION(mState == STATE_DOWNLOADING,
|
||||
"ProcessNextURI should only be called from the DOWNLOADING state");
|
||||
|
||||
if (mState != STATE_DOWNLOADING) {
|
||||
LOG((" should only be called from the DOWNLOADING state, ignoring"));
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
@@ -2361,6 +2340,29 @@ nsOfflineCacheUpdate::AddDynamicURI(nsIURI *aURI)
|
||||
return AddURI(aURI, nsIApplicationCache::ITEM_DYNAMIC);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOfflineCacheUpdate::Cancel()
|
||||
{
|
||||
LOG(("nsOfflineCacheUpdate::Cancel [%p]", this));
|
||||
|
||||
if ((mState == STATE_FINISHED) || (mState == STATE_CANCELLED)) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
mState = STATE_CANCELLED;
|
||||
mSucceeded = false;
|
||||
|
||||
// Cancel all running downloads
|
||||
for (uint32_t i = 0; i < mItems.Length(); ++i) {
|
||||
nsOfflineCacheUpdateItem * item = mItems[i];
|
||||
|
||||
if (item->IsInProgress())
|
||||
item->Cancel();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOfflineCacheUpdate::AddObserver(nsIOfflineCacheUpdateObserver *aObserver,
|
||||
bool aHoldWeak)
|
||||
|
||||
@@ -201,7 +201,6 @@ public:
|
||||
nsresult Init();
|
||||
|
||||
nsresult Begin();
|
||||
nsresult Cancel();
|
||||
|
||||
void LoadCompleted(nsOfflineCacheUpdateItem *aItem);
|
||||
void ManifestCheckCompleted(nsresult aStatus,
|
||||
|
||||
Reference in New Issue
Block a user