Backed out 3 changesets (bug 1395017) for frequent failures in test_video_crossorigin.html

Backed out changeset 438657f4637d (bug 1395017)
Backed out changeset 243ef641e6c3 (bug 1395017)
Backed out changeset 78625f947f69 (bug 1395017)

MozReview-Commit-ID: DeBaUOPQrAD
This commit is contained in:
Phil Ringnalda 2017-09-05 22:39:50 -07:00
Родитель 197c575bed
Коммит c0f8dd917a
4 изменённых файлов: 46 добавлений и 45 удалений

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

@ -234,9 +234,6 @@ public:
, mResourceID(aResourceID)
, mNext(0)
{
MOZ_ASSERT(
NS_IsMainThread() ||
(aMediaCache->GetReentrantMonitor().AssertCurrentThreadIn(), true));
}
MediaCacheStream* Next()
{
@ -1879,21 +1876,27 @@ MediaCacheStream::UpdatePrincipal(nsIPrincipal* aPrincipal)
}
void
MediaCacheStream::NotifyDataReceived(int64_t aSize, const char* aData)
MediaCacheStream::NotifyDataReceived(int64_t aSize, const char* aData,
nsIPrincipal* aPrincipal)
{
// This might happen off the main thread.
MOZ_DIAGNOSTIC_ASSERT(!mClosed);
ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
// Update principals before putting the data in the cache. This is important,
// we want to make sure all principals are updated before any consumer
// can see the new data.
// We do this without holding the cache monitor, in case the client wants
// to do something that takes a lock.
{
// Need to acquire the monitor because this code might run
// off the main thread.
MediaCache::ResourceStreamIterator iter(mMediaCache, mResourceID);
while (MediaCacheStream* stream = iter.Next()) {
stream->mClient->CacheClientUpdatePrincipal();
if (stream->UpdatePrincipal(aPrincipal)) {
stream->mClient->CacheClientNotifyPrincipalChanged();
}
}
}
ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
int64_t size = aSize;
const char* data = aData;

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

@ -261,7 +261,8 @@ public:
// the cache requested the offset in
// ChannelMediaResource::CacheClientSeek, or because it defaulted to 0.
// We pass in the principal that was used to load this data.
void NotifyDataReceived(int64_t aSize, const char* aData);
void NotifyDataReceived(int64_t aSize, const char* aData,
nsIPrincipal* aPrincipal);
// Notifies the cache that the current bytes should be written to disk.
// Called on the main thread.
void FlushPartialBlock();
@ -347,9 +348,6 @@ public:
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
// Update mPrincipal given that data has been received from aPrincipal
bool UpdatePrincipal(nsIPrincipal* aPrincipal);
private:
friend class MediaCache;
@ -427,6 +425,8 @@ private:
// If |aNotifyAll| is true, this function will wake up readers who may be
// waiting on the media cache monitor. Called on the main thread only.
void FlushPartialBlockInternal(bool aNotify, ReentrantMonitorAutoEnter& aReentrantMonitor);
// Update mPrincipal given that data has been received from aPrincipal
bool UpdatePrincipal(nsIPrincipal* aPrincipal);
// Instance of MediaCache to use with this MediaCacheStream.
RefPtr<MediaCache> mMediaCache;

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

@ -456,7 +456,8 @@ ChannelMediaResource::OnChannelRedirect(nsIChannel* aOld, nsIChannel* aNew,
}
nsresult
ChannelMediaResource::CopySegmentToCache(const char* aFromSegment,
ChannelMediaResource::CopySegmentToCache(nsIPrincipal* aPrincipal,
const char* aFromSegment,
uint32_t aCount,
uint32_t* aWriteCount)
{
@ -465,21 +466,28 @@ ChannelMediaResource::CopySegmentToCache(const char* aFromSegment,
"[%d] bytes for decoder[%p]",
mOffset, aCount, mCallback.get());
mOffset += aCount;
mCacheStream.NotifyDataReceived(aCount, aFromSegment);
mCacheStream.NotifyDataReceived(aCount, aFromSegment, aPrincipal);
*aWriteCount = aCount;
return NS_OK;
}
struct CopySegmentClosure {
nsCOMPtr<nsIPrincipal> mPrincipal;
ChannelMediaResource* mResource;
};
nsresult
ChannelMediaResource::CopySegmentToCache(nsIInputStream* aInStream,
void* aResource,
void* aClosure,
const char* aFromSegment,
uint32_t aToOffset,
uint32_t aCount,
uint32_t* aWriteCount)
{
ChannelMediaResource* res = static_cast<ChannelMediaResource*>(aResource);
return res->CopySegmentToCache(aFromSegment, aCount, aWriteCount);
CopySegmentClosure* closure = static_cast<CopySegmentClosure*>(aClosure);
return closure->mResource->CopySegmentToCache(
closure->mPrincipal, aFromSegment, aCount, aWriteCount);
}
nsresult
@ -494,10 +502,18 @@ ChannelMediaResource::OnDataAvailable(nsIRequest* aRequest,
mChannelStatistics.AddBytes(aCount);
}
CopySegmentClosure closure;
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
if (secMan && mChannel) {
secMan->GetChannelResultPrincipal(mChannel, getter_AddRefs(closure.mPrincipal));
}
closure.mResource = this;
uint32_t count = aCount;
while (count > 0) {
uint32_t read;
nsresult rv = aStream->ReadSegments(CopySegmentToCache, this, count, &read);
nsresult rv = aStream->ReadSegments(CopySegmentToCache, &closure, count,
&read);
if (NS_FAILED(rv))
return rv;
NS_ASSERTION(read > 0, "Read 0 bytes while data was available?");
@ -621,8 +637,7 @@ nsresult ChannelMediaResource::Close()
return NS_OK;
}
already_AddRefed<nsIPrincipal>
ChannelMediaResource::GetCurrentPrincipal()
already_AddRefed<nsIPrincipal> ChannelMediaResource::GetCurrentPrincipal()
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
@ -873,27 +888,11 @@ ChannelMediaResource::CacheClientNotifyDataEnded(nsresult aStatus)
}
void
ChannelMediaResource::UpdatePrincipal()
ChannelMediaResource::CacheClientNotifyPrincipalChanged()
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIPrincipal> principal;
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
if (secMan && mChannel) {
secMan->GetChannelResultPrincipal(mChannel, getter_AddRefs(principal));
}
if (mCacheStream.UpdatePrincipal(principal)) {
mCallback->NotifyPrincipalChanged();
}
}
NS_ASSERTION(NS_IsMainThread(), "Don't call on non-main thread");
void
ChannelMediaResource::CacheClientUpdatePrincipal()
{
SystemGroup::Dispatch(
TaskCategory::Other,
NewRunnableMethod("ChannelMediaResource::UpdatePrincipal",
this,
&ChannelMediaResource::UpdatePrincipal));
mCallback->NotifyPrincipalChanged();
}
void

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

