Bug 744710 - Enable getting updates on how many bytes of an appcache update have been downloaded, r=michal

This commit is contained in:
Honza Bambas 2012-05-22 22:12:40 +02:00
parent 86d5cd775b
commit acf15bad5e
8 changed files with 58 additions and 7 deletions

View File

@ -78,6 +78,7 @@ OfflineCacheUpdateChild::OfflineCacheUpdateChild(nsIDOMWindow* aWindow)
, mIsUpgrade(false)
, mIPCActivated(false)
, mWindow(aWindow)
, mByteProgress(0)
{
}
@ -340,6 +341,15 @@ OfflineCacheUpdateChild::RemoveObserver(nsIOfflineCacheUpdateObserver *aObserver
return NS_OK;
}
NS_IMETHODIMP
OfflineCacheUpdateChild::GetByteProgress(PRUint64 * _result)
{
NS_ENSURE_ARG(_result);
*_result = mByteProgress;
return NS_OK;
}
NS_IMETHODIMP
OfflineCacheUpdateChild::Schedule()
{
@ -435,10 +445,13 @@ OfflineCacheUpdateChild::RecvAssociateDocuments(const nsCString &cacheGroupId,
}
bool
OfflineCacheUpdateChild::RecvNotifyStateEvent(const PRUint32 &event)
OfflineCacheUpdateChild::RecvNotifyStateEvent(const PRUint32 &event,
const PRUint64 &byteProgress)
{
LOG(("OfflineCacheUpdateChild::RecvNotifyStateEvent [%p]", this));
mByteProgress = byteProgress;
// Convert the public observer state to our internal state
switch (event) {
case nsIOfflineCacheUpdateObserver::STATE_CHECKING:

View File

@ -23,14 +23,15 @@ namespace mozilla {
namespace docshell {
class OfflineCacheUpdateChild : public nsIOfflineCacheUpdate
, public POfflineCacheUpdateChild
, public POfflineCacheUpdateChild
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOFFLINECACHEUPDATE
virtual bool
RecvNotifyStateEvent(const PRUint32& stateEvent);
RecvNotifyStateEvent(const PRUint32& stateEvent,
const PRUint64& byteProgress);
virtual bool
RecvAssociateDocuments(
@ -85,6 +86,8 @@ private:
/* Keep reference to the window that owns this update to call the
parent offline cache update construcor */
nsCOMPtr<nsIDOMWindow> mWindow;
PRUint64 mByteProgress;
};
}

View File

@ -31,7 +31,8 @@ namespace docshell {
NS_SCRIPTABLE NS_IMETHOD InitPartial(nsIURI *aManifestURI, const nsACString & aClientID, nsIURI *aDocumentURI) { return !_to ? NS_ERROR_NULL_POINTER : _to->InitPartial(aManifestURI, aClientID, aDocumentURI); } \
NS_SCRIPTABLE NS_IMETHOD AddDynamicURI(nsIURI *aURI) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddDynamicURI(aURI); } \
NS_SCRIPTABLE NS_IMETHOD AddObserver(nsIOfflineCacheUpdateObserver *aObserver, bool aHoldWeak) { return !_to ? NS_ERROR_NULL_POINTER : _to->AddObserver(aObserver, aHoldWeak); } \
NS_SCRIPTABLE NS_IMETHOD RemoveObserver(nsIOfflineCacheUpdateObserver *aObserver) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveObserver(aObserver); }
NS_SCRIPTABLE NS_IMETHOD RemoveObserver(nsIOfflineCacheUpdateObserver *aObserver) { return !_to ? NS_ERROR_NULL_POINTER : _to->RemoveObserver(aObserver); } \
NS_SCRIPTABLE NS_IMETHOD GetByteProgress(PRUint64 * _result) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetByteProgress(_result); }
class OfflineCacheUpdateGlue : public nsSupportsWeakReference
, public nsIOfflineCacheUpdate

View File

@ -109,7 +109,9 @@ OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate *aUpdate, PRU
LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this));
SendNotifyStateEvent(state);
PRUint64 byteProgress;
aUpdate->GetByteProgress(&byteProgress);
SendNotifyStateEvent(state, byteProgress);
if (state == nsIOfflineCacheUpdateObserver::STATE_FINISHED) {
// Tell the child the particulars after the update has finished.

View File

@ -23,7 +23,7 @@ parent:
__delete__();
child:
NotifyStateEvent(PRUint32 stateEvent);
NotifyStateEvent(PRUint32 stateEvent, PRUint64 byteProgress);
AssociateDocuments(nsCString cacheGroupId, nsCString cacheClientId);
Finish(bool succeded, bool isUpgrate);
};

