Commit b00bac4b authored by Tom Tung's avatar Tom Tung
Browse files

Bug 1683299 - Introduce site quota for legacy LocalStorage; r=janv, a=RyanVM

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
parent d629da1e
......@@ -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);
});
}
......
......@@ -2875,6 +2875,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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment