зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1371882 - Let GetMediaCache decide which block cache to use - r=cpearce
This allows a fallback to the file-backed MediaCache, if a MemoryBlockCache could not be created and initialized (which may happen in the next patch, where MemoryBlockCache will take care of not using more than MediaMemoryCachesCombinedLimit). MediaCache::Init() is not needed anymore, as its only work was to initialize its block cache. MozReview-Commit-ID: ItAdOPuxEvt --HG-- extra : rebase_source : 08461d61b8d738edb8c2088bca4e33213b8ae4e1
This commit is contained in:
Родитель
5a0a2a8c04
Коммит
319f8220ec
|
@ -252,10 +252,11 @@ public:
|
|||
};
|
||||
|
||||
protected:
|
||||
explicit MediaCache(int64_t aContentLength)
|
||||
explicit MediaCache(int64_t aContentLength, MediaBlockCacheBase* aCache)
|
||||
: mContentLength(aContentLength)
|
||||
, mNextResourceID(1)
|
||||
, mReentrantMonitor("MediaCache.mReentrantMonitor")
|
||||
, mBlockCache(aCache)
|
||||
, mUpdateQueued(false)
|
||||
#ifdef DEBUG
|
||||
, mInUpdate(false)
|
||||
|
@ -306,11 +307,6 @@ protected:
|
|||
MOZ_COUNT_DTOR(MediaCache);
|
||||
}
|
||||
|
||||
// Main thread only. Creates the backing cache file. If this fails,
|
||||
// then the cache is still in a semi-valid state; mFD will be null,
|
||||
// so all I/O on the cache file will fail.
|
||||
nsresult Init();
|
||||
|
||||
// Find a free or reusable block and return its index. If there are no
|
||||
// free blocks and no reusable blocks, add a new block to the cache
|
||||
// and return it. Can return -1 on OOM.
|
||||
|
@ -674,25 +670,6 @@ MediaCacheStream::BlockList::NotifyBlockSwapped(int32_t aBlockIndex1,
|
|||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
MediaCache::Init()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
|
||||
NS_ASSERTION(!mBlockCache, "Block cache already open?");
|
||||
|
||||
if (mContentLength <= 0) {
|
||||
// The global MediaCache uses a file-backed storage for its resource blocks.
|
||||
mBlockCache = new FileBlockCache();
|
||||
} else {
|
||||
// Non-global MediaCaches keep the whole resource in memory.
|
||||
mBlockCache = new MemoryBlockCache(mContentLength);
|
||||
}
|
||||
nsresult rv = mBlockCache->Init();
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
MediaCache::Flush()
|
||||
{
|
||||
|
@ -736,9 +713,10 @@ MediaCache::GetMediaCache(int64_t aContentLength)
|
|||
sysmem * MediaPrefs::MediaMemoryCachesCombinedLimitPcSysmem() / 100)) {
|
||||
// Small-enough resource (and we are under the maximum memory usage), use
|
||||
// a new memory-backed MediaCache.
|
||||
RefPtr<MediaCache> mc = new MediaCache(aContentLength);
|
||||
nsresult rv = mc->Init();
|
||||
RefPtr<MediaBlockCacheBase> bc = new MemoryBlockCache(aContentLength);
|
||||
nsresult rv = bc->Init();
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
RefPtr<MediaCache> mc = new MediaCache(aContentLength, bc);
|
||||
gMediaMemoryCachesCombinedSize += aContentLength;
|
||||
LOG("GetMediaCache(%" PRIi64
|
||||
") -> Memory MediaCache %p, combined size %" PRIi64,
|
||||
|
@ -747,7 +725,7 @@ MediaCache::GetMediaCache(int64_t aContentLength)
|
|||
gMediaMemoryCachesCombinedSize);
|
||||
return mc;
|
||||
}
|
||||
// Memory-backed MediaCache initialization failed, clean up and try for a
|
||||
// MemoryBlockCache initialization failed, clean up and try for a
|
||||
// file-backed MediaCache below.
|
||||
}
|
||||
|
||||
|
@ -757,14 +735,14 @@ MediaCache::GetMediaCache(int64_t aContentLength)
|
|||
return gMediaCache;
|
||||
}
|
||||
|
||||
gMediaCache = new MediaCache(-1);
|
||||
nsresult rv = gMediaCache->Init();
|
||||
if (NS_FAILED(rv)) {
|
||||
gMediaCache = nullptr;
|
||||
LOG("GetMediaCache(%" PRIi64 ") -> Failed to create file-backed MediaCache",
|
||||
RefPtr<MediaBlockCacheBase> bc = new FileBlockCache();
|
||||
nsresult rv = bc->Init();
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
gMediaCache = new MediaCache(-1, bc);
|
||||
LOG("GetMediaCache(%" PRIi64 ") -> Created file-backed MediaCache",
|
||||
aContentLength);
|
||||
} else {
|
||||
LOG("GetMediaCache(%" PRIi64 ") -> Created file-backed MediaCache",
|
||||
LOG("GetMediaCache(%" PRIi64 ") -> Failed to create file-backed MediaCache",
|
||||
aContentLength);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче