Bug 1194891. P4 - close all streams associated with private browsing windows when PB is done. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 06 Apr 2017 16:39:14 +0800
changeset 557705 668a337401c1bc276eaa3884f62a1347568fc3e7
parent 557704 52bc246fbcee99424dce763600c8722c3bdbc93b
child 557711 dbce56553d04274b381a48efafbd2683a9cade9c
child 558245 1fd7fbfbbced3a5432f6a8870a2bc7b0b19886c7
push id52791
push userjwwang@mozilla.com
push dateFri, 07 Apr 2017 06:23:27 +0000
bugs1194891
milestone55.0a1
Bug 1194891. P4 - close all streams associated with private browsing windows when PB is done. MozReview-Commit-ID: MmvMuzuFX3
dom/media/MediaCache.cpp
--- 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;
   }