Bug 1353668. P1 - add a member function, CopySegmentToCache.
MozReview-Commit-ID: 5uEWpMigspX
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -420,44 +420,51 @@ nsresult
ChannelMediaResource::OnChannelRedirect(nsIChannel* aOld, nsIChannel* aNew,
uint32_t aFlags)
{
mChannel = aNew;
mSuspendAgent.NotifyChannelOpened(mChannel);
return SetupChannelHeaders();
}
+nsresult
+ChannelMediaResource::CopySegmentToCache(nsIPrincipal* aPrincipal,
+ const char* aFromSegment,
+ uint32_t aCount,
+ uint32_t* aWriteCount)
+{
+ mCallback->NotifyDataArrived();
+
+ // Keep track of where we're up to.
+ CMLOG("CopySegmentToCache at mOffset [%" PRId64 "] add "
+ "[%d] bytes for decoder[%p]",
+ mOffset, aCount, mCallback.get());
+ mOffset += aCount;
+ mCacheStream.NotifyDataReceived(aCount, aFromSegment, aPrincipal);
+ *aWriteCount = aCount;
+ return NS_OK;
+}
+
+
struct CopySegmentClosure {
nsCOMPtr<nsIPrincipal> mPrincipal;
ChannelMediaResource* mResource;
};
nsresult
-ChannelMediaResource::CopySegmentToCache(nsIInputStream *aInStream,
- void *aClosure,
- const char *aFromSegment,
+ChannelMediaResource::CopySegmentToCache(nsIInputStream* aInStream,
+ void* aClosure,
+ const char* aFromSegment,
uint32_t aToOffset,
uint32_t aCount,
- uint32_t *aWriteCount)
+ uint32_t* aWriteCount)
{
CopySegmentClosure* closure = static_cast<CopySegmentClosure*>(aClosure);
-
- closure->mResource->mCallback->NotifyDataArrived();
-
- // Keep track of where we're up to.
- RESOURCE_LOG("%p [ChannelMediaResource]: CopySegmentToCache at mOffset [%" PRId64 "] add "
- "[%d] bytes for decoder[%p]",
- closure->mResource, closure->mResource->mOffset, aCount,
- closure->mResource->mCallback.get());
- closure->mResource->mOffset += aCount;
-
- closure->mResource->mCacheStream.NotifyDataReceived(aCount, aFromSegment,
- closure->mPrincipal);
- *aWriteCount = aCount;
- return NS_OK;
+ return closure->mResource->CopySegmentToCache(
+ closure->mPrincipal, aFromSegment, aCount, aWriteCount);
}
nsresult
ChannelMediaResource::OnDataAvailable(nsIRequest* aRequest,
nsIInputStream* aStream,
uint32_t aCount)
{
NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -653,22 +653,27 @@ protected:
// values are out of range.
nsresult ParseContentRangeHeader(nsIHttpChannel * aHttpChan,
int64_t& aRangeStart,
int64_t& aRangeEnd,
int64_t& aRangeTotal);
void DoNotifyDataReceived();
- static nsresult CopySegmentToCache(nsIInputStream *aInStream,
- void *aClosure,
- const char *aFromSegment,
+ static nsresult CopySegmentToCache(nsIInputStream* aInStream,
+ void* aClosure,
+ const char* aFromSegment,
uint32_t aToOffset,
uint32_t aCount,
- uint32_t *aWriteCount);
+ uint32_t* aWriteCount);
+
+ nsresult CopySegmentToCache(nsIPrincipal* aPrincipal,
+ const char* aFromSegment,
+ uint32_t aCount,
+ uint32_t* aWriteCount);
// Main thread access only
int64_t mOffset;
RefPtr<Listener> mListener;
// A data received event for the decoder that has been dispatched but has
// not yet been processed.
nsRevocableEventPtr<nsRunnableMethod<ChannelMediaResource, void, false> > mDataReceivedEvent;
// When this flag is set, if we get a network error we should silently