From d64d62164c57cf1ac14aa0f8fea1ab4e6340217c Mon Sep 17 00:00:00 2001 From: JW Wang Date: Thu, 6 Apr 2017 16:39:14 +0800 Subject: [PATCH] Bug 1194891. P4 - close all streams associated with private browsing windows when PB is done. r=cpearce MozReview-Commit-ID: MmvMuzuFX3 --HG-- extra : rebase_source : d5f98bd815323e9a79959af49a9585d8f6108d28 extra : source : 7a82be361a50b950b579a5f6b1872d10de80d76f --- dom/media/MediaCache.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index df9cd79b8d98..d6b0d8050843 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -140,6 +140,11 @@ public: 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. @@ -355,10 +360,12 @@ 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; } @@ -614,6 +621,20 @@ MediaCache::FlushInternal() Init(); } +void +MediaCache::CloseStreamsForPrivateBrowsing() +{ + MOZ_ASSERT(NS_IsMainThread()); + if (!gMediaCache) { + return; + } + for (auto& s : gMediaCache->mStreams) { + if (s->mIsPrivateBrowsing) { + s->Close(); + } + } +} + void MediaCache::MaybeShutdown() {