mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 861920 - Avoid apps to write in its local storage while device free storage is low. r=honzab
This commit is contained in:
parent
700bb67234
commit
d75360beb8
@ -194,6 +194,11 @@ DOMStorageCache::ProcessUsageDelta(const DOMStorage* aStorage, int64_t aDelta)
|
|||||||
bool
|
bool
|
||||||
DOMStorageCache::ProcessUsageDelta(uint32_t aGetDataSetIndex, const int64_t aDelta)
|
DOMStorageCache::ProcessUsageDelta(uint32_t aGetDataSetIndex, const int64_t aDelta)
|
||||||
{
|
{
|
||||||
|
// Check if we are in a low disk space situation
|
||||||
|
if (aDelta > 0 && mManager && mManager->IsLowDiskSpace()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Check limit per this origin
|
// Check limit per this origin
|
||||||
Data& data = mData[aGetDataSetIndex];
|
Data& data = mData[aGetDataSetIndex];
|
||||||
uint64_t newOriginUsage = data.mOriginQuotaUsage + aDelta;
|
uint64_t newOriginUsage = data.mOriginQuotaUsage + aDelta;
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "mozilla/dom/ContentChild.h"
|
#include "mozilla/dom/ContentChild.h"
|
||||||
#include "mozilla/unused.h"
|
#include "mozilla/unused.h"
|
||||||
|
#include "nsIDiskSpaceWatcher.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
@ -294,10 +295,10 @@ DOMStorageDBParent::ReleaseIPDLReference()
|
|||||||
|
|
||||||
namespace { // anon
|
namespace { // anon
|
||||||
|
|
||||||
class SendScopesHavingDataRunnable : public nsRunnable
|
class SendInitialChildDataRunnable : public nsRunnable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SendScopesHavingDataRunnable(DOMStorageDBParent* aParent)
|
SendInitialChildDataRunnable(DOMStorageDBParent* aParent)
|
||||||
: mParent(aParent)
|
: mParent(aParent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -315,6 +316,17 @@ private:
|
|||||||
mozilla::unused << mParent->SendScopesHavingData(scopes);
|
mozilla::unused << mParent->SendScopesHavingData(scopes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We need to check if the device is in a low disk space situation, so
|
||||||
|
// we can forbid in that case any write in localStorage.
|
||||||
|
nsCOMPtr<nsIDiskSpaceWatcher> diskSpaceWatcher =
|
||||||
|
do_GetService("@mozilla.org/toolkit/disk-space-watcher;1");
|
||||||
|
bool lowDiskSpace = false;
|
||||||
|
diskSpaceWatcher->GetIsDiskFull(&lowDiskSpace);
|
||||||
|
if (lowDiskSpace) {
|
||||||
|
mozilla::unused << mParent->SendObserve(
|
||||||
|
nsDependentCString("low-disk-space"), EmptyCString());
|
||||||
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,8 +348,8 @@ DOMStorageDBParent::DOMStorageDBParent()
|
|||||||
|
|
||||||
// Cannot send directly from here since the channel
|
// Cannot send directly from here since the channel
|
||||||
// is not completely built at this moment.
|
// is not completely built at this moment.
|
||||||
nsRefPtr<SendScopesHavingDataRunnable> r =
|
nsRefPtr<SendInitialChildDataRunnable> r =
|
||||||
new SendScopesHavingDataRunnable(this);
|
new SendInitialChildDataRunnable(this);
|
||||||
NS_DispatchToCurrentThread(r);
|
NS_DispatchToCurrentThread(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +109,7 @@ NS_IMPL_ISUPPORTS1(DOMStorageManager,
|
|||||||
|
|
||||||
DOMStorageManager::DOMStorageManager(nsPIDOMStorage::StorageType aType)
|
DOMStorageManager::DOMStorageManager(nsPIDOMStorage::StorageType aType)
|
||||||
: mType(aType)
|
: mType(aType)
|
||||||
|
, mLowDiskSpace(false)
|
||||||
{
|
{
|
||||||
mCaches.Init(10);
|
mCaches.Init(10);
|
||||||
DOMStorageObserver* observer = DOMStorageObserver::Self();
|
DOMStorageObserver* observer = DOMStorageObserver::Self();
|
||||||
@ -566,6 +567,22 @@ DOMStorageManager::Observe(const char* aTopic, const nsACString& aScopePrefix)
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcmp(aTopic, "low-disk-space")) {
|
||||||
|
if (mType == LocalStorage) {
|
||||||
|
mLowDiskSpace = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(aTopic, "no-low-disk-space")) {
|
||||||
|
if (mType == LocalStorage) {
|
||||||
|
mLowDiskSpace = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DOM_STORAGE_TESTS
|
#ifdef DOM_STORAGE_TESTS
|
||||||
if (!strcmp(aTopic, "test-reload")) {
|
if (!strcmp(aTopic, "test-reload")) {
|
||||||
if (mType != LocalStorage) {
|
if (mType != LocalStorage) {
|
||||||
|
@ -87,6 +87,12 @@ private:
|
|||||||
nsTHashtable<DOMStorageCacheHashKey> mCaches;
|
nsTHashtable<DOMStorageCacheHashKey> mCaches;
|
||||||
const nsPIDOMStorage::StorageType mType;
|
const nsPIDOMStorage::StorageType mType;
|
||||||
|
|
||||||
|
// If mLowDiskSpace is true it indicates a low device storage situation and
|
||||||
|
// so no localStorage writes are allowed. sessionStorage writes are still
|
||||||
|
// allowed.
|
||||||
|
bool mLowDiskSpace;
|
||||||
|
bool IsLowDiskSpace() const { return mLowDiskSpace; };
|
||||||
|
|
||||||
static PLDHashOperator ClearCacheEnumerator(DOMStorageCacheHashKey* aCache,
|
static PLDHashOperator ClearCacheEnumerator(DOMStorageCacheHashKey* aCache,
|
||||||
void* aClosure);
|
void* aClosure);
|
||||||
|
|
||||||
|
@ -68,6 +68,11 @@ DOMStorageObserver::Init()
|
|||||||
obs->AddObserver(sSelf, "profile-before-change", true);
|
obs->AddObserver(sSelf, "profile-before-change", true);
|
||||||
obs->AddObserver(sSelf, "xpcom-shutdown", true);
|
obs->AddObserver(sSelf, "xpcom-shutdown", true);
|
||||||
|
|
||||||
|
// Observe low device storage notifications. Only in the parent.
|
||||||
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||||
|
obs->AddObserver(sSelf, "disk-space-watcher", true);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DOM_STORAGE_TESTS
|
#ifdef DOM_STORAGE_TESTS
|
||||||
// Testing
|
// Testing
|
||||||
obs->AddObserver(sSelf, "domstorage-test-flush-force", true);
|
obs->AddObserver(sSelf, "domstorage-test-flush-force", true);
|
||||||
@ -300,6 +305,16 @@ DOMStorageObserver::Observe(nsISupports* aSubject,
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcmp(aTopic, "disk-space-watcher")) {
|
||||||
|
if (NS_LITERAL_STRING("full").Equals(aData)) {
|
||||||
|
Notify("low-disk-space");
|
||||||
|
} else if (NS_LITERAL_STRING("free").Equals(aData)) {
|
||||||
|
Notify("no-low-disk-space");
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DOM_STORAGE_TESTS
|
#ifdef DOM_STORAGE_TESTS
|
||||||
if (!strcmp(aTopic, "domstorage-test-flush-force")) {
|
if (!strcmp(aTopic, "domstorage-test-flush-force")) {
|
||||||
DOMStorageDBBridge* db = DOMStorageCache::GetDatabase();
|
DOMStorageDBBridge* db = DOMStorageCache::GetDatabase();
|
||||||
|
Loading…
Reference in New Issue
Block a user