Bug 1194891. P4 - close all streams associated with private browsing windows when PB is done.
MozReview-Commit-ID: MmvMuzuFX3
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -135,16 +135,21 @@ public:
// many times, but that's OK since starting it up is cheap and
// shutting it down cleans things up and releases disk space.
static void MaybeShutdown();
// Brutally flush the cache contents. Main thread only.
static void Flush();
void FlushInternal();
+ // Close all streams associated with private browsing windows. This will
+ // also remove the blocks from the cache since we don't want to leave any
+ // traces when PB is done.
+ static void CloseStreamsForPrivateBrowsing();
+
// Cache-file access methods. These are the lowest-level cache methods.
// mReentrantMonitor must be held; these can be called on any thread.
// This can return partial reads.
nsresult ReadCacheFile(int64_t aOffset, void* aData, int32_t aLength,
int32_t* aBytes);
// This will fail if all aLength bytes are not read
nsresult ReadCacheFileAllBytes(int64_t aOffset, void* aData, int32_t aLength);
@@ -350,20 +355,22 @@ protected:
// A list of resource IDs to notify about the change in suspended status.
nsTArray<int64_t> mSuspendedStatusToNotify;
};
NS_IMETHODIMP
MediaCacheFlusher::Observe(nsISupports *aSubject, char const *aTopic, char16_t const *aData)
{
if (strcmp(aTopic, "last-pb-context-exited") == 0) {
- MediaCache::Flush();
+ MediaCache::CloseStreamsForPrivateBrowsing();
+ return NS_OK;
}
if (strcmp(aTopic, "cacheservice:empty-cache") == 0) {
MediaCache::Flush();
+ return NS_OK;
}
return NS_OK;
}
MediaCacheStream::MediaCacheStream(ChannelMediaResource* aClient,
bool aIsPrivateBrowsing)
: mClient(aClient),
mInitialized(false),
@@ -610,16 +617,30 @@ MediaCache::FlushInternal()
if (mFileCache) {
mFileCache->Close();
mFileCache = nullptr;
}
Init();
}
void
+MediaCache::CloseStreamsForPrivateBrowsing()
+{
+ MOZ_ASSERT(NS_IsMainThread());
+ if (!gMediaCache) {
+ return;
+ }
+ for (auto& s : gMediaCache->mStreams) {
+ if (s->mIsPrivateBrowsing) {
+ s->Close();
+ }
+ }
+}
+
+void
MediaCache::MaybeShutdown()
{
NS_ASSERTION(NS_IsMainThread(),
"MediaCache::MaybeShutdown called on non-main thread");
if (!gMediaCache->mStreams.IsEmpty()) {
// Don't shut down yet, streams are still alive
return;
}