View File

@ -24,6 +24,7 @@ interface nsIOfflineCacheUpdateObserver : nsISupports {
const unsigned long STATE_DOWNLOADING = 5;
const unsigned long STATE_ITEMSTARTED = 6;
const unsigned long STATE_ITEMCOMPLETED = 7;
const unsigned long STATE_ITEMPROGRESS = 8;
const unsigned long STATE_FINISHED = 10;
/**
@ -60,7 +61,7 @@ interface nsIOfflineCacheUpdateObserver : nsISupports {
* load its items one by one, sending itemCompleted() to any registered
* observers.
*/
[scriptable, uuid(24605d81-8cf9-4021-8575-7f39aacbf31a)]
[scriptable, uuid(2FA574B8-AE62-426b-BE95-08E6AA957455)]
interface nsIOfflineCacheUpdate : nsISupports {
/**
* Fetch the status of the running update. This will return a value
@ -154,6 +155,11 @@ interface nsIOfflineCacheUpdate : nsISupports {
* the observer to remove.
*/
void removeObserver(in nsIOfflineCacheUpdateObserver aObserver);
/**
* Return the number of bytes downloaded so far
*/
readonly attribute PRUint64 byteProgress;
};
[scriptable, uuid(6fd2030f-7b00-4102-a0e3-d73078821eb1)]

View File

@ -402,6 +402,9 @@ nsOfflineCacheUpdateItem::OnDataAvailable(nsIRequest *aRequest,
mBytesRead += bytesRead;
LOG(("loaded %u bytes into offline cache [offset=%u]\n",
bytesRead, aOffset));
mUpdate->OnByteProgress(bytesRead);
return NS_OK;
}
@ -419,6 +422,7 @@ nsOfflineCacheUpdateItem::OnStopRequest(nsIRequest *aRequest,
// specified), but the object should report loadedSize as if it
// did.
mChannel->GetContentLength(&mBytesRead);
mUpdate->OnByteProgress(mBytesRead);
}
// We need to notify the update that the load is complete, but we
@ -1548,6 +1552,7 @@ nsOfflineCacheUpdate::Begin()
}
mState = STATE_CHECKING;
mByteProgress = 0;
NotifyState(nsIOfflineCacheUpdateObserver::STATE_CHECKING);
nsresult rv = mManifestItem->OpenChannel();
@ -1753,6 +1758,13 @@ nsOfflineCacheUpdate::UpdateFinished(nsOfflineCacheUpdate *aUpdate)
return NS_OK;
}
void
nsOfflineCacheUpdate::OnByteProgress(PRUint64 byteIncrement)
{
mByteProgress += byteIncrement;
NotifyState(nsIOfflineCacheUpdateObserver::STATE_ITEMPROGRESS);
}
nsresult
nsOfflineCacheUpdate::ScheduleImplicit()
{
@ -2085,6 +2097,14 @@ nsOfflineCacheUpdate::RemoveObserver(nsIOfflineCacheUpdateObserver *aObserver)
return NS_OK;
}
NS_IMETHODIMP
nsOfflineCacheUpdate::GetByteProgress(PRUint64 * _result)
{
NS_ENSURE_ARG(_result);
*_result = mByteProgress;
return NS_OK;
}
NS_IMETHODIMP
nsOfflineCacheUpdate::Schedule()

View File

@ -205,6 +205,10 @@ public:
virtual nsresult UpdateFinished(nsOfflineCacheUpdate *aUpdate);
protected:
friend class nsOfflineCacheUpdateItem;
void OnByteProgress(PRUint64 byteIncrement);
private:
nsresult HandleManifest(bool *aDoUpdate);
nsresult AddURI(nsIURI *aURI, PRUint32 aItemType);
@ -277,6 +281,8 @@ private:
nsRefPtr<nsOfflineCacheUpdate> mImplicitUpdate;
bool mPinned;
PRUint64 mByteProgress;
};
class nsOfflineCacheUpdateService : public nsIOfflineCacheUpdateService