@ -435,8 +435,8 @@ public:
// if this stream didn't read any data, since another stream might have
// received data for the same resource.
void CacheClientNotifyDataEnded(nsresult aStatus);
// Notified by the cache to update the principal of the resource.
void CacheClientUpdatePrincipal();
// Notify that the principal for the cached resource changed.
void CacheClientNotifyPrincipalChanged();
// Notify the decoder that the cache suspended status changed.
void CacheClientNotifySuspendedStatusChanged();
@ -547,8 +547,6 @@ protected:
nsresult SetupChannelHeaders();
// Closes the channel. Main thread only.
void CloseChannel();
// Update the principal for the resource. Main thread only.
void UpdatePrincipal();
// Parses 'Content-Range' header and returns results via parameters.
// Returns error if header is not available, values are not parse-able or
@ -559,13 +557,14 @@ protected:
int64_t& aRangeTotal);
static nsresult CopySegmentToCache(nsIInputStream* aInStream,
void* aResource,
void* aClosure,
const char* aFromSegment,
uint32_t aToOffset,
uint32_t aCount,
uint32_t* aWriteCount);
nsresult CopySegmentToCache(const char* aFromSegment,
nsresult CopySegmentToCache(nsIPrincipal* aPrincipal,
const char* aFromSegment,
uint32_t aCount,
uint32_t* aWriteCount);