Bug 1371882 - MediaCache::constructor/destructor/Init() don't need to be public - r=cpearce
MozReview-Commit-ID: 9naYvPbGn14
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -128,57 +128,20 @@ MediaCacheFlusher::UnregisterMediaCache(
}
class MediaCache {
public:
friend class MediaCacheStream::BlockList;
typedef MediaCacheStream::BlockList BlockList;
static const int64_t BLOCK_SIZE = MediaCacheStream::BLOCK_SIZE;
- MediaCache() : mNextResourceID(1),
- mReentrantMonitor("MediaCache.mReentrantMonitor"),
- mUpdateQueued(false)
-#ifdef DEBUG
- , mInUpdate(false)
-#endif
- {
- MOZ_COUNT_CTOR(MediaCache);
- MediaCacheFlusher::RegisterMediaCache(this);
- }
- ~MediaCache() {
- MediaCacheFlusher::UnregisterMediaCache(this);
- NS_ASSERTION(mStreams.IsEmpty(), "Stream(s) still open!");
- Truncate();
- NS_ASSERTION(mIndex.Length() == 0, "Blocks leaked?");
- if (mFileCache) {
- mFileCache->Close();
- mFileCache = nullptr;
- }
- LOG("MediaCache::~MediaCache(this=%p) MEDIACACHE_WATERMARK_KB=%u",
- this, unsigned(mIndexWatermark * MediaCache::BLOCK_SIZE / 1024));
- Telemetry::Accumulate(
- Telemetry::HistogramID::MEDIACACHE_WATERMARK_KB,
- uint32_t(mIndexWatermark * MediaCache::BLOCK_SIZE / 1024));
- LOG("MediaCache::~MediaCache(this=%p) MEDIACACHE_BLOCKOWNERS_WATERMARK=%u",
- this, unsigned(mBlockOwnersWatermark));
- Telemetry::Accumulate(
- Telemetry::HistogramID::MEDIACACHE_BLOCKOWNERS_WATERMARK,
- mBlockOwnersWatermark);
-
- 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.
- nsresult Init();
// Shut down the global cache if it's no longer needed. We shut down
// the cache as soon as there are no streams. This means that during
// normal operation we are likely to start up the cache and shut it down
// many times, but that's OK since starting it up is cheap and
// shutting it down cleans things up and releases disk space.
void MaybeShutdown();
// Brutally flush the cache contents. Main thread only.
@@ -287,16 +250,59 @@ public:
}
private:
MediaCache* mMediaCache;
int64_t mResourceID;
uint32_t mNext;
};
protected:
+ MediaCache()
+ : mNextResourceID(1)
+ , mReentrantMonitor("MediaCache.mReentrantMonitor")
+ , mUpdateQueued(false)
+#ifdef DEBUG
+ , mInUpdate(false)
+#endif
+ {
+ MOZ_COUNT_CTOR(MediaCache);
+ MediaCacheFlusher::RegisterMediaCache(this);
+ }
+
+ ~MediaCache()
+ {
+ MediaCacheFlusher::UnregisterMediaCache(this);
+ NS_ASSERTION(mStreams.IsEmpty(), "Stream(s) still open!");
+ Truncate();
+ NS_ASSERTION(mIndex.Length() == 0, "Blocks leaked?");
+ if (mFileCache) {
+ mFileCache->Close();
+ mFileCache = nullptr;
+ }
+ LOG("MediaCache::~MediaCache(this=%p) MEDIACACHE_WATERMARK_KB=%u",
+ this,
+ unsigned(mIndexWatermark * MediaCache::BLOCK_SIZE / 1024));
+ Telemetry::Accumulate(
+ Telemetry::HistogramID::MEDIACACHE_WATERMARK_KB,
+ uint32_t(mIndexWatermark * MediaCache::BLOCK_SIZE / 1024));
+ LOG("MediaCache::~MediaCache(this=%p) MEDIACACHE_BLOCKOWNERS_WATERMARK=%u",
+ this,
+ unsigned(mBlockOwnersWatermark));
+ Telemetry::Accumulate(
+ Telemetry::HistogramID::MEDIACACHE_BLOCKOWNERS_WATERMARK,
+ mBlockOwnersWatermark);
+
+ 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.
int32_t FindBlockForIncomingData(TimeStamp aNow, MediaCacheStream* aStream);
// Find a reusable block --- a free block, if there is one, otherwise
// the reusable block with the latest predicted-next-use, or -1 if
// there aren't any freeable blocks. Only block indices less than
// aMaxSearchBlockIndex are considered. If aForStream is non-null,