Bug 1683299 - Introduce site quota for legacy LocalStorage; r=dom-workers-and-storage-reviewers,janv

This patch:
- adds a new pref for site quota.
- sets 25 MB as the default site qutoa.
- renames LocalStorageManager::GetQuota() to LocalStorageManager::GetOriginQuota().
- adds LocalStorageManager::GetSiteQuota().
- updates LocalStorage quota tests.

Differential Revision: https://phabricator.services.mozilla.com/D101756
This commit is contained in:
Tom Tung 2021-01-14 16:01:17 +00:00
Родитель 256e63ce3d
Коммит 15704220ee
10 изменённых файлов: 28 добавлений и 8 удалений

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

@ -25,6 +25,7 @@ async function testSteps() {
info("Setting pref");
Services.prefs.setBoolPref("dom.storage.next_gen", true);
Services.prefs.setBoolPref("dom.storage.snapshot_reusing", false);
info("Setting limits");

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

@ -194,7 +194,7 @@ bool LocalStorageCache::ProcessUsageDelta(uint32_t aGetDataSetIndex,
Data& data = mData[aGetDataSetIndex];
uint64_t newOriginUsage = data.mOriginQuotaUsage + aDelta;
if (aSource == ContentMutation && aDelta > 0 &&
newOriginUsage > LocalStorageManager::GetQuota()) {
newOriginUsage > LocalStorageManager::GetOriginQuota()) {
return false;
}
@ -609,7 +609,7 @@ bool StorageUsage::CheckAndSetETLD1UsageDelta(
int64_t newUsage = mUsage[aDataSetIndex] + aDelta;
if (aSource == LocalStorageCache::ContentMutation && aDelta > 0 &&
newUsage > LocalStorageManager::GetQuota()) {
newUsage > LocalStorageManager::GetSiteQuota()) {
return false;
}

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

@ -33,10 +33,17 @@ using namespace StorageUtils;
LocalStorageManager* LocalStorageManager::sSelf = nullptr;
// static
uint32_t LocalStorageManager::GetQuota() {
uint32_t LocalStorageManager::GetOriginQuota() {
return StaticPrefs::dom_storage_default_quota() * 1024; // pref is in kBs
}
// static
uint32_t LocalStorageManager::GetSiteQuota() {
return std::max(StaticPrefs::dom_storage_default_quota(),
StaticPrefs::dom_storage_default_site_quota()) *
1024; // pref is in kBs
}
NS_IMPL_ISUPPORTS(LocalStorageManager, nsIDOMStorageManager,
nsILocalStorageManager)

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

@ -37,7 +37,10 @@ class LocalStorageManager final : public nsIDOMStorageManager,
LocalStorageManager();
// Reads the preference for DOM storage quota
static uint32_t GetQuota();
static uint32_t GetOriginQuota();
// Reads the preference for DOM storage site quota
static uint32_t GetSiteQuota();
// Gets (but not ensures) cache for the given scope
LocalStorageCache* GetCache(const nsACString& aOriginSuffix,

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

@ -327,7 +327,7 @@ void SessionStorageCache::ClearActor() {
bool SessionStorageCache::DataSet::ProcessUsageDelta(int64_t aDelta) {
// Check limit per this origin
uint64_t newOriginUsage = mOriginQuotaUsage + aDelta;
if (aDelta > 0 && newOriginUsage > LocalStorageManager::GetQuota()) {
if (aDelta > 0 && newOriginUsage > LocalStorageManager::GetOriginQuota()) {
return false;
}

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

@ -117,7 +117,7 @@ SimpleTest.waitForExplicitFinish();
function startTest() {
// Initialy setup the quota to testing value of 1024B and
// set a 500 bytes key with name length 1 (allocate 501 bytes)
SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, doNextTest);
SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["dom.storage.default_site_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, doNextTest);
}
</script>

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

@ -14,8 +14,10 @@ const CONTENT_PAGE = "http://mochi.test:8888/chrome/dom/tests/mochitest/localsto
const slavePath = "/chrome/dom/tests/mochitest/localstorage/";
var currentTest = 1;
var quota = Services.prefs.getIntPref("dom.storage.default_quota", 5 * 1024);
var siteQuota = Services.prefs.getIntPref("dom.storage.default_site_quota", 25 * 1024);
Services.prefs.setIntPref("browser.startup.page", 0);
Services.prefs.setIntPref("dom.storage.default_quota", 1);
Services.prefs.setIntPref("dom.storage.default_site_quota", 1);
var slaveLoadsPending = 1;
var slaveOrigin = "";
@ -128,6 +130,7 @@ function doNextTest(aWindow) {
default:
Services.prefs.clearUserPref("browser.startup.page")
Services.prefs.setIntPref("dom.storage.default_quota", quota);
Services.prefs.setIntPref("dom.storage.default_site_quota", siteQuota);
aWindow.close();
SimpleTest.finish();
}

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

@ -121,7 +121,7 @@ function startTest() {
], function() {
// Initialy setup the quota to testing value of 1024B and
// set a 500 bytes key with name length 1 (allocate 501 bytes)
SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, doNextTest);
SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["dom.storage.default_site_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, doNextTest);
});
}
</script>

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

@ -84,7 +84,7 @@ SimpleTest.waitForExplicitFinish();
function startTest() {
// Initialy setup the quota to testing value of 1024B and
// set a 500 bytes key with name length 1 (allocate 501 bytes)
SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, function() {
SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["dom.storage.default_site_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, function() {
SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION, 'context': document}], doNextTest);
});
}

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

@ -2906,6 +2906,12 @@
value: 5 * 1024
mirror: always
# Per-site quota for legacy LocalStorage implementation.
- name: dom.storage.default_site_quota
type: RelaxedAtomicUint32
value: 25 * 1024
mirror: always
# Whether or not LSNG (Next Generation Local Storage) is enabled.
# See bug 1517090 for enabling this on Nightly.
# See bug 1534736 for changing it to EARLY_BETA_OR_EARLIER.