Bug 848344 - Clear media cache along with network cache when storage policy is set to STORE_ANYWHERE. r=michal

This commit is contained in:
Srinath N 2013-06-18 01:44:00 -04:00
parent fbd56e66c5
commit de0e5072f0
3 changed files with 28 additions and 1 deletions

View File

@ -98,6 +98,7 @@ void MediaCacheFlusher::Init()
mozilla::services::GetObserverService();
if (observerService) {
observerService->AddObserver(gMediaCacheFlusher, "last-pb-context-exited", true);
observerService->AddObserver(gMediaCacheFlusher, "network-clear-cache-stored-anywhere", true);
}
}
@ -353,6 +354,9 @@ MediaCacheFlusher::Observe(nsISupports *aSubject, char const *aTopic, PRUnichar
if (strcmp(aTopic, "last-pb-context-exited") == 0) {
MediaCache::Flush();
}
if (strcmp(aTopic, "network-clear-cache-stored-anywhere") == 0) {
MediaCache::Flush();
}
return NS_OK;
}

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/Attributes.h"
#include "mozilla/Assertions.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/Util.h"
@ -1496,9 +1497,30 @@ NS_IMETHODIMP nsCacheService::VisitEntries(nsICacheVisitor *visitor)
return NS_OK;
}
void nsCacheService::FireClearNetworkCacheStoredAnywhereNotification()
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIObserverService> obsvc = mozilla::services::GetObserverService();
if (obsvc) {
obsvc->NotifyObservers(nullptr,
"network-clear-cache-stored-anywhere",
nullptr);
}
}
NS_IMETHODIMP nsCacheService::EvictEntries(nsCacheStoragePolicy storagePolicy)
{
if (storagePolicy == nsICache::STORE_ANYWHERE) {
// if not called on main thread, dispatch the notification to the main thread to notify observers
if (!NS_IsMainThread()) {
nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this,
&nsCacheService::FireClearNetworkCacheStoredAnywhereNotification);
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
} else {
// else you're already on main thread - notify observers
FireClearNetworkCacheStoredAnywhereNotification();
}
}
return EvictEntriesForClient(nullptr, storagePolicy);
}

View File

@ -292,6 +292,7 @@ private:
void ClearDoomList(void);
void DoomActiveEntries(DoomCheckFn check);
void CloseAllStreams();
void FireClearNetworkCacheStoredAnywhereNotification();
static
PLDHashOperator GetActiveEntries(PLDHashTable * table,