Bug 1425170. P1 - add a member to ChannelMediaResource to store the nsIPrincipal. r=bechen,gerald

Note SharedInfo contains an array to store the original and cloned resources.
This allows us to iterate over resources on the main thread without taking the
cache monitor.

MozReview-Commit-ID: K3gcPYbf72Z

--HG--
extra : rebase_source : eaa070a889797c29d2599b4c3d2507f440d476e7
extra : source : 5dc420815d7a26771c176cdc7b6a87a1c2278da8
This commit is contained in:
JW Wang 2017-12-08 11:08:38 +08:00
Родитель 3ec05888ca
Коммит d764d94fc5
2 изменённых файлов: 32 добавлений и 8 удалений

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

@ -39,6 +39,9 @@ ChannelMediaResource::~ChannelMediaResource()
MOZ_ASSERT(mClosed);
MOZ_ASSERT(!mChannel);
MOZ_ASSERT(!mListener);
if (mSharedInfo) {
mSharedInfo->mResources.RemoveElement(this);
}
}
// ChannelMediaResource::Listener just observes the channel and
@ -463,6 +466,9 @@ ChannelMediaResource::Open(nsIStreamListener** aStreamListener)
return rv;
}
mSharedInfo = new SharedInfo;
mSharedInfo->mResources.AppendElement(this);
mIsLiveStream = cl < 0;
MOZ_ASSERT(GetOffset() == 0, "Who set offset already?");
mListener = new Listener(this, 0, ++mLoadID);
@ -546,10 +552,8 @@ nsresult ChannelMediaResource::Close()
already_AddRefed<nsIPrincipal>
ChannelMediaResource::GetCurrentPrincipal()
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
nsCOMPtr<nsIPrincipal> principal = mCacheStream.GetCurrentPrincipal();
return principal.forget();
MOZ_ASSERT(NS_IsMainThread());
return do_AddRef(mSharedInfo->mPrincipal);
}
bool ChannelMediaResource::CanClone()
@ -568,6 +572,8 @@ ChannelMediaResource::CloneData(MediaResourceCallback* aCallback)
resource->mIsLiveStream = mIsLiveStream;
resource->mIsTransportSeekable = mIsTransportSeekable;
resource->mSharedInfo = mSharedInfo;
mSharedInfo->mResources.AppendElement(resource.get());
// Initially the clone is treated as suspended by the cache, because
// we don't have a channel. If the cache needs to read data from the clone
@ -807,11 +813,17 @@ ChannelMediaResource::UpdatePrincipal()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mChannel);
nsCOMPtr<nsIPrincipal> principal;
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
if (secMan) {
secMan->GetChannelResultPrincipal(mChannel, getter_AddRefs(principal));
mCacheStream.UpdatePrincipal(principal);
if (!secMan) {
return;
}
nsCOMPtr<nsIPrincipal> principal;
secMan->GetChannelResultPrincipal(mChannel, getter_AddRefs(principal));
if (nsContentUtils::CombineResourcePrincipals(&mSharedInfo->mPrincipal,
principal)) {
for (auto* r : mSharedInfo->mResources) {
r->CacheClientNotifyPrincipalChanged();
}
}
}

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

@ -67,6 +67,18 @@ class ChannelMediaResource
: public BaseMediaResource
, public DecoderDoctorLifeLogger<ChannelMediaResource>
{
// Store information shared among resources. Main thread only.
struct SharedInfo
{
NS_INLINE_DECL_REFCOUNTING(SharedInfo);
nsCOMPtr<nsIPrincipal> mPrincipal;
nsTArray<ChannelMediaResource*> mResources;
private:
~SharedInfo() = default;
};
RefPtr<SharedInfo> mSharedInfo;
public:
ChannelMediaResource(MediaResourceCallback* aDecoder,
nsIChannel* aChannel,