Bug 1371882 - static MediaCache::GetMediaCache to get file-backed MediaCache - r=cpearce

This is the new recommended way to create&initialize the file-backed
MediaCache.

In future patches, this will also allow the creation of memory-backed
MediaCache objects.

MozReview-Commit-ID: 6RUlNW2eBPP

--HG--
extra : rebase_source : 0b3e6fae71207076812b5cb9172d4497d3e68ea2
This commit is contained in:
Gerald Squelart 2017-06-08 15:09:40 +12:00
Родитель 2bfadd1441
Коммит 901a3dbeea
1 изменённых файлов: 15 добавлений и 6 удалений

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

@ -166,6 +166,10 @@ public:
MOZ_COUNT_DTOR(MediaCache);
}
// Get an instance of the file-backed MediaCache.
// Returns nullptr if initialization failed.
static MediaCache* GetMediaCache();
// 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.
@ -693,11 +697,13 @@ MediaCache::MaybeShutdown()
gMediaCache = nullptr;
}
static void
InitMediaCache()
/* static */ MediaCache*
MediaCache::GetMediaCache()
{
if (gMediaCache)
return;
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
if (gMediaCache) {
return gMediaCache;
}
gMediaCache = new MediaCache();
nsresult rv = gMediaCache->Init();
@ -705,6 +711,8 @@ InitMediaCache()
delete gMediaCache;
gMediaCache = nullptr;
}
return gMediaCache;
}
nsresult
@ -2483,9 +2491,10 @@ MediaCacheStream::Init()
if (mInitialized)
return NS_OK;
InitMediaCache();
if (!gMediaCache)
MediaCache::GetMediaCache();
if (!gMediaCache) {
return NS_ERROR_FAILURE;
}
gMediaCache->OpenStream(this);
mInitialized = true;
return NS_OK;