Bug 572243 - Media cache should be cleared when leaving private browsing mode; r=bzbarsky a=blocking-betaN+

This commit is contained in:
Ehsan Akhgari 2010-09-28 20:02:08 -04:00
Родитель 4a0d8ef948
Коммит eb2baf6ce0
1 изменённых файлов: 50 добавлений и 0 удалений

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

@ -49,6 +49,7 @@
#include "nsMediaStream.h" #include "nsMediaStream.h"
#include "nsMathUtils.h" #include "nsMathUtils.h"
#include "prlog.h" #include "prlog.h"
#include "nsIPrivateBrowsingService.h"
#ifdef PR_LOGGING #ifdef PR_LOGGING
PRLogModuleInfo* gMediaCacheLog; PRLogModuleInfo* gMediaCacheLog;
@ -89,6 +90,42 @@ using mozilla::TimeDuration;
// size limits). // size limits).
static nsMediaCache* gMediaCache; static nsMediaCache* gMediaCache;
class nsMediaCacheFlusher : public nsIObserver,
public nsSupportsWeakReference {
nsMediaCacheFlusher() {}
~nsMediaCacheFlusher();
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
static void Init();
};
static nsMediaCacheFlusher* gMediaCacheFlusher;
NS_IMPL_ISUPPORTS2(nsMediaCacheFlusher, nsIObserver, nsISupportsWeakReference)
nsMediaCacheFlusher::~nsMediaCacheFlusher()
{
gMediaCacheFlusher = nsnull;
}
void nsMediaCacheFlusher::Init()
{
if (gMediaCacheFlusher) {
return;
}
gMediaCacheFlusher = new nsMediaCacheFlusher();
NS_ADDREF(gMediaCacheFlusher);
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (observerService) {
observerService->AddObserver(gMediaCacheFlusher, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE);
}
}
class nsMediaCache { class nsMediaCache {
public: public:
friend class nsMediaCacheStream::BlockList; friend class nsMediaCacheStream::BlockList;
@ -334,6 +371,16 @@ protected:
#endif #endif
}; };
NS_IMETHODIMP
nsMediaCacheFlusher::Observe(nsISupports *aSubject, char const *aTopic, PRUnichar const *aData)
{
if (strcmp(aTopic, NS_PRIVATE_BROWSING_SWITCH_TOPIC) == 0 &&
NS_LITERAL_STRING(NS_PRIVATE_BROWSING_LEAVE).Equals(aData)) {
nsMediaCache::Flush();
}
return NS_OK;
}
void nsMediaCacheStream::BlockList::AddFirstBlock(PRInt32 aBlock) void nsMediaCacheStream::BlockList::AddFirstBlock(PRInt32 aBlock)
{ {
NS_ASSERTION(!mEntries.GetEntry(aBlock), "Block already in list"); NS_ASSERTION(!mEntries.GetEntry(aBlock), "Block already in list");
@ -531,6 +578,8 @@ nsMediaCache::Init()
} }
#endif #endif
nsMediaCacheFlusher::Init();
return NS_OK; return NS_OK;
} }
@ -579,6 +628,7 @@ nsMediaCache::MaybeShutdown()
// This function is static so we don't have to delete 'this'. // This function is static so we don't have to delete 'this'.
delete gMediaCache; delete gMediaCache;
gMediaCache = nsnull; gMediaCache = nsnull;
NS_IF_RELEASE(gMediaCacheFlusher);
} }
static void static void