mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1333568. r=valentin
This commit is contained in:
parent
9419e1a97c
commit
4476c148e4
64
netwerk/cache/nsDiskCacheDeviceSQL.cpp
vendored
64
netwerk/cache/nsDiskCacheDeviceSQL.cpp
vendored
@ -9,6 +9,7 @@
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Sprintf.h"
|
||||
#include "mozilla/ThreadLocal.h"
|
||||
|
||||
#include "nsCache.h"
|
||||
#include "nsDiskCache.h"
|
||||
@ -115,13 +116,13 @@ class EvictionObserver
|
||||
nsOfflineCacheEvictionFunction *evictionFunction)
|
||||
: mDB(db), mEvictionFunction(evictionFunction)
|
||||
{
|
||||
mEvictionFunction->Init();
|
||||
mDB->ExecuteSimpleSQL(
|
||||
NS_LITERAL_CSTRING("CREATE TEMP TRIGGER cache_on_delete BEFORE DELETE"
|
||||
" ON moz_cache FOR EACH ROW BEGIN SELECT"
|
||||
" cache_eviction_observer("
|
||||
" OLD.ClientID, OLD.key, OLD.generation);"
|
||||
" END;"));
|
||||
mEvictionFunction->Reset();
|
||||
}
|
||||
|
||||
~EvictionObserver()
|
||||
@ -187,6 +188,13 @@ GetCacheDataFile(nsIFile *cacheDir, const char *key,
|
||||
return file->AppendNative(nsDependentCString(leaf));
|
||||
}
|
||||
|
||||
namespace appcachedetail {
|
||||
|
||||
typedef nsCOMArray<nsIFile> FileArray;
|
||||
static MOZ_THREAD_LOCAL(FileArray*) tlsEvictionItems;
|
||||
|
||||
} // appcachedetail
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOfflineCacheEvictionFunction::OnFunctionCall(mozIStorageValueArray *values, nsIVariant **_retval)
|
||||
{
|
||||
@ -223,27 +231,69 @@ nsOfflineCacheEvictionFunction::OnFunctionCall(mozIStorageValueArray *values, ns
|
||||
return rv;
|
||||
}
|
||||
|
||||
mItems.AppendObject(file);
|
||||
appcachedetail::FileArray* items = appcachedetail::tlsEvictionItems.get();
|
||||
MOZ_ASSERT(items);
|
||||
if (items) {
|
||||
items->AppendObject(file);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsOfflineCacheEvictionFunction::nsOfflineCacheEvictionFunction(nsOfflineCacheDevice * device)
|
||||
: mDevice(device)
|
||||
{
|
||||
mTLSInited = appcachedetail::tlsEvictionItems.init();
|
||||
}
|
||||
|
||||
void nsOfflineCacheEvictionFunction::Init()
|
||||
{
|
||||
if (mTLSInited) {
|
||||
appcachedetail::tlsEvictionItems.set(new appcachedetail::FileArray());
|
||||
}
|
||||
}
|
||||
|
||||
void nsOfflineCacheEvictionFunction::Reset()
|
||||
{
|
||||
if (!mTLSInited) {
|
||||
return;
|
||||
}
|
||||
|
||||
appcachedetail::FileArray* items = appcachedetail::tlsEvictionItems.get();
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
|
||||
appcachedetail::tlsEvictionItems.set(nullptr);
|
||||
delete items;
|
||||
}
|
||||
|
||||
void
|
||||
nsOfflineCacheEvictionFunction::Apply()
|
||||
{
|
||||
LOG(("nsOfflineCacheEvictionFunction::Apply\n"));
|
||||
|
||||
for (int32_t i = 0; i < mItems.Count(); i++) {
|
||||
if (!mTLSInited) {
|
||||
return;
|
||||
}
|
||||
|
||||
appcachedetail::FileArray* pitems = appcachedetail::tlsEvictionItems.get();
|
||||
if (!pitems) {
|
||||
return;
|
||||
}
|
||||
|
||||
appcachedetail::FileArray items;
|
||||
items.SwapElements(*pitems);
|
||||
|
||||
for (int32_t i = 0; i < items.Count(); i++) {
|
||||
if (MOZ_LOG_TEST(gCacheLog, LogLevel::Debug)) {
|
||||
nsAutoCString path;
|
||||
mItems[i]->GetNativePath(path);
|
||||
items[i]->GetNativePath(path);
|
||||
LOG((" removing %s\n", path.get()));
|
||||
}
|
||||
|
||||
mItems[i]->Remove(false);
|
||||
items[i]->Remove(false);
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
|
||||
class nsOfflineCacheDiscardCache : public Runnable
|
||||
|
10
netwerk/cache/nsDiskCacheDeviceSQL.h
vendored
10
netwerk/cache/nsDiskCacheDeviceSQL.h
vendored
@ -49,19 +49,17 @@ public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_MOZISTORAGEFUNCTION
|
||||
|
||||
explicit nsOfflineCacheEvictionFunction(nsOfflineCacheDevice *device)
|
||||
: mDevice(device)
|
||||
{}
|
||||
explicit nsOfflineCacheEvictionFunction(nsOfflineCacheDevice *device);
|
||||
|
||||
void Reset() { mItems.Clear(); }
|
||||
void Init();
|
||||
void Reset();
|
||||
void Apply();
|
||||
|
||||
private:
|
||||
~nsOfflineCacheEvictionFunction() {}
|
||||
|
||||
nsOfflineCacheDevice *mDevice;
|
||||
nsCOMArray<nsIFile> mItems;
|
||||
|
||||
bool mTLSInited;
|
||||
};
|
||||
|
||||
class nsOfflineCacheDevice final : public nsCacheDevice
|
||||
|
Loading…
Reference in New Issue
Block a user