Bug 1573720 - Convert dom.storage.default.quota to a static pref. r=mccr8
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 15 Aug 2019 05:31:38 +0000
changeset 488381 8dc85cb7b8be0122ceda10fec5886ee92f3e4a6c
parent 488380 53019621c04ed8460626f88a9d650ffab5d96aa9
child 488382 257776683ca2ea65d61b7e3cc1100e43a93cd6c3
push id113906
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 04:07:24 +0000
treeherdermozilla-inbound@d887276421d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1573720
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1573720 - Convert dom.storage.default.quota to a static pref. r=mccr8 This one was VarCached to two different variables in two different modules. Differential Revision: https://phabricator.services.mozilla.com/D41920
dom/localstorage/ActorsParent.cpp
dom/storage/LocalStorageManager.cpp
modules/libpref/init/StaticPrefList.yaml
modules/libpref/init/all.js
--- a/dom/localstorage/ActorsParent.cpp
+++ b/dom/localstorage/ActorsParent.cpp
@@ -9,16 +9,17 @@
 #include "LocalStorageCommon.h"
 #include "LSObject.h"
 #include "mozIStorageConnection.h"
 #include "mozIStorageFunction.h"
 #include "mozIStorageService.h"
 #include "mozStorageCID.h"
 #include "mozStorageHelper.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/StaticPrefs_dom.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ClientManagerService.h"
 #include "mozilla/dom/LSWriteOptimizer.h"
 #include "mozilla/dom/PBackgroundLSDatabaseParent.h"
 #include "mozilla/dom/PBackgroundLSObserverParent.h"
 #include "mozilla/dom/PBackgroundLSRequestParent.h"
@@ -188,34 +189,25 @@ static const uint32_t kUsageFileCookie =
  * batch mechanism which helps avoid wasteful IPC in the case of silly content
  * code.
  */
 const uint32_t kFlushTimeoutMs = 5000;
 
 const char kPrivateBrowsingObserverTopic[] = "last-pb-context-exited";
 
 const uint32_t kDefaultNextGen = false;
-const uint32_t kDefaultOriginLimitKB = 5 * 1024;
 const uint32_t kDefaultShadowWrites = true;
 const uint32_t kDefaultSnapshotPrefill = 16384;
 const uint32_t kDefaultSnapshotGradualPrefill = 4096;
 const uint32_t kDefaultClientValidation = true;
 /**
  *
  */
 const char kNextGenPref[] = "dom.storage.next_gen";
 /**
- * LocalStorage data limit as determined by summing up the lengths of all string
- * keys and values.  This is consistent with the legacy implementation and other
- * browser engines.  This value should really only ever change in unit testing
- * where being able to lower it makes it easier for us to test certain edge
- * cases.
- */
-const char kDefaultQuotaPref[] = "dom.storage.default_quota";
-/**
  * Should all mutations also be reflected in the "shadow" database, which is
  * the legacy webappsstore.sqlite database.  When this is enabled, users can
  * downgrade their version of Firefox and/or otherwise fall back to the legacy
  * implementation without loss of data.  (Older versions of Firefox will
  * recognize the presence of ls-archive.sqlite and purge it and the other
  * LocalStorage directories so privacy is maintained.)
  */
 const char kShadowWritesPref[] = "dom.storage.shadow_writes";
@@ -2910,17 +2902,16 @@ typedef nsRefPtrHashtable<nsUint64HashKe
 StaticAutoPtr<PreparedObserverHashtable> gPreparedObsevers;
 
 typedef nsClassHashtable<nsCStringHashKey, nsTArray<Observer*>>
     ObserverHashtable;
 
 StaticAutoPtr<ObserverHashtable> gObservers;
 
 Atomic<bool> gNextGen(kDefaultNextGen);
-Atomic<uint32_t, Relaxed> gOriginLimitKB(kDefaultOriginLimitKB);
 Atomic<bool> gShadowWrites(kDefaultShadowWrites);
 Atomic<int32_t, Relaxed> gSnapshotPrefill(kDefaultSnapshotPrefill);
 Atomic<int32_t, Relaxed> gSnapshotGradualPrefill(
     kDefaultSnapshotGradualPrefill);
 Atomic<bool> gClientValidation(kDefaultClientValidation);
 
 typedef nsDataHashtable<nsCStringHashKey, int64_t> UsageHashtable;
 
@@ -3265,19 +3256,16 @@ void InitializeLocalStorage() {
   }
 
   if (NS_FAILED(QuotaClient::Initialize())) {
     NS_WARNING("Failed to initialize quota client!");
   }
 
   Preferences::AddAtomicBoolVarCache(&gNextGen, kNextGenPref, kDefaultNextGen);
 
