mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1405962. P1 - give MediaCache a thread on which we will run data callbacks from the HTTP channel. r=gerald
MozReview-Commit-ID: Av7bFGx9SW --HG-- extra : rebase_source : 296a6137ee63328e11eb11a8ee3430979cf8e5a8 extra : intermediate-source : 9634a9cd63e188799fe691cfe7108a173db503d5 extra : source : 43860a593eb810088adac150c0fa85cf8133ce17
This commit is contained in:
parent
9d77bd9d20
commit
b2cbe2833f
@ -10,6 +10,7 @@
|
||||
#include "nsICachingChannel.h"
|
||||
#include "nsIClassOfService.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIThreadRetargetableRequest.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
static const uint32_t HTTP_PARTIAL_RESPONSE_CODE = 206;
|
||||
@ -299,6 +300,16 @@ ChannelMediaResource::OnStartRequest(nsIRequest* aRequest,
|
||||
// Fires an initial progress event.
|
||||
owner->DownloadProgressed();
|
||||
|
||||
// TODO: Don't turn this on until we fix all data races.
|
||||
nsCOMPtr<nsIThreadRetargetableRequest> retarget;
|
||||
if (Preferences::GetBool("media.omt_data_delivery.enabled", false) &&
|
||||
(retarget = do_QueryInterface(aRequest)) && mCacheStream.OwnerThread()) {
|
||||
// Note this will not always succeed. We need to handle the case where
|
||||
// all resources sharing the same cache might run their data callbacks
|
||||
// on different threads.
|
||||
retarget->RetargetDeliveryTo(mCacheStream.OwnerThread());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,8 @@ public:
|
||||
// file backing will be provided.
|
||||
static RefPtr<MediaCache> GetMediaCache(int64_t aContentLength);
|
||||
|
||||
nsIEventTarget* OwnerThread() const { return mThread; }
|
||||
|
||||
// Brutally flush the cache contents. Main thread only.
|
||||
void Flush();
|
||||
|
||||
@ -277,6 +279,10 @@ protected:
|
||||
NS_ASSERTION(NS_IsMainThread(), "Only construct MediaCache on main thread");
|
||||
MOZ_COUNT_CTOR(MediaCache);
|
||||
MediaCacheFlusher::RegisterMediaCache(this);
|
||||
nsresult rv = NS_NewNamedThread("MediaCache", getter_AddRefs(mThread));
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Failed to create a thread for MediaCache.");
|
||||
}
|
||||
}
|
||||
|
||||
~MediaCache()
|
||||
@ -308,6 +314,11 @@ protected:
|
||||
Truncate();
|
||||
NS_ASSERTION(mIndex.Length() == 0, "Blocks leaked?");
|
||||
|
||||
nsCOMPtr<nsIThread> thread = mThread.forget();
|
||||
if (thread) {
|
||||
thread->Shutdown();
|
||||
}
|
||||
|
||||
MOZ_COUNT_DTOR(MediaCache);
|
||||
}
|
||||
|
||||
@ -436,6 +447,9 @@ protected:
|
||||
#endif
|
||||
// A list of resource IDs to notify about the change in suspended status.
|
||||
nsTArray<int64_t> mSuspendedStatusToNotify;
|
||||
// The thread on which we will run data callbacks from the channels.
|
||||
// Could be null if failing to create the thread.
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
};
|
||||
|
||||
// Initialized to nullptr by non-local static initialization.
|
||||
@ -1939,11 +1953,6 @@ MediaCacheStream::NotifyDataReceived(uint32_t aLoadID,
|
||||
aSize,
|
||||
aLoadID);
|
||||
|
||||
// TODO: For now NotifyDataReceived() always runs on the main thread. This
|
||||
// assertion is to make sure our load ID algorithm doesn't go wrong. Remove it
|
||||
// when OMT data delievery is enabled.
|
||||
MOZ_DIAGNOSTIC_ASSERT(mLoadID == aLoadID);
|
||||
|
||||
if (mLoadID != aLoadID) {
|
||||
// mChannelOffset is updated to a new position when loading a new channel.
|
||||
// We should discard the data coming from the old channel so it won't be
|
||||
@ -2662,6 +2671,12 @@ MediaCacheStream::InitAsClone(MediaCacheStream* aOriginal)
|
||||
}
|
||||
}
|
||||
|
||||
nsIEventTarget*
|
||||
MediaCacheStream::OwnerThread() const
|
||||
{
|
||||
return mMediaCache->OwnerThread();
|
||||
}
|
||||
|
||||
nsresult MediaCacheStream::GetCachedRanges(MediaByteRangeSet& aRanges)
|
||||
{
|
||||
// Take the monitor, so that the cached data ranges can't grow while we're
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "nsTArray.h"
|
||||
#include "nsTHashtable.h"
|
||||
|
||||
class nsIEventTarget;
|
||||
class nsIPrincipal;
|
||||
|
||||
namespace mozilla {
|
||||
@ -210,6 +211,8 @@ public:
|
||||
// on this class.
|
||||
void InitAsClone(MediaCacheStream* aOriginal);
|
||||
|
||||
nsIEventTarget* OwnerThread() const;
|
||||
|
||||
// These are called on the main thread.
|
||||
// Tell us whether the stream is seekable or not. Non-seekable streams
|
||||
// will always pass 0 for aOffset to CacheClientSeek. This should only
|
||||
|
@ -311,6 +311,10 @@ pref("mathml.scale_stretchy_operators.enabled", true);
|
||||
|
||||
pref("media.dormant-on-pause-timeout-ms", 5000);
|
||||
|
||||
// Used by ChannelMediaResource to run data callbacks from HTTP channel
|
||||
// off the main thread.
|
||||
pref("media.omt_data_delivery.enabled", false);
|
||||
|
||||
// File-backed MediaCache size in kilobytes
|
||||
pref("media.cache_size", 512000);
|
||||
// When a network connection is suspended, don't resume it until the
|
||||
|
Loading…
Reference in New Issue
Block a user