From acf15bad5e64ca44f24157b538ab3618a3c9dffe Mon Sep 17 00:00:00 2001 From: Honza Bambas Date: Tue, 22 May 2012 22:12:40 +0200 Subject: [PATCH] Bug 744710 - Enable getting updates on how many bytes of an appcache update have been downloaded, r=michal --- .../prefetch/OfflineCacheUpdateChild.cpp | 15 +++++++++++++- uriloader/prefetch/OfflineCacheUpdateChild.h | 7 +++++-- uriloader/prefetch/OfflineCacheUpdateGlue.h | 3 ++- .../prefetch/OfflineCacheUpdateParent.cpp | 4 +++- uriloader/prefetch/POfflineCacheUpdate.ipdl | 2 +- uriloader/prefetch/nsIOfflineCacheUpdate.idl | 8 +++++++- uriloader/prefetch/nsOfflineCacheUpdate.cpp | 20 +++++++++++++++++++ uriloader/prefetch/nsOfflineCacheUpdate.h | 6 ++++++ 8 files changed, 58 insertions(+), 7 deletions(-) diff --git a/uriloader/prefetch/OfflineCacheUpdateChild.cpp b/uriloader/prefetch/OfflineCacheUpdateChild.cpp index aa44925df90..5cf2f7e3748 100644 --- a/uriloader/prefetch/OfflineCacheUpdateChild.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateChild.cpp @@ -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: diff --git a/uriloader/prefetch/OfflineCacheUpdateChild.h b/uriloader/prefetch/OfflineCacheUpdateChild.h index aa0219ffb33..d2b9a2bf60b 100644 --- a/uriloader/prefetch/OfflineCacheUpdateChild.h +++ b/uriloader/prefetch/OfflineCacheUpdateChild.h @@ -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 mWindow; + + PRUint64 mByteProgress; }; } diff --git a/uriloader/prefetch/OfflineCacheUpdateGlue.h b/uriloader/prefetch/OfflineCacheUpdateGlue.h index 4f0fa75afb4..cbf55246392 100644 --- a/uriloader/prefetch/OfflineCacheUpdateGlue.h +++ b/uriloader/prefetch/OfflineCacheUpdateGlue.h @@ -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 diff --git a/uriloader/prefetch/OfflineCacheUpdateParent.cpp b/uriloader/prefetch/OfflineCacheUpdateParent.cpp index e86a6a03aa3..516611d8c07 100644 --- a/uriloader/prefetch/OfflineCacheUpdateParent.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateParent.cpp @@ -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. diff --git a/uriloader/prefetch/POfflineCacheUpdate.ipdl b/uriloader/prefetch/POfflineCacheUpdate.ipdl index 7734a10b7ca..cbb25a1054d 100644 --- a/uriloader/prefetch/POfflineCacheUpdate.ipdl +++ b/uriloader/prefetch/POfflineCacheUpdate.ipdl @@ -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); }; diff --git a/uriloader/prefetch/nsIOfflineCacheUpdate.idl b/uriloader/prefetch/nsIOfflineCacheUpdate.idl index f6d2f2e0bce..8745bc63d42 100644 --- a/uriloader/prefetch/nsIOfflineCacheUpdate.idl +++ b/uriloader/prefetch/nsIOfflineCacheUpdate.idl @@ -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)] diff --git a/uriloader/prefetch/nsOfflineCacheUpdate.cpp b/uriloader/prefetch/nsOfflineCacheUpdate.cpp index b54e6360f29..25fd3128551 100644 --- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp +++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp @@ -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() diff --git a/uriloader/prefetch/nsOfflineCacheUpdate.h b/uriloader/prefetch/nsOfflineCacheUpdate.h index ce00e30de0a..1c4fe8c49be 100644 --- a/uriloader/prefetch/nsOfflineCacheUpdate.h +++ b/uriloader/prefetch/nsOfflineCacheUpdate.h @@ -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 mImplicitUpdate; bool mPinned; + + PRUint64 mByteProgress; }; class nsOfflineCacheUpdateService : public nsIOfflineCacheUpdateService