-  Preferences::AddAtomicUintVarCache(&gOriginLimitKB, kDefaultQuotaPref,
-                                     kDefaultOriginLimitKB);
-
   Preferences::RegisterCallbackAndCall(ShadowWritesPrefChangedCallback,
                                        kShadowWritesPref);
 
   Preferences::RegisterCallbackAndCall(SnapshotPrefillPrefChangedCallback,
                                        kSnapshotPrefillPref);
 
   Preferences::RegisterCallbackAndCall(
       SnapshotGradualPrefillPrefChangedCallback, kSnapshotGradualPrefillPref);
@@ -5409,17 +5397,17 @@ void Datastore::NoteChangedObserverArray
 bool Datastore::UpdateUsage(int64_t aDelta) {
   AssertIsOnBackgroundThread();
 
   // Check internal LocalStorage origin limit.
   int64_t newUsage = mUsage + aDelta;
 
   MOZ_ASSERT(newUsage >= 0);
 
-  if (newUsage > gOriginLimitKB * 1024) {
+  if (newUsage > StaticPrefs::dom_storage_default_quota() * 1024) {
     return false;
   }
 
   // Check QuotaManager limits (group and global limit).
   if (IsPersistent()) {
     MOZ_ASSERT(mQuotaObject);
 
     if (!mQuotaObject->MaybeUpdateSize(newUsage, /* aTruncate */ true)) {
--- a/dom/storage/LocalStorageManager.cpp
+++ b/dom/storage/LocalStorageManager.cpp
@@ -15,47 +15,29 @@
 #include "nsNetUtil.h"
 #include "nsNetCID.h"
 #include "nsIURL.h"
 #include "nsPrintfCString.h"
 #include "nsXULAppAPI.h"
 #include "nsThreadUtils.h"
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
-#include "mozilla/Preferences.h"
+#include "mozilla/StaticPrefs_dom.h"
 #include "mozilla/dom/LocalStorageCommon.h"
 
-// Only allow relatively small amounts of data since performance of
-// the synchronous IO is very bad.
-// We are enforcing simple per-origin quota only.
-#define DEFAULT_QUOTA_LIMIT (5 * 1024)
-
 namespace mozilla {
 namespace dom {
 
 using namespace StorageUtils;
 
-namespace {
-
-int32_t gQuotaLimit = DEFAULT_QUOTA_LIMIT;
-
-}  // namespace
-
 LocalStorageManager* LocalStorageManager::sSelf = nullptr;
 
 // static
 uint32_t LocalStorageManager::GetQuota() {
-  static bool preferencesInitialized = false;
-  if (!preferencesInitialized) {
-    mozilla::Preferences::AddIntVarCache(
-        &gQuotaLimit, "dom.storage.default_quota", DEFAULT_QUOTA_LIMIT);
-    preferencesInitialized = true;
-  }
-
-  return gQuotaLimit * 1024;  // pref is in kBs
+  return StaticPrefs::dom_storage_default_quota() * 1024;  // pref is in kBs
 }
 
 NS_IMPL_ISUPPORTS(LocalStorageManager, nsIDOMStorageManager,
                   nsILocalStorageManager)
 
 LocalStorageManager::LocalStorageManager() : mCaches(8) {
   MOZ_ASSERT(!NextGenLocalStorageEnabled());
 
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -2061,16 +2061,28 @@
   type: RelaxedAtomicBool
 #if !defined(MOZ_WIDGET_ANDROID)
   value: true
 #else
   value: false
 #endif
   mirror: always
 
+# LocalStorage data limit as determined by summing up the lengths of all string
+# keys and values. This is consistent with the legacy implementation and other
+# browser engines. This value should really only ever change in unit testing
+# where being able to lower it makes it easier for us to test certain edge
+# cases. Measured in KiBs.
+- name: dom.storage.default_quota
+  type: RelaxedAtomicUint32
+  # Only allow relatively small amounts of data since performance of the
+  # synchronous IO is very bad. We are enforcing simple per-origin quota only.
+  value: 5 * 1024
+  mirror: always
+
 # Is support for Storage test APIs enabled?
 - name: dom.storage.testing
   type: bool
   value: false
   mirror: always
 
 # For area and anchor elements with target=_blank and no rel set to
 # opener/noopener.
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -1242,17 +1242,16 @@ pref("dom.popup_allowed_events", "change
 pref("dom.serviceWorkers.disable_open_click_delay", 1000);
 
 pref("dom.storage.enabled", true);
 // 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.
 // See bug 1539835 for enabling this unconditionally.
 pref("dom.storage.next_gen", true);
-pref("dom.storage.default_quota",      5120);
 pref("dom.storage.shadow_writes", true);
 pref("dom.storage.snapshot_prefill", 16384);
 pref("dom.storage.snapshot_gradual_prefill", 4096);
 pref("dom.storage.snapshot_reusing", true);
 pref("dom.storage.client_validation", true);
 
 pref("dom.send_after_paint_to_content